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.
48 bash ./create_invalid_request.sh
49 cat /tmp/invalid_data.bin |netcat -w 2 127.0.0.1 4560
51 # An invalid request with invalid header length information
52 # As per RIC-919 / CVE-2023-40997 this caused a crash. This
53 # test case is to make sure the bug does not come back
54 bash ./create_invalid_request2.sh
55 cat /tmp/invalid_data2.bin |netcat -w 2 127.0.0.1 4560
57 # now let's send still one valid message over another TCP
59 bash ./create_valid_request.sh
60 cat /tmp/valid_data.bin|netcat -w 2 127.0.0.1 4560
62 echo $? >/tmp/PID$$.src # must communicate state back via file b/c asynch
67 export RMR_LOG_VLEVEL=5
70 echo "<TEST> testing with mt-receiver" >&2
71 ./mt_receiver${si} $nmsg
75 echo $? >/tmp/PID$$.rrc
78 # snarf the first v4 IP (not the loopback) that belongs to this box/container/guest
80 ip addr| sed -e '/inet /b c; d' -e ':c' -e '/127.0.0.1/d; s!/.*!!; s!^.* !!; q'
83 # Drop a contrived route table in. This table should add a reference to our
84 # local IP to an entry to ensure that the route table collector code in RMr
85 # is removing 'hairpin' loops. If RMr isn't removing the references to our
86 # hostname and IP address when it builds the endpoint lists, the sender will
87 # send messages to itself some of the time, causing the receiver to come up
88 # short when comparing messages received with expected count and thus failing.
91 typeset port=4560 # port the receiver listens on by default
93 cat <<endKat >app_test.rt
95 mse | 0 | 0 | 127.0.0.1:$port,$my_ip:43086
96 mse | 1 | 10 | 127.0.0.1:$port,${my_host//.*/}:43086
97 mse | 2 | 20 | 127.0.0.1:$port
98 rte | 3 | 127.0.0.1:$port
99 mse | 3 | 100 | 127.0.0.1:$port # special test to ensure that this does not affect previous entry
100 rte | 4 | 127.0.0.1:$port
101 rte | 5 | 127.0.0.1:$port
102 rte | 6 | 127.0.0.1:$port
103 rte | 7 | 127.0.0.1:$port
104 rte | 8 | 127.0.0.1:$port
105 rte | 9 | 127.0.0.1:$port
106 rte | 10 | 127.0.0.1:$port
107 rte | 11 | 127.0.0.1:$port
108 rte | 12 | 127.0.0.1:$port
109 rte | 13 | 127.0.0.1:$port
118 # ---------------------------------------------------------
120 nmsg=1 # total number of messages to be exchanged (-n value changes)
121 # need two sent to each receiver to ensure hairpin entries were removed (will fail if they were not)
122 delay=100000 # microsec sleep between msg 1,000,000 == 1s
125 nopull="" # -b sets so that build does not pull
128 my_ip=$(snarf_ip) # get an ip to insert into the route table
130 mt_receiver=0 # -m sets in order to test with multi-threaded receive stuff
133 echo --------------------
134 echo running test for negative message size
135 echo --------------------
141 -B) rebuild=1;; # build with pull first
142 -b) rebuild=1; nopull="nopull";; # buld without pull
143 -d) delay=$2; shift;;
145 -i) use_installed=1;;
149 -N) ;; # ignored for back compat; NNG not supported; all binaries are si95
150 -S) ;; # ignored for back compat; all binaries are si95 and no _si suffix is used
153 *) echo "unrecognised option: $1"
154 echo "usage: $0 [-B] [-d micor-sec-delay] [-i] [-k] [-M] [-m] [-n num-msgs] [-S]"
155 echo " -B forces an RMR rebuild which will use .build"
156 echo " -i causes the installd libraries (/usr/local) to be referenced; -B is ignored if supplied"
157 echo " -k keeps the route table"
158 echo " -M force make on test applications"
159 echo " -m test with mt-receive mode"
160 echo " -S build/test SI95 based binaries"
162 echo "total number of messages must > 20 to correctly test hairpin loop removal"
170 if [[ ! -f app_test.rt ]] # we need the real host name in the local.rt; build one from mask if not there
183 export RMR_VCTL_FILE=".verbose"
187 if (( use_installed )) # point at installed library rather than testing the build
189 export LD_LIBRARY_PATH=/usr/local/lib
190 export LIBRARY_PATH=$LD_LIBRARY_PATH
195 $SHELL ./rebuild.ksh $nopull | read build_path
198 build_path=${BUILD_PATH:-"../../.build"} # we prefer .build at the root level, but allow user option
200 if [[ ! -d $build_path ]]
202 echo "[FAIL] cannot find build in: $build_path"
203 echo "[FAIL] either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
208 if [[ -z $LD_LIBRARY_PATH ]] # the cmake test environment will set this; we must use if set
210 if [[ -d $build_path/lib64 ]]
212 export LD_LIBRARY_PATH=$build_path:$build_path/lib64
214 export LD_LIBRARY_PATH=$build_path:$build_path/lib
217 export LIBRARY_PATH=$LD_LIBRARY_PATH
220 export RMR_SEED_RT=${RMR_SEED_RT:-./app_test.rt} # allow easy testing with different rt
222 if (( force_make )) || [[ ! -f ./sender${si} || ! -f ./receiver${si} ]]
224 if ! make -B sender${si} receiver${si} >/tmp/PID$$.clog 2>&1
226 echo "[FAIL] cannot find sender${si} and/or receiver${si} binary, and cannot make them.... humm?"
227 echo "[INFO] ------------- PATH settings -----------------"
229 echo "[INFO] ------------- compiler output (head) -----------------"
230 head -50 /tmp/PID$$.clog
238 sleep 2 # if sender starts faster than rcvr we can drop msgs, so pause a bit
239 netstat -nptl|grep receiver
240 netstat -nptl|grep sender
245 head -1 /tmp/PID$$.rrc | read rrc
246 head -1 /tmp/PID$$.src | read src
248 if (( !! (src + rrc) ))
250 echo "[FAIL] sender rc=$src receiver rc=$rrc"
252 echo "[PASS] sender rc=$src receiver rc=$rrc"
263 exit $(( !! (src + rrc) ))