blob: 829ed2b20541bd777c870b3f7446e15be45642ea [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
Neels Hofmeyrdadde172018-06-18 06:18:34 +020027if [ x"$VERDICT" = x"pass" ]; then
Vadim Yanitskiyaa94d322020-05-21 20:36:33 +070028 echo -e "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020029else
Vadim Yanitskiyaa94d322020-05-21 20:36:33 +070030 echo -e "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020031fi
32echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010033
34if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
35 TTCN3_PCAP_PATH=/tmp
36fi
37
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030038# Order the SUT to print a talloc report
39if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then
40 if [ -x "$(command -v osmo_interact_vty.py)" ]; then
Oliver Smith9678c222021-12-17 12:04:11 +010041 echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc"
42 if ! timeout 5 osmo_interact_vty.py \
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030043 -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \
44 -c "en; show talloc-context application full" \
Oliver Smith9678c222021-12-17 12:04:11 +010045 > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then
46 echo
47 echo "ERROR: failed to get talloc report via vty"
48 echo
49 fi
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030050 else
51 echo "Missing osmo_interact_vty.py from osmo-python-tests!"
52 echo " -> Unable to obtain talloc report from the SUT"
53 fi
54fi
55
Maxe5214452019-03-14 18:15:27 +010056# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010057# otherwise we might lose last packets from test.
58i=0
59prev_count=-1
60count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
61while [ $count -gt $prev_count ] && [ $i -lt 2 ]
62do
Maxe5214452019-03-14 18:15:27 +010063 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010064 sleep 1
65 prev_count=$count
66 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
67 i=$((i+1))
68done
Harald Weltee0571462018-02-14 15:42:14 +010069
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020070kill_rm_pidfile "$PIDFILE_PCAP"
71kill_rm_pidfile "$PIDFILE_NETCAT"
arehbeinbc85a322022-11-13 18:46:32 +010072rm $FIFO
Vadim Yanitskiyf949f462020-07-12 15:49:37 +070073
Vadim Yanitskiyeb662c82020-07-13 05:50:06 +070074gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"