blob: dc39981456c687b70da25763119cfdae378a9c1c [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
arehbein81dbe602022-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
arehbein82f93ec2022-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
arehbein82f93ec2022-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
arehbeina63feac2022-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
arehbein6ff41c42022-11-13 22:28:01 +010028SHELL="$(cat /proc/$$/cmdline | tr -d '\0')"
29if [ "$SHELL" = "bash" ]; then
arehbeina63feac2022-11-13 18:48:58 +010030 ESCAPE_OPT="-e"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020031else
arehbeina63feac2022-11-13 18:48:58 +010032 ESCAPE_OPT=""
33fi
34
35if [ x"$VERDICT" = x"pass" ]; then
36 echo $ESCAPE_OPT "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
37else
38 echo $ESCAPE_OPT "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020039fi
40echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010041
42if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
43 TTCN3_PCAP_PATH=/tmp
44fi
45
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030046# Order the SUT to print a talloc report
47if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then
48 if [ -x "$(command -v osmo_interact_vty.py)" ]; then
Oliver Smith9678c222021-12-17 12:04:11 +010049 echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc"
50 if ! timeout 5 osmo_interact_vty.py \
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030051 -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \
52 -c "en; show talloc-context application full" \
Oliver Smith9678c222021-12-17 12:04:11 +010053 > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then
54 echo
55 echo "ERROR: failed to get talloc report via vty"
56 echo
57 fi
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030058 else
59 echo "Missing osmo_interact_vty.py from osmo-python-tests!"
60 echo " -> Unable to obtain talloc report from the SUT"
61 fi
62fi
63
Maxe5214452019-03-14 18:15:27 +010064# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010065# otherwise we might lose last packets from test.
66i=0
67prev_count=-1
68count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
69while [ $count -gt $prev_count ] && [ $i -lt 2 ]
70do
Maxe5214452019-03-14 18:15:27 +010071 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010072 sleep 1
73 prev_count=$count
74 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
75 i=$((i+1))
76done
Harald Weltee0571462018-02-14 15:42:14 +010077
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020078kill_rm_pidfile "$PIDFILE_PCAP"
79kill_rm_pidfile "$PIDFILE_NETCAT"
arehbein81dbe602022-11-13 18:46:32 +010080rm $FIFO
Vadim Yanitskiyf949f462020-07-12 15:49:37 +070081
Vadim Yanitskiyeb662c82020-07-13 05:50:06 +070082gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"