Correct the max receive message constant
[ric-plt/lib/rmr.git] / test / app_test / run_exrts_test.ksh
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 # The sender and receivers are run asynch. Their exit statuses are captured in a
42 # file in order for the 'main' to pick them up easily.
43 #
44 function run_sender {
45         ./v_sender${si} ${nmsg:-10} ${delay:-100000} ${mtype_start_stop:-0:1} 
46         echo $? >/tmp/PID$$.src         # must communicate state back via file b/c asynch
47 }
48
49 # $1 is the instance so we can keep logs separate
50 function run_rcvr {
51         typeset port
52
53         port=$(( 4460 + ${1:-0} ))
54         export RMR_RTG_SVC=$(( 9990 + $1 ))
55         ./ex_rts_receiver${si} $copyclone -p $port
56         echo $? >/tmp/PID$$.$1.rrc
57 }
58
59 #       Drop a contrived route table in such that the sender sends each message to n
60 #       receivers.
61 #
62 function set_rt {
63         typeset port=4460
64         typeset groups="localhost:4460"
65         for (( i=1; i < ${1:-3}; i++ ))
66         do
67                 groups="$groups,localhost:$((port+i))"
68         done
69
70         cat <<endKat >ex_rts.rt
71                 newrt | start
72                 mse |0 | 0 | $groups
73                 mse |1 | 10 | $groups
74                 mse |2 | 20 | $groups
75                 rte |3 | $groups
76                 rte |4 | $groups
77                 rte |5 | $groups
78                 rte |6 | $groups
79                 rte |7 | $groups
80                 rte |8 | $groups
81                 rte |9 | $groups
82                 rte |10 | $groups
83                 rte |11 | $groups
84                 newrt | end
85 endKat
86
87         cat ex_rts.rt
88 }
89
90 # ---------------------------------------------------------
91
92 if [[ ! -f local.rt ]]          # we need the real host name in the local.rt; build one from mask if not there
93 then
94         hn=$(hostname)
95         sed "s!%%hostname%%!$hn!" rt.mask >local.rt
96 fi
97
98 export EX_CFLAGS=""
99 export RMR_ASYNC_CONN=0         # ensure we don't lose first msg as drops waiting for conn look like errors
100 nmsg=100                                        # total number of messages to be exchanged (-n value changes)
101 delay=500                                       # microsec sleep between msg 1,000,000 == 1s
102 wait=1
103 rebuild=0
104 verbose=0
105 nrcvrs=1                                        # this is sane, but -r allows it to be set up
106 use_installed=0
107 mtype_start_stop=""
108 si=""                                           # -S will enable si library testing
109
110 while [[ $1 == -* ]]
111 do
112         case $1 in
113                 -c)     copyclone="-c $2"; shift;;
114                 -B)     rebuild=1;;
115                 -d)     delay=${2//,/}; shift;;                         # delay in micro seconds allow 1,000 to make it easier on user
116                 -i)     use_installed=1;;
117                 -m)     mtype_start_stop="$2"; shift;;
118                 -M)     mt_call_flag="EX_CFLAGS=-DMTC=1";;      # turn on mt-call receiver option
119                 -N)     si="";;                                                         # enable nng based testing
120                 -n)     nmsg=$2; shift;;
121                 -r) nrcvrs=$2; shift;;
122                 -S)     si="_si";;                                                      # run SI95 based binaries
123                 -v)     verbose=1;;
124
125                 *)      echo "unrecognised option: $1"
126                         echo "usage: $0 [-B] [-c caller-threads] [-d micor-sec-delay] [-i] [-M] [-m mtype] [-n num-msgs] [-r num-receivers] [-S] [-v]"
127                         echo "  -B forces a rebuild which will use .build"
128                         echo "  -i will use installed libraries (/usr/local) and cause -B to be ignored if supplied)"
129                         echo "  -m mtype  will set the stopping (max) message type; sender will loop through 0 through mtype-1"
130                         echo "  -m start:stop  will set the starting and stopping mtypes; start through stop -1"
131                         echo "  -M enables mt-call receive processing to test the RMR asynch receive pthread"
132                         echo "  -N enables NNG based testing (default)"
133                         echo "  -S enables SI95 based testing"
134                         echo ""
135                         echo "The receivers will run until they have not received a message for a few seconds. The"
136                         echo "sender will send the requested number of messages, 10 by default."
137                         exit 1
138                         ;;
139         esac
140
141         shift
142 done
143
144
145 if (( verbose ))
146 then
147         echo "2" >.verbose
148         export RMR_VCTL_FILE=".verbose"
149 fi
150
151 if (( use_installed ))                  # point at installed library
152 then
153         export LD_LIBRARY_PATH=${LD_LIBRARY_PATH-:/usr/local/lib}       # use caller's or set sane default
154 else
155         if (( rebuild ))
156         then
157                 build_path=../../.build         # if we rebuild we can insist that it is in .build :)
158                 set -e
159                 $SHELL ./rebuild.ksh
160                 set +e
161         else
162                 build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
163
164                 if [[ ! -d $build_path ]]
165                 then
166                         echo "cannot find build in: $build_path"
167                         echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
168                         exit 1
169                 fi
170         fi
171
172         if [[ -d $build_path/lib64 ]]
173         then
174                 export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH
175         else
176                 export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH
177         fi
178 fi
179
180 export LIBRARY_PATH=$LD_LIBRARY_PATH
181 export RMR_SEED_RT=./ex_rts.rt
182
183 set_rt $nrcvrs                                                                                                          # set up the rt for n receivers
184
185 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
186 then
187         echo "[FAIL] cannot make binaries"
188         echo "====="
189         env
190         echo "====="
191         cat /tmp/PID$$.log
192         rm -f /tmp/PID$$*
193         exit 1
194 fi
195
196 echo "<RUN> binaries built"
197
198 for (( i=0; i < nrcvrs; i++  ))
199 do
200         run_rcvr $i &
201 done
202
203 sleep 2                         # let receivers init so we don't shoot at empty targets
204 if (( verbose ))
205 then
206         netstat -an|grep LISTEN
207 fi
208 run_sender &
209
210 wait
211
212
213 for (( i=0; i < nrcvrs; i++ ))          # collect return codes
214 do
215         head -1 /tmp/PID$$.$i.rrc | read x
216         (( rrc += x ))
217 done
218
219 head -1 /tmp/PID$$.src | read src
220
221 if (( !! (src + rrc) ))
222 then
223         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
224 else
225         echo "[PASS] sender rc=$src  receiver rc=$rrc"
226         rm -f ex_rts.rt
227 fi
228
229 rm /tmp/PID$$.*
230 rm -f .verbose
231
232 exit $(( !! (src + rrc) ))
233