Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 3 | PIDFILE_PCAP=/tmp/pcap.pid |
| 4 | PIDFILE_NETCAT=/tmp/netcat.pid |
arehbein | bc85a32 | 2022-11-13 18:46:32 +0100 | [diff] [blame] | 5 | FIFO=/tmp/cmderr |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 6 | TESTCASE=$1 |
Neels Hofmeyr | dadde17 | 2018-06-18 06:18:34 +0200 | [diff] [blame] | 7 | VERDICT="$2" |
| 8 | |
arehbein | cf8c450 | 2022-11-13 17:52:48 +0100 | [diff] [blame] | 9 | SUDOSTR="" |
| 10 | if ! [ "$(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 |
| 14 | fi |
| 15 | |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 16 | kill_rm_pidfile() { |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 17 | # NOTE: This requires you to be root or something like |
| 18 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
arehbein | cf8c450 | 2022-11-13 17:52:48 +0100 | [diff] [blame] | 19 | if ! [ -e "$1" ] && [ -s "$1" ]; then |
| 20 | $SUDOSTR kill "$(cat "$1")" 2>&1 | grep -v "No such process" |
| 21 | rm $1 |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 22 | fi |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 23 | } |
| 24 | |
Neels Hofmeyr | ced8acf | 2019-02-26 05:03:22 +0100 | [diff] [blame] | 25 | date |
| 26 | |
arehbein | bf45a5c | 2022-11-13 18:48:58 +0100 | [diff] [blame] | 27 | # -e only works/is required only in Bash; in dash/POSIX shells it isn't required and will be part of the output |
arehbein | be074e1 | 2022-11-13 22:28:01 +0100 | [diff] [blame^] | 28 | # SHELL environment variable doesn't always give name of current shell (e.g. for dash run inside bash...) |
| 29 | SHELL_NAME="$(cat /proc/$$/cmdline | tr -d '\0')" |
| 30 | if [ "$SHELL_NAME" = "bash" ]; then |
arehbein | bf45a5c | 2022-11-13 18:48:58 +0100 | [diff] [blame] | 31 | ESCAPE_OPT="-e" |
Neels Hofmeyr | dadde17 | 2018-06-18 06:18:34 +0200 | [diff] [blame] | 32 | else |
arehbein | bf45a5c | 2022-11-13 18:48:58 +0100 | [diff] [blame] | 33 | ESCAPE_OPT="" |
| 34 | fi |
| 35 | |
| 36 | if [ x"$VERDICT" = x"pass" ]; then |
| 37 | echo $ESCAPE_OPT "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m" |
| 38 | else |
| 39 | echo $ESCAPE_OPT "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m" |
Neels Hofmeyr | dadde17 | 2018-06-18 06:18:34 +0200 | [diff] [blame] | 40 | fi |
| 41 | echo |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 42 | |
| 43 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 44 | TTCN3_PCAP_PATH=/tmp |
| 45 | fi |
| 46 | |
Vadim Yanitskiy | 23d6665 | 2021-11-28 21:41:07 +0300 | [diff] [blame] | 47 | # Order the SUT to print a talloc report |
| 48 | if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then |
| 49 | if [ -x "$(command -v osmo_interact_vty.py)" ]; then |
Oliver Smith | 9678c22 | 2021-12-17 12:04:11 +0100 | [diff] [blame] | 50 | echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc" |
| 51 | if ! timeout 5 osmo_interact_vty.py \ |
Vadim Yanitskiy | 23d6665 | 2021-11-28 21:41:07 +0300 | [diff] [blame] | 52 | -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \ |
| 53 | -c "en; show talloc-context application full" \ |
Oliver Smith | 9678c22 | 2021-12-17 12:04:11 +0100 | [diff] [blame] | 54 | > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then |
| 55 | echo |
| 56 | echo "ERROR: failed to get talloc report via vty" |
| 57 | echo |
| 58 | fi |
Vadim Yanitskiy | 23d6665 | 2021-11-28 21:41:07 +0300 | [diff] [blame] | 59 | else |
| 60 | echo "Missing osmo_interact_vty.py from osmo-python-tests!" |
| 61 | echo " -> Unable to obtain talloc report from the SUT" |
| 62 | fi |
| 63 | fi |
| 64 | |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 65 | # Wait for up to 2 seconds if we keep receiving traffinc from packet dumper, |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 66 | # otherwise we might lose last packets from test. |
| 67 | i=0 |
| 68 | prev_count=-1 |
| 69 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 70 | while [ $count -gt $prev_count ] && [ $i -lt 2 ] |
| 71 | do |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 72 | echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)" |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 73 | sleep 1 |
| 74 | prev_count=$count |
| 75 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 76 | i=$((i+1)) |
| 77 | done |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 78 | |
Pau Espin Pedrol | ad931f2 | 2019-10-02 13:00:51 +0200 | [diff] [blame] | 79 | kill_rm_pidfile "$PIDFILE_PCAP" |
| 80 | kill_rm_pidfile "$PIDFILE_NETCAT" |
arehbein | bc85a32 | 2022-11-13 18:46:32 +0100 | [diff] [blame] | 81 | rm $FIFO |
Vadim Yanitskiy | f949f46 | 2020-07-12 15:49:37 +0700 | [diff] [blame] | 82 | |
Vadim Yanitskiy | eb662c8 | 2020-07-13 05:50:06 +0700 | [diff] [blame] | 83 | gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" |