test(e2e): Add return to sender app based test
[ric-plt/lib/rmr.git] / test / app_test / run_rts_test.ksh
1 #!/usr/bin/env ksh
2 # :vi ts=4 sw=4 noet :
3 #==================================================================================
4 #    Copyright (c) 2019 Nokia
5 #    Copyright (c) 2018-2019 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_rts_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 nano/nng. This
25 #                               particular test starts several senders and one receiver. All messages
26 #                               go to the receiver and an ack is sent back to the sending process.
27 #                               Each sender puts a tag into the message allowing it to verify that
28 #                               all messages received were 'acks' to the ones it sent, and that no
29 #                               rts messages were routed to the wrong sender.
30 #
31 #                               Example command line:
32 #
33 #       Date:           15 May 2019
34 #       Author:         E. Scott Daniels
35 # ---------------------------------------------------------------------------------
36
37
38 # The sender and receivers are run asynch. Their exit statuses are captured in a
39 # file in order for the 'main' to pick them up easily.
40 # $1 is the instance so we can keep logs separate.
41 #
42 function run_sender {
43         export RMR_RTG_SVC=$(( 9991 + $1 ))
44         port=$((  43080 + $1 ))
45         if (( $nano_sender ))
46         then
47                 ./sender_nano $nmsg $delay 5:6 $port    # 5:6 causes mtype 5 only which is what receiver acks
48         else
49                 ./sender $nmsg $delay 5:6 $port
50         fi
51         echo $? >/tmp/PID$$.$1.src              # must communicate state back via file b/c asynch
52 }
53
54 # $1 is the instance so we can keep logs separate
55 function run_rcvr {
56         typeset port
57
58         port=4460
59         export RMR_RTG_SVC=9990
60         if (( $nano_receiver ))
61         then
62                 ./receiver_nano $(( nmsg * nsenders ))  $port
63         else
64                 ./receiver $(( nmsg * nsenders ))  $port
65         fi
66         echo $? >/tmp/PID$$.rrc
67 }
68
69 #       Drop in a contrived route table. It should have only one entry which points
70 #       message type 0 to the receiver.  The sender must NOT be defined for a valid
71 #       tests (rts should not require the sendter be in the route thable).
72 #
73 function set_rt {
74         cat <<endKat >rts.rt
75                 newrt | start
76                 mse |5 | -1 | localhost:4460
77                 newrt | end
78 endKat
79
80 }
81
82 # ---------------------------------------------------------
83
84 nmsg=10                                         # total number of messages to be exchanged (-n value changes)
85 delay=1000000                           # microsec sleep between msg 1,000,000 == 1s
86 nano_sender=0                           # start nano version if set (-N)
87 nano_receiver=0
88 wait=1
89 rebuild=0
90 nopull=""
91 verbose=0
92 nsenders=3                                      # this is sane, but -s allows it to be set up
93
94 while [[ $1 == -* ]]
95 do
96         case $1 in
97                 -B)     rebuild=1;;
98                 -b)     rebuild=1; nopull="nopull";;    # build without pulling
99                 -d)     delay=$2; shift;;
100                 -N)     nano_sender=1
101                         nano_receiver=1
102                         ;;
103                 -n)     nmsg=$2; shift;;
104                 -s)     nsenders=$2; shift;;
105                 -v)     verbose=1;;
106
107                 *)      echo "unrecognised option: $1"
108                         echo "usage: $0 [-B] [-d micor-sec-delay] [-N] [-n num-msgs] [-s nsenders]"
109                         echo "  -B forces a rebuild which will use .build"
110                         exit 1
111                         ;;
112         esac
113
114         shift
115 done
116
117 if (( verbose ))
118 then
119         echo "2" >.verbose
120         export RMR_VCTL_FILE=".verbose"
121 fi
122
123 if (( rebuild ))
124 then
125         set -e
126         ksh ./rebuild.ksh $nopull | read build_path
127         set +e
128 else
129         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
130
131         if [[ ! -d $build_path ]]
132         then
133                 echo "cannot find build in: $build_path"
134                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
135                 exit 1
136         fi
137 fi
138
139 if [[ -d $build_path/lib64 ]]
140 then
141         export LD_LIBRARY_PATH=$build_path:$build_path/lib64
142 else
143         export LD_LIBRARY_PATH=$build_path:$build_path/lib
144 fi
145 export LIBRARY_PATH=$LD_LIBRARY_PATH
146 export RMR_SEED_RT=./rts.rt
147
148 set_rt          # create the route table
149
150 if [[ ! -f ./sender ]]
151 then
152         if ! make >/dev/null 2>&1
153         then
154                 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
155                 exit 1
156         fi
157 fi
158
159 run_rcvr &
160
161 sleep 2                         # let receivers init so we don't shoot at an empty target
162 for (( i=0; i < nsenders; i++ ))                # start the receivers with an instance number
163 do
164         run_sender $i &
165 done
166
167 wait
168
169
170 for (( i=0; i < nsenders; i++ ))                # collect return codes
171 do
172         head -1 /tmp/PID$$.$i.src | read x
173         (( src += x ))
174 done
175
176 head -1 /tmp/PID$$.rrc | read rrc
177
178 if (( !! (src + rrc) ))
179 then
180         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
181 else
182         echo "[PASS] sender rc=$src  receiver rc=$rrc"
183         rm -f multi.rt
184 fi
185
186 rm /tmp/PID$$.*
187 rm -f .verbose
188
189 exit $(( !! (src + rrc) ))
190