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