Remove nanomsg support from app test scripts
[ric-plt/lib/rmr.git] / test / app_test / run_multi_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_multi_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 tests starts several receivers and creates a route table
26 #                               which causes messages to be sent to all receivers in parallel
27 #                               (forcing message cloning internally in RMr).
28 #                               It should be possible to clone the repo, switch to this directory
29 #                               and execute  'ksh run -B'  which will build RMr, make the sender and
30 #                               recevier then  run the basic test.
31 #
32 #                               Example command line:
33 #                                       ksh ./run_multi_test.ksh                # default 10 messages at 1 msg/sec
34 #                                       ksh ./run_multi_test.ksh -d 100 -n 10000 # send 10k messages with 100ms delay between
35 #
36 #       Date:           24 April 2019
37 #       Author:         E. Scott Daniels
38 # ---------------------------------------------------------------------------------
39
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         ./sender $nmsg $delay
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         ./receiver $nmsg $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 >multi.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 }
88
89 # ---------------------------------------------------------
90
91 if [[ ! -f local.rt ]]          # we need the real host name in the local.rt; build one from mask if not there
92 then
93         hn=$(hostname)
94         sed "s!%%hostname%%!$hn!" rt.mask >local.rt
95 fi
96
97 nmsg=10                                         # total number of messages to be exchanged (-n value changes)
98 delay=1000000                           # microsec sleep between msg 1,000,000 == 1s
99 wait=1
100 rebuild=0
101 nopull=""
102 verbose=0
103 nrcvrs=3                                        # this is sane, but -r allows it to be set up
104
105 while [[ $1 == -* ]]
106 do
107         case $1 in
108                 -B)     rebuild=1;;
109                 -b)     rebuild=1; nopull="nopull";;            # enable build but without pull
110                 -d)     delay=$2; shift;;
111                 -n)     nmsg=$2; shift;;
112                 -r)     nrcvrs=$2; shift;;
113                 -v)     verbose=1;;
114
115                 *)      echo "unrecognised option: $1"
116                         echo "usage: $0 [-B] [-d micor-sec-delay] [-n num-msgs]"
117                         echo "  -B forces an RMR rebuild which will use .build"
118                         exit 1
119                         ;;
120         esac
121
122         shift
123 done
124
125 if (( verbose ))
126 then
127         echo "2" >.verbose
128         export RMR_VCTL_FILE=".verbose"
129 fi
130
131 if (( rebuild ))
132 then
133         set -e
134         ksh ./rebuild.ksh $nopull | read build_path
135         set +e
136 else
137         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
138
139         if [[ ! -d $build_path ]]
140         then
141                 echo "cannot find build in: $build_path"
142                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
143                 exit 1
144         fi
145 fi
146
147 if [[ -d $build_path/lib64 ]]
148 then
149         export LD_LIBRARY_PATH=$build_path:$build_path/lib64
150 else
151         export LD_LIBRARY_PATH=$build_path:$build_path/lib
152 fi
153 export LIBRARY_PATH=$LD_LIBRARY_PATH
154 export RMR_SEED_RT=./multi.rt
155
156 set_rt $nrcvrs                                          # set up the rt for n receivers
157
158 if [[ ! -f ./sender ]]
159 then
160         if ! make >/dev/null 2>&1
161         then
162                 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
163                 exit 1
164         fi
165 fi
166
167 for (( i=0; i < nrcvrs; i++ ))          # start the receivers with an instance number
168 do
169         run_rcvr $i &
170 done
171
172 sleep 2                         # let receivers init so we don't shoot at an empty target
173 run_sender &
174
175 wait
176
177
178 for (( i=0; i < nrcvrs; i++ ))          # collect return codes
179 do
180         head -1 /tmp/PID$$.$i.rrc | read x
181         (( rrc += x ))
182 done
183
184 head -1 /tmp/PID$$.src | read src
185
186 if (( !! (src + rrc) ))
187 then
188         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
189 else
190         echo "[PASS] sender rc=$src  receiver rc=$rrc"
191         rm -f multi.rt
192 fi
193
194 rm /tmp/PID$$.*
195 rm -f .verbose
196
197 exit $(( !! (src + rrc) ))
198