blob: 67966125438724e513b8c1ebd284321cbfc81286 [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
Pau Espin Pedroldada4c52018-02-15 16:07:23 +01005TESTCASE=$1
Neels Hofmeyrdadde172018-06-18 06:18:34 +02006VERDICT="$2"
7
arehbeincf8c4502022-11-13 17:52:48 +01008SUDOSTR=""
9if ! [ "$(id -u)" = "0" ]; then
10 SUDOSTR="sudo -n"
11 # Otherwise, if sudo /usr/bin/kill, sudo /usr/bin/tcpdump cannot be run without a password prompt,
12 # and this script will hang indefinitely
13fi
14
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020015kill_rm_pidfile() {
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020016 # NOTE: This requires you to be root or something like
17 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
arehbeincf8c4502022-11-13 17:52:48 +010018 if ! [ -e "$1" ] && [ -s "$1" ]; then
19 $SUDOSTR kill "$(cat "$1")" 2>&1 | grep -v "No such process"
20 rm $1
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020021 fi
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020022}
23
Neels Hofmeyrced8acf2019-02-26 05:03:22 +010024date
25
Neels Hofmeyrdadde172018-06-18 06:18:34 +020026if [ x"$VERDICT" = x"pass" ]; then
Vadim Yanitskiyaa94d322020-05-21 20:36:33 +070027 echo -e "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020028else
Vadim Yanitskiyaa94d322020-05-21 20:36:33 +070029 echo -e "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
Neels Hofmeyrdadde172018-06-18 06:18:34 +020030fi
31echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010032
33if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
34 TTCN3_PCAP_PATH=/tmp
35fi
36
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030037# Order the SUT to print a talloc report
38if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then
39 if [ -x "$(command -v osmo_interact_vty.py)" ]; then
Oliver Smith9678c222021-12-17 12:04:11 +010040 echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc"
41 if ! timeout 5 osmo_interact_vty.py \
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030042 -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \
43 -c "en; show talloc-context application full" \
Oliver Smith9678c222021-12-17 12:04:11 +010044 > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then
45 echo
46 echo "ERROR: failed to get talloc report via vty"
47 echo
48 fi
Vadim Yanitskiy23d66652021-11-28 21:41:07 +030049 else
50 echo "Missing osmo_interact_vty.py from osmo-python-tests!"
51 echo " -> Unable to obtain talloc report from the SUT"
52 fi
53fi
54
Maxe5214452019-03-14 18:15:27 +010055# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010056# otherwise we might lose last packets from test.
57i=0
58prev_count=-1
59count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
60while [ $count -gt $prev_count ] && [ $i -lt 2 ]
61do
Maxe5214452019-03-14 18:15:27 +010062 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010063 sleep 1
64 prev_count=$count
65 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
66 i=$((i+1))
67done
Harald Weltee0571462018-02-14 15:42:14 +010068
Pau Espin Pedrolad931f22019-10-02 13:00:51 +020069kill_rm_pidfile "$PIDFILE_PCAP"
70kill_rm_pidfile "$PIDFILE_NETCAT"
Vadim Yanitskiyf949f462020-07-12 15:49:37 +070071
Vadim Yanitskiyeb662c82020-07-13 05:50:06 +070072gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"