blob: 0feaeaa9cc1573047b83e3e641a761ac7ee74d5f [file] [log] [blame]
Harald Weltee0571462018-02-14 15:42:14 +01001#!/bin/sh
2
Pau Espin Pedrolad931f22019-10-02 13:00:51 +02003PIDFILE_PCAP=/tmp/pcap.pid
4PIDFILE_NETCAT=/tmp/netcat.pid
arehbeinbc85a322022-11-13 18:46:32 +01005FIFO=/tmp/cmderr
Pau Espin Pedroldada4c52018-02-15 16:07:23 +01006TESTCASE=$1
Neels Hofmeyrdadde172018-06-18 06:18:34 +02007VERDICT="$2"
8
arehbeincf8c4502022-11-13 17:52:48 +01009SUDOSTR=""
10if ! [ "$(id -u)" = "0" ]; then
11 SUDOSTR="sudo -n"
12 # Otherwise, if sudo /usr/bin/kill, sudo /usr/bin/tcpdump cannot be run without a password prompt,
13 # and this script will hang indefinitely
14fi
15
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020016kill_rm_pidfile() {
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020017 # NOTE: This requires you to be root or something like
18 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
arehbeine66c1f82022-11-28 22:39:21 +010019 if [ -e "$1" ]; then
20 if [ -s "$1" ]; then
21 $SUDOSTR kill "$(cat "$1")" 2>&1 | grep -v "No such process"
22 fi
arehbeincf8c4502022-11-13 17:52:48 +010023 rm $1
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020024 fi
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020025}
26
Neels Hofmeyrced8acf2019-02-26 05:03:22 +010027date
28
arehbeinbf45a5c2022-11-13 18:48:58 +010029# -e only works/is required only in Bash; in dash/POSIX shells it isn't required and will be part of the output
arehbeinbe074e12022-11-13 22:28:01 +010030# SHELL environment variable doesn't always give name of current shell (e.g. for dash run inside bash...)
31SHELL_NAME="$(cat /proc/$$/cmdline | tr -d '\0')"
32if [ "$SHELL_NAME" = "bash" ]; then
arehbeinbf45a5c2022-11-13 18:48:58 +010033 ESCAPE_OPT="-e"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020034else
arehbeinbf45a5c2022-11-13 18:48:58 +010035 ESCAPE_OPT=""
36fi
37
38if [ x"$VERDICT" = x"pass" ]; then
39 echo $ESCAPE_OPT "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
40else
41 echo $ESCAPE_OPT "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020042fi
43echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010044
45if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
46 TTCN3_PCAP_PATH=/tmp
47fi
48
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030049# Order the SUT to print a talloc report
50if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then
51 if [ -x "$(command -v osmo_interact_vty.py)" ]; then
Oliver Smith9678c222021-12-17 12:04:11 +010052 echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc"
53 if ! timeout 5 osmo_interact_vty.py \
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030054 -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \
55 -c "en; show talloc-context application full" \
Oliver Smith9678c222021-12-17 12:04:11 +010056 > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then
57 echo
58 echo "ERROR: failed to get talloc report via vty"
59 echo
60 fi
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030061 else
62 echo "Missing osmo_interact_vty.py from osmo-python-tests!"
63 echo " -> Unable to obtain talloc report from the SUT"
64 fi
65fi
66
Maxe5214452019-03-14 18:15:27 +010067# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010068# otherwise we might lose last packets from test.
69i=0
70prev_count=-1
71count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
72while [ $count -gt $prev_count ] && [ $i -lt 2 ]
73do
Maxe5214452019-03-14 18:15:27 +010074 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010075 sleep 1
76 prev_count=$count
77 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
78 i=$((i+1))
79done
Harald Weltee0571462018-02-14 15:42:14 +010080
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020081kill_rm_pidfile "$PIDFILE_PCAP"
82kill_rm_pidfile "$PIDFILE_NETCAT"
arehbeinbc85a322022-11-13 18:46:32 +010083rm $FIFO
Vadim Yanitskiyf949f462020-07-12 15:49:37 +070084
Vadim Yanitskiyeb662c82020-07-13 05:50:06 +070085gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"