f6e16b45c561d33235ae054c4a7f67cabf8d6281
[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 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 | localhost: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
82 while [[ $1 == -* ]]
83 do
84         case $1 in
85                 -B)     rebuild=1;;
86                 -b)     rebuild=1; nopull="nopull";;    # build without pulling
87                 -d)     delay=$2; shift;;
88                 -n)     nmsg=$2; shift;;
89                 -s)     nsenders=$2; shift;;
90                 -v)     verbose=1;;
91
92                 *)      echo "unrecognised option: $1"
93                         echo "usage: $0 [-B] [-d micor-sec-delay] [-n num-msgs] [-s nsenders]"
94                         echo "  -B forces a rebuild which will use .build"
95                         exit 1
96                         ;;
97         esac
98
99         shift
100 done
101
102 if (( verbose ))
103 then
104         echo "2" >.verbose
105         export RMR_VCTL_FILE=".verbose"
106 fi
107
108 if (( rebuild ))
109 then
110         set -e
111         ksh ./rebuild.ksh $nopull | read build_path
112         set +e
113 else
114         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
115
116         if [[ ! -d $build_path ]]
117         then
118                 echo "cannot find build in: $build_path"
119                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
120                 exit 1
121         fi
122 fi
123
124 if [[ -d $build_path/lib64 ]]
125 then
126         export LD_LIBRARY_PATH=$build_path:$build_path/lib64
127 else
128         export LD_LIBRARY_PATH=$build_path:$build_path/lib
129 fi
130 export LIBRARY_PATH=$LD_LIBRARY_PATH
131 export RMR_SEED_RT=./rts.rt
132
133 set_rt          # create the route table
134
135 if [[ ! -f ./sender ]]
136 then
137         if ! make >/dev/null 2>&1
138         then
139                 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
140                 exit 1
141         fi
142 fi
143
144 run_rcvr &
145
146 sleep 2                         # let receivers init so we don't shoot at an empty target
147 for (( i=0; i < nsenders; i++ ))                # start the receivers with an instance number
148 do
149         run_sender $i &
150 done
151
152 wait
153
154
155 for (( i=0; i < nsenders; i++ ))                # collect return codes
156 do
157         head -1 /tmp/PID$$.$i.src | read x
158         (( src += x ))
159 done
160
161 head -1 /tmp/PID$$.rrc | read rrc
162
163 if (( !! (src + rrc) ))
164 then
165         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
166 else
167         echo "[PASS] sender rc=$src  receiver rc=$rrc"
168         rm -f multi.rt
169 fi
170
171 rm /tmp/PID$$.*
172 rm -f .verbose
173
174 exit $(( !! (src + rrc) ))
175