Add better support for manual app testing
[ric-plt/lib/rmr.git] / test / app_test / run_call_test.sh
1 #!/usr/bin/env ksh
2 # vim: ts=4 sw=4 noet :
3 #==================================================================================
4 #    Copyright (c) 2019-2021 Nokia
5 #    Copyright (c) 2018-2021 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_call_test.ksh
23 #       Abstract:       This is a simple script to set up and run the basic send/receive
24 #                               processes for some library validation on top of nng.
25 #                               It should be possible to clone the repo, switch to this directory
26 #                               and execute  'ksh run -B'  which will build RMr, make the sender and
27 #                               recevier then  run the basic test.
28 #
29 #                               The call test drives three RMr based processes:
30 #                                       caller which invokes rmr_mt_call() to send n messages
31 #
32 #                                       receiver which executes rmr_rts_msg() on each received
33 #                                               message with type == 5.
34 #       
35 #                                       sender which sends n "pings" to the caller process
36 #
37 #                               The script assumes that all three proessess are running on the same
38 #                               host/container such that setting up the route table with localhost:port
39 #                               will work.
40 #
41 #                               The number of message, and the delay between each message may be given
42 #                               on the command line. The number of threads may also be given. The
43 #                               number of messages defines the number _each_ caller will sent (5000 
44 #                               messages and three threads == 15,000 total messages.
45 #
46 #                               Example command line:
47 #                                       ksh ./run_call_test.ksh         # default 10 messages at 1 msg/sec 3 threads
48 #                                       ksh ./run_call_test.ksh -n 5000  -t 6 -d 400    # 5k messages, 6 threads, delay 400 mus
49 #
50 #       Date:           20 May 2019
51 #       Author:         E. Scott Daniels
52 # ---------------------------------------------------------------------------------
53
54
55 # The sender and receiver are run asynch. Their exit statuses are captured in a
56 # file in order for the 'main' to pick them up easily.
57 #
58 function run_sender {
59         ./caller${si} $nmsg $delay $nthreads
60         echo $? >/tmp/PID$$.src         # must communicate state back via file b/c asynch
61 }
62
63 # start receiver listening for nmsgs from each thread
64 function run_rcvr {
65         ./mt_receiver${si} $(( nmsg * nthreads ))               # we'll test with the RMr multi threaded receive function
66         echo $? >/tmp/PID$$.rrc
67 }
68
69 # This will send 100 messages to the caller process. This is a test to verify that
70 # threaded calling is not affected by normal messages and that normal messages can
71 # be received concurrently.
72 #
73 function run_pinger {
74     RMR_RTG_SVC=9999 ./sender${si} 100 100 4 3333 >/dev/NULL 2>&1  # send pings
75 }
76
77
78 # Generate a route table that is tailored to our needs of sender sending messages to
79 # the caller, and caller sending mtype == 5 to the receiver.
80 #
81 function mk_rt {
82
83 cat <<endKat >caller.rt
84 # this is a specialised rt for caller testing. mtype 5 go to the
85 # receiver, and all others go to the caller.
86
87 newrt | start
88 mse | 0 |  0 | $localhost:43086
89 mse | 1 | 10 | $localhost:43086
90 mse | 2 | 20 | $localhost:43086
91 rte | 3 | $localhost:43086
92 mse | 3 | 100 | $localhost:43086        # special test to ensure that this does not affect previous entry
93 rte | 4 | $localhost:43086
94 rte | 5 | $localhost:4560
95 rte | 6 | $localhost:43086
96 rte | 7 | $localhost:43086
97 rte | 8 | $localhost:43086
98 rte | 9 | $localhost:43086
99 rte | 10 | $localhost:43086
100 rte | 11 | $localhost:43086
101 rte | 12 | $localhost:43086
102 rte | 13 | $localhost:43086
103
104 newrt | end | 16
105 endKat
106 }
107
108 # ---------------------------------------------------------
109
110 nmsg=10                                         # total number of messages to be exchanged (-n value changes)
111 delay=1000000                           # microsec sleep between msg 1,000,000 == 1s
112 wait=1
113 rebuild=0
114 verbose=0
115 nthreads=3
116 dev_base=1                                      # -D turns off to allow this to run on installed libs
117 force_make=0
118 si=""
119 localhost="127.0.0.1"
120
121
122
123 while [[ $1 == -* ]]
124 do
125         case $1 in
126                 -B)     rebuild=1;;
127                 -d)     delay=$2; shift;;
128                 -D)     dev_base=0;;
129                 -n)     nmsg=$2; shift;;
130                 -M)     force_make=1;;
131                 -N)     si="";;                                                 # ignored for back compat; NNG not supported; all binaries are si95
132                 -S)     si="";;                                                 # ignored for back compat; all binaries are si95 and no _si suffix is used
133                 -N) si="";;                                             # enable NNG testing (off si)
134                 -t)     nthreads=$2; shift;;
135                 -v)     verbose=1;;
136
137                 *)      echo "unrecognised option: $1"
138                         echo "usage: $0 [-B] [-d micro-sec-delay] [-M] [-n num-msgs] [-S] [-t num-threads]"
139                         echo "  -B forces an RMR rebuild which will use .build"
140                         echo "  -M force test applications to rebuild"
141                         echo "  -S build/test SI95 based binaries"
142                         exit 1
143                         ;;
144         esac
145
146         shift
147 done
148
149 if (( verbose ))
150 then
151         echo "2" >.verbose
152         export RMR_VCTL_FILE=".verbose"
153 fi
154
155 if (( rebuild ))
156 then
157         build_path=../../.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 [[ -z $LD_LIBRARY_PATH ]]                                    # cmake test will set and it must be honoured
173 then
174         if (( dev_base ))                                                       # assume we are testing against what we've built, not what is installed
175         then
176                 if [[ -d $build_path/lib64 ]]
177                 then
178                         export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH
179                 else
180                         export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH
181                 fi
182                 export LIBRARY_PATH=$LD_LIBRARY_PATH
183         else                                                                            # -D option gets us here to test an installed library
184                 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
185                 export LIBRARY_PATH=$LD_LIBRARY_PATH
186         fi
187 fi
188
189 export RMR_SEED_RT=${RMR_SEED_RT:-./caller.rt}          # allow easy testing with different rt
190
191 if [[ ! -f $RMR_SEED_RT ]]                                                      # special caller rt for three process setup
192 then
193         mk_rt
194 fi
195
196 if (( rebuild || force_make )) || [[ ! -f ./sender${si} || ! -f ./caller${si} || ! -f ./mt_receiver${si} ]]
197 then
198         if ! make -B sender${si} caller${si} mt_receiver${si} >/tmp/PID$$.log 2>&1
199         then
200                 echo "[FAIL] cannot find caller{$si} and/or mt_receiver${si} binary, and cannot make them.... humm?"
201                 cat /tmp/PID$$.log
202                 rm -f /tmp/PID$$.*
203                 exit 1
204         fi
205 fi
206
207 run_rcvr &
208 sleep 2                         # if caller starts faster than rcvr we can drop, so pause a bit
209 run_sender &
210 run_pinger &
211
212 wait
213 head -1 /tmp/PID$$.rrc | read rrc               # get pass/fail state from each
214 head -1 /tmp/PID$$.src | read src
215
216 if (( !! (src + rrc) ))
217 then
218         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
219 else
220         echo "[PASS] sender rc=$src  receiver rc=$rrc"
221 fi
222
223 rm /tmp/PID$$.*
224 rm -f .verbose
225
226 exit $(( !! (src + rrc) ))
227