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