Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | PIDFILE=/tmp/tcpdump.pid |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 4 | TESTCASE=$1 |
Neels Hofmeyr | dadde17 | 2018-06-18 06:18:34 +0200 | [diff] [blame] | 5 | VERDICT="$2" |
| 6 | |
| 7 | if [ x"$VERDICT" = x"pass" ]; then |
| 8 | echo "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m" |
| 9 | else |
| 10 | echo "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m" |
| 11 | fi |
| 12 | echo |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 13 | |
| 14 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 15 | TTCN3_PCAP_PATH=/tmp |
| 16 | fi |
| 17 | |
| 18 | # Wait for up to 2 seconds if we keep receiving traffinc from tcpdump, |
| 19 | # otherwise we might lose last packets from test. |
| 20 | i=0 |
| 21 | prev_count=-1 |
| 22 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 23 | while [ $count -gt $prev_count ] && [ $i -lt 2 ] |
| 24 | do |
| 25 | echo "Waiting for tcpdump to finish... $i (prev_count=$prev_count, count=$count)" |
| 26 | sleep 1 |
| 27 | prev_count=$count |
| 28 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 29 | i=$((i+1)) |
| 30 | done |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 31 | |
| 32 | if [ -e $PIDFILE ]; then |
| 33 | # NOTE: This requires you to be root or something like |
| 34 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
| 35 | if [ "$(id -u)" = "0" ]; then |
| 36 | kill "$(cat "$PIDFILE")" |
| 37 | else |
| 38 | sudo kill "$(cat "$PIDFILE")" |
| 39 | fi |
| 40 | rm $PIDFILE |
| 41 | fi |