Eliminate the SI receive buffer length requirement
[ric-plt/lib/rmr.git] / test / app_test / run_exrts_test.sh
1 #!/usr/bin/env ksh
2 # vim: ts=4 sw=4 noet :
3 #==================================================================================
4 #    Copyright (c) 2019-2020 Nokia
5 #    Copyright (c) 2018-2020 AT&T Intellectual Property.
6 #
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18 #==================================================================================
19 #
20
21 # ---------------------------------------------------------------------------------
22 #       Mnemonic:       run_exrts_test.ksh
23 #       Abstract:       This is a simple script to set up and run the v_send/ex_rts_receive
24 #                               processes for some library validation on top of nng. This test
25 #                               starts these processes to verify that when a receiver has an ack 
26 #                               message larger than the received message it is able to allocate
27 #                               a new payload which can be returned via the RMR return to sender
28 #                               function.
29 #
30 #                               Example command line:
31 #                                       # run with 10 caller threads sending 10,000 meessages each, 
32 #                                       # 5 receivers, and a 10 mu-s delay between each caller send
33 #                                       ksh ./run_lcall_test.ksh -d 10 -n 10000 -r 5 -c 10
34 #
35 #       Date:           28 October 2019
36 #       Author:         E. Scott Daniels
37 # ---------------------------------------------------------------------------------
38
39 ulimit -c unlimited
40
41 # driven with -L sender or -L receiver on the command line
42 # run something though valgrind to check for leaks; requires valgind
43 function leak_anal {
44         valgrind  -v --leak-resolution=high --leak-check=yes $opt "$@"
45 }
46
47 # The sender and receivers are run asynch. Their exit statuses are captured in a
48 # file in order for the 'main' to pick them up easily.
49 #
50 function run_sender {
51         if (( la_sender ))
52         then
53                 leak_anal ./v_sender${si} ${nmsg:-10} ${delay:-100000} ${mtype_start_stop:-0:1}  >/tmp/la.log 2>&1
54         else
55                 ./v_sender${si} ${nmsg:-10} ${delay:-100000} ${mtype_start_stop:-0:1}
56         fi
57         echo $? >/tmp/PID$$.src         # must communicate state back via file b/c asynch
58 }
59
60 # $1 is the instance so we can keep logs separate
61 function run_rcvr {
62         typeset port
63
64         port=$(( 4460 + ${1:-0} ))
65         export RMR_RTG_SVC=$(( 9990 + $1 ))
66         if (( la_receiver ))
67         then
68                 leak_anal ./ex_rts_receiver${si} $copyclone -p $port >/tmp/la.log 2>&1
69         else
70                 ./ex_rts_receiver${si} $copyclone -p $port
71         fi
72         echo $? >/tmp/PID$$.$1.rrc
73 }
74
75 #       Drop a contrived route table in such that the sender sends each message to n
76 #       receivers.
77 #
78 function set_rt {
79         typeset port=4460
80         typeset groups="localhost:4460"
81         for (( i=1; i < ${1:-3}; i++ ))
82         do
83                 groups="$groups,localhost:$((port+i))"
84         done
85
86         cat <<endKat >ex_rts.rt
87                 newrt | start
88                 mse |0 | 0 | $groups
89                 mse |1 | 10 | $groups
90                 mse |2 | 20 | $groups
91                 rte |3 | $groups
92                 rte |4 | $groups
93                 rte |5 | $groups
94                 rte |6 | $groups
95                 rte |7 | $groups
96                 rte |8 | $groups
97                 rte |9 | $groups
98                 rte |10 | $groups
99                 rte |11 | $groups
100                 newrt | end
101 endKat
102
103         cat ex_rts.rt
104 }
105
106 # ---------------------------------------------------------
107
108 if [[ ! -f local.rt ]]          # we need the real host name in the local.rt; build one from mask if not there
109 then
110         hn=$(hostname)
111         sed "s!%%hostname%%!$hn!" rt.mask >local.rt
112 fi
113
114 export EX_CFLAGS=""
115 export RMR_ASYNC_CONN=0         # ensure we don't lose first msg as drops waiting for conn look like errors
116 nmsg=100                                        # total number of messages to be exchanged (-n value changes)
117 delay=500                                       # microsec sleep between msg 1,000,000 == 1s
118 wait=1
119 rebuild=0
120 verbose=0
121 nrcvrs=1                                        # this is sane, but -r allows it to be set up
122 use_installed=0
123 mtype_start_stop=""
124 si=""                                           # -S will enable si library testing
125
126 while [[ $1 == -* ]]
127 do
128         case $1 in
129                 -c)     copyclone="-c $2"; shift;;
130                 -B)     rebuild=1;;
131                 -d)     delay=${2//,/}; shift;;                         # delay in micro seconds allow 1,000 to make it easier on user
132                 -i)     use_installed=1;;
133                 -L)     leak_anal=$2; shift;;
134                 -m)     mtype_start_stop="$2"; shift;;
135                 -M)     mt_call_flag="EX_CFLAGS=-DMTC=1";;      # turn on mt-call receiver option
136                 -N)     si="";;                                                         # enable nng based testing
137                 -n)     nmsg=$2; shift;;
138                 -r) nrcvrs=$2; shift;;
139                 -S)     si="_si";;                                                      # run SI95 based binaries
140                 -v)     verbose=1;;
141
142                 *)      echo "unrecognised option: $1"
143                         echo "usage: $0 [-B] [-c caller-threads] [-d micor-sec-delay] [-i] [-M] [-m mtype] [-n num-msgs] [-r num-receivers] [-S] [-v]"
144                         echo "  -B forces a rebuild which will use .build"
145                         echo "  -i will use installed libraries (/usr/local) and cause -B to be ignored if supplied)"
146                         echo "  -L {sender|receiver} run the sender or recevier code under valgrind for leak analysis (output to /tmp/la.log)"
147                         echo "  -m mtype  will set the stopping (max) message type; sender will loop through 0 through mtype-1"
148                         echo "  -m start:stop  will set the starting and stopping mtypes; start through stop -1"
149                         echo "  -M enables mt-call receive processing to test the RMR asynch receive pthread"
150                         echo "  -N enables NNG based testing (default)"
151                         echo "  -S enables SI95 based testing"
152                         echo ""
153                         echo "The receivers will run until they have not received a message for a few seconds. The"
154                         echo "sender will send the requested number of messages, 10 by default."
155                         exit 1
156                         ;;
157         esac
158
159         shift
160 done
161
162 # set leak analysis (do not do this from any automated tests)
163 case $leak_anal in 
164         s*)     la_sender=1;;
165         r*)     la_receiver=1;;
166 esac
167
168 if (( verbose ))
169 then
170         echo "2" >.verbose
171         export RMR_VCTL_FILE=".verbose"
172 fi
173
174 if (( use_installed ))                  # point at installed library
175 then
176         export LD_LIBRARY_PATH=${LD_LIBRARY_PATH-:/usr/local/lib}       # use caller's or set sane default
177 else
178         if (( rebuild ))
179         then
180                 build_path=../../.build         # if we rebuild we can insist that it is in .build :)
181                 set -e
182                 $SHELL ./rebuild.ksh
183                 set +e
184         else
185                 build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
186
187                 if [[ ! -d $build_path ]]
188                 then
189                         echo "cannot find build in: $build_path"
190                         echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
191                         exit 1
192                 fi
193         fi
194
195         if [[ -z $LD_LIBRARY_PATH ]]            # cmake test will set this up and we must honour
196         then
197                 if [[ -d $build_path/lib64 ]]
198                 then
199                         export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH
200                 else
201                         export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH
202                 fi
203         fi
204 fi
205
206 export LIBRARY_PATH=$LD_LIBRARY_PATH
207 export RMR_SEED_RT=./ex_rts.rt
208
209 set_rt $nrcvrs                                                                                                          # set up the rt for n receivers
210
211 if ! build_path=$build_path make -B $mt_call_flag v_sender${si} ex_rts_receiver${si} >/tmp/PID$$.log 2>&1                       # for sanity, always rebuild test binaries
212 then
213         echo "[FAIL] cannot make binaries"
214         echo "====="
215         env
216         echo "====="
217         cat /tmp/PID$$.log
218         rm -f /tmp/PID$$*
219         exit 1
220 fi
221
222 echo "<RUN> binaries built"
223
224 for (( i=0; i < nrcvrs; i++  ))
225 do
226         run_rcvr $i &
227 done
228
229 sleep 2                         # let receivers init so we don't shoot at empty targets
230 if (( verbose ))
231 then
232         netstat -an|grep LISTEN
233 fi
234 run_sender &
235
236 wait
237
238
239 for (( i=0; i < nrcvrs; i++ ))          # collect return codes
240 do
241         head -1 /tmp/PID$$.$i.rrc | read x
242         (( rrc += x ))
243 done
244
245 head -1 /tmp/PID$$.src | read src
246
247 if (( !! (src + rrc) ))
248 then
249         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
250 else
251         echo "[PASS] sender rc=$src  receiver rc=$rrc"
252         rm -f ex_rts.rt
253 fi
254
255 rm /tmp/PID$$.*
256 rm -f .verbose
257
258 exit $(( !! (src + rrc) ))
259