3 # vim: ts=4 sw=4 noet :
4 #==================================================================================
5 # Copyright (c) 2019-2021 Nokia
6 # Copyright (c) 2018-2021 AT&T Intellectual Property.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #==================================================================================
22 # ---------------------------------------------------------------------------------
23 # Mnemonic: run_app_test.ksh
24 # Abstract: This is a simple script to set up and run the basic send/receive
25 # processes for some library validation on top of nng.
26 # It should be possible to clone the repo, switch to this directory
27 # and execute 'ksh run -B' which will build RMr, make the sender and
28 # recevier then run the basic test.
30 # Example command line:
31 # ksh ./run_app_test.ksh # default 20 messages at 2 msg/sec
32 # ksh ./run_app_test.ksh -d 100 -n 10000 # send 10k messages with 100ms delay between
35 # Author: E. Scott Daniels
36 # ---------------------------------------------------------------------------------
39 # The sender and receiver are run asynch. Their exit statuses are captured in a
40 # file in order for the 'main' to pick them up easily.
44 # first we send an invalid message with a negative message length
45 # as per RIC-989 / CVE-2023-40998 processes used to crash for such
46 # invalid size data. So this test case would fail with a crash
47 # if for some reason the bug comes back.
49 bash ./create_invalid_request.sh
50 cat /tmp/invalid_data.bin |netcat -w 2 127.0.0.1 4560
52 echo $? >/tmp/PID$$.src # must communicate state back via file b/c asynch
55 # now let's send still one valid message over another TCP
57 bash ./create_valid_request.sh
58 cat /tmp/valid_data.bin|netcat -w 2 127.0.0.1 4560
63 export RMR_LOG_VLEVEL=5
66 echo "<TEST> testing with mt-receiver" >&2
67 ./mt_receiver${si} $nmsg
71 echo $? >/tmp/PID$$.rrc
74 # snarf the first v4 IP (not the loopback) that belongs to this box/container/guest
76 ip addr| sed -e '/inet /b c; d' -e ':c' -e '/127.0.0.1/d; s!/.*!!; s!^.* !!; q'
79 # Drop a contrived route table in. This table should add a reference to our
80 # local IP to an entry to ensure that the route table collector code in RMr
81 # is removing 'hairpin' loops. If RMr isn't removing the references to our
82 # hostname and IP address when it builds the endpoint lists, the sender will
83 # send messages to itself some of the time, causing the receiver to come up
84 # short when comparing messages received with expected count and thus failing.
87 typeset port=4560 # port the receiver listens on by default
89 cat <<endKat >app_test.rt
91 mse | 0 | 0 | 127.0.0.1:$port,$my_ip:43086
92 mse | 1 | 10 | 127.0.0.1:$port,${my_host//.*/}:43086
93 mse | 2 | 20 | 127.0.0.1:$port
94 rte | 3 | 127.0.0.1:$port
95 mse | 3 | 100 | 127.0.0.1:$port # special test to ensure that this does not affect previous entry
96 rte | 4 | 127.0.0.1:$port
97 rte | 5 | 127.0.0.1:$port
98 rte | 6 | 127.0.0.1:$port
99 rte | 7 | 127.0.0.1:$port
100 rte | 8 | 127.0.0.1:$port
101 rte | 9 | 127.0.0.1:$port
102 rte | 10 | 127.0.0.1:$port
103 rte | 11 | 127.0.0.1:$port
104 rte | 12 | 127.0.0.1:$port
105 rte | 13 | 127.0.0.1:$port
114 # ---------------------------------------------------------
116 nmsg=1 # total number of messages to be exchanged (-n value changes)
117 # need two sent to each receiver to ensure hairpin entries were removed (will fail if they were not)
118 delay=100000 # microsec sleep between msg 1,000,000 == 1s
121 nopull="" # -b sets so that build does not pull
124 my_ip=$(snarf_ip) # get an ip to insert into the route table
126 mt_receiver=0 # -m sets in order to test with multi-threaded receive stuff
129 echo --------------------
130 echo running test for negative message size
131 echo --------------------
137 -B) rebuild=1;; # build with pull first
138 -b) rebuild=1; nopull="nopull";; # buld without pull
139 -d) delay=$2; shift;;
141 -i) use_installed=1;;
145 -N) ;; # ignored for back compat; NNG not supported; all binaries are si95
146 -S) ;; # ignored for back compat; all binaries are si95 and no _si suffix is used
149 *) echo "unrecognised option: $1"
150 echo "usage: $0 [-B] [-d micor-sec-delay] [-i] [-k] [-M] [-m] [-n num-msgs] [-S]"
151 echo " -B forces an RMR rebuild which will use .build"
152 echo " -i causes the installd libraries (/usr/local) to be referenced; -B is ignored if supplied"
153 echo " -k keeps the route table"
154 echo " -M force make on test applications"
155 echo " -m test with mt-receive mode"
156 echo " -S build/test SI95 based binaries"
158 echo "total number of messages must > 20 to correctly test hairpin loop removal"
166 if [[ ! -f app_test.rt ]] # we need the real host name in the local.rt; build one from mask if not there
179 export RMR_VCTL_FILE=".verbose"
183 if (( use_installed )) # point at installed library rather than testing the build
185 export LD_LIBRARY_PATH=/usr/local/lib
186 export LIBRARY_PATH=$LD_LIBRARY_PATH
191 $SHELL ./rebuild.ksh $nopull | read build_path
194 build_path=${BUILD_PATH:-"../../.build"} # we prefer .build at the root level, but allow user option
196 if [[ ! -d $build_path ]]
198 echo "[FAIL] cannot find build in: $build_path"
199 echo "[FAIL] either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
204 if [[ -z $LD_LIBRARY_PATH ]] # the cmake test environment will set this; we must use if set
206 if [[ -d $build_path/lib64 ]]
208 export LD_LIBRARY_PATH=$build_path:$build_path/lib64
210 export LD_LIBRARY_PATH=$build_path:$build_path/lib
213 export LIBRARY_PATH=$LD_LIBRARY_PATH
216 export RMR_SEED_RT=${RMR_SEED_RT:-./app_test.rt} # allow easy testing with different rt
218 if (( force_make )) || [[ ! -f ./sender${si} || ! -f ./receiver${si} ]]
220 if ! make -B sender${si} receiver${si} >/tmp/PID$$.clog 2>&1
222 echo "[FAIL] cannot find sender${si} and/or receiver${si} binary, and cannot make them.... humm?"
223 echo "[INFO] ------------- PATH settings -----------------"
225 echo "[INFO] ------------- compiler output (head) -----------------"
226 head -50 /tmp/PID$$.clog
234 sleep 2 # if sender starts faster than rcvr we can drop msgs, so pause a bit
235 netstat -nptl|grep receiver
236 netstat -nptl|grep sender
241 head -1 /tmp/PID$$.rrc | read rrc
242 head -1 /tmp/PID$$.src | read src
244 if (( !! (src + rrc) ))
246 echo "[FAIL] sender rc=$src receiver rc=$rrc"
248 echo "[PASS] sender rc=$src receiver rc=$rrc"
259 exit $(( !! (src + rrc) ))