CI: Add silent cmake SonarCloud scan
[ric-plt/lib/rmr.git] / test / app_test / run_rts_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_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 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         ./sender $nmsg $delay 5:6 $port
46         echo $? >/tmp/PID$$.$1.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
54         export RMR_RTG_SVC=9990
55         ./receiver $(( nmsg * nsenders ))  $port
56         echo $? >/tmp/PID$$.rrc
57 }
58
59 #       Drop in a contrived route table. It should have only one entry which points
60 #       message type 0 to the receiver.  The sender must NOT be defined for a valid
61 #       tests (rts should not require the sendter be in the route thable).
62 #
63 function set_rt {
64         cat <<endKat >rts.rt
65                 newrt | start
66                 mse |5 | -1 | 127.0.0.1:4460
67                 newrt | end
68 endKat
69
70 }
71
72 # ---------------------------------------------------------
73
74 nmsg=10                                         # total number of messages to be exchanged (-n value changes)
75 delay=1000000                           # microsec sleep between msg 1,000,000 == 1s
76 wait=1
77 rebuild=0
78 nopull=""
79 verbose=0
80 nsenders=3                                      # this is sane, but -s allows it to be set up
81 si=""
82
83 while [[ $1 == -* ]]
84 do
85         case $1 in
86                 -B)     rebuild=1;;
87                 -b)     rebuild=1; nopull="nopull";;    # build without pulling
88                 -d)     delay=$2; shift;;
89                 -n)     nmsg=$2; shift;;
90                 -N) ;;                                                  # ignored for back compat -- nng no longer supported
91                 -s)     nsenders=$2; shift;;
92                 -S) ;;                                                  # ignored for back compat -- si is only supported transport
93                 -v)     verbose=1;;
94
95                 *)      echo "unrecognised option: $1"
96                         echo "usage: $0 [-B] [-d micor-sec-delay] [-M] [-n num-msgs] [-s nsenders] [-S]"
97                         echo "  -B forces a rebuild which will use .build"
98                         echo "  -M force test applications to be remade"
99                         echo "  -S build/test SI95 based binaries"
100                         exit 1
101                         ;;
102         esac
103
104         shift
105 done
106
107 if (( verbose ))
108 then
109         echo "2" >.verbose
110         export RMR_VCTL_FILE=".verbose"
111 fi
112
113 if (( rebuild ))
114 then
115         set -e
116         $SHELL ./rebuild.ksh $nopull | read build_path
117         set +e
118 else
119         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
120
121         if [[ ! -d $build_path ]]
122         then
123                 echo "cannot find build in: $build_path"
124                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
125                 exit 1
126         fi
127 fi
128
129 if [[ -z LD_LIBRARY_PATH ]]                     # honour if cmake test sets it
130 then
131         if [[ -d $build_path/lib64 ]]
132         then
133                 export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH
134         else
135                 export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH
136         fi
137 fi
138
139 export LIBRARY_PATH=$LD_LIBRARY_PATH
140 export RMR_SEED_RT=./rts.rt
141
142 set_rt          # create the route table
143
144 if [[ ! -f ./sender || ! -f ./receiver ]]
145 then
146         if ! make ./sender ./receiver >/dev/null 2>&1
147         then
148                 echo "[FAIL] cannot find sender and/or receiver binary, and cannot make them.... humm?"
149                 exit 1
150         fi
151 fi
152
153 run_rcvr &
154
155 sleep 2                         # let receivers init so we don't shoot at an empty target
156 for (( i=0; i < nsenders; i++ ))                # start the receivers with an instance number
157 do
158         run_sender $i &
159 done
160
161 wait
162
163
164 for (( i=0; i < nsenders; i++ ))                # collect return codes
165 do
166         head -1 /tmp/PID$$.$i.src | read x
167         (( src += x ))
168 done
169
170 head -1 /tmp/PID$$.rrc | read rrc
171
172 if (( !! (src + rrc) ))
173 then
174         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
175 else
176         echo "[PASS] sender rc=$src  receiver rc=$rrc"
177         rm -f multi.rt
178 fi
179
180 rm /tmp/PID$$.*
181 rm -f .verbose
182
183 exit $(( !! (src + rrc) ))
184