blob: b4795307f6e79839a3739e5527c7e39aeb8054c6 [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
arehbeincf8c4502022-11-13 17:52:48 +010019 if ! [ -e "$1" ] && [ -s "$1" ]; then
20 $SUDOSTR kill "$(cat "$1")" 2>&1 | grep -v "No such process"
21 rm $1
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020022 fi
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020023}
24
Neels Hofmeyrced8acf2019-02-26 05:03:22 +010025date
26
arehbeinbf45a5c2022-11-13 18:48:58 +010027# -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 +010028# SHELL environment variable doesn't always give name of current shell (e.g. for dash run inside bash...)
29SHELL_NAME="$(cat /proc/$$/cmdline | tr -d '\0')"
30if [ "$SHELL_NAME" = "bash" ]; then
arehbeinbf45a5c2022-11-13 18:48:58 +010031 ESCAPE_OPT="-e"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020032else
arehbeinbf45a5c2022-11-13 18:48:58 +010033 ESCAPE_OPT=""
34fi
35
36if [ x"$VERDICT" = x"pass" ]; then
37 echo $ESCAPE_OPT "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
38else
39 echo $ESCAPE_OPT "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020040fi
41echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010042
43if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
44 TTCN3_PCAP_PATH=/tmp
45fi
46
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030047# Order the SUT to print a talloc report
48if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then
49 if [ -x "$(command -v osmo_interact_vty.py)" ]; then
Oliver Smith9678c222021-12-17 12:04:11 +010050 echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc"
51 if ! timeout 5 osmo_interact_vty.py \
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030052 -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \
53 -c "en; show talloc-context application full" \
Oliver Smith9678c222021-12-17 12:04:11 +010054 > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then
55 echo
56 echo "ERROR: failed to get talloc report via vty"
57 echo
58 fi
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030059 else
60 echo "Missing osmo_interact_vty.py from osmo-python-tests!"
61 echo " -> Unable to obtain talloc report from the SUT"
62 fi
63fi
64
Maxe5214452019-03-14 18:15:27 +010065# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010066# otherwise we might lose last packets from test.
67i=0
68prev_count=-1
69count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
70while [ $count -gt $prev_count ] && [ $i -lt 2 ]
71do
Maxe5214452019-03-14 18:15:27 +010072 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010073 sleep 1
74 prev_count=$count
75 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
76 i=$((i+1))
77done
Harald Weltee0571462018-02-14 15:42:14 +010078
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020079kill_rm_pidfile "$PIDFILE_PCAP"
80kill_rm_pidfile "$PIDFILE_NETCAT"
arehbeinbc85a322022-11-13 18:46:32 +010081rm $FIFO
Vadim Yanitskiyf949f462020-07-12 15:49:37 +070082
Vadim Yanitskiyeb662c82020-07-13 05:50:06 +070083gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"