Harald Welte | 7c29536 | 2020-12-11 15:30:56 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | PIDFILE_PCAP=/tmp/pcap.pid |
| 4 | PIDFILE_NETCAT=/tmp/netcat.pid |
| 5 | TESTCASE=$1 |
| 6 | VERDICT="$2" |
| 7 | |
| 8 | kill_rm_pidfile() { |
| 9 | if [ -e $1 ]; then |
| 10 | PSNAME="$(ps -q "$(cat "$1")" -o comm=)" |
| 11 | if [ "$PSNAME" != "sudo" ]; then |
| 12 | kill "$(cat "$1")" |
| 13 | else |
| 14 | # NOTE: This requires you to be root or something like |
| 15 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
| 16 | sudo kill "$(cat "$1")" |
| 17 | fi |
| 18 | rm $1 |
| 19 | fi |
| 20 | } |
| 21 | |
| 22 | date |
| 23 | |
| 24 | if [ x"$VERDICT" = x"pass" ]; then |
| 25 | echo -e "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m" |
| 26 | else |
| 27 | echo -e "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m" |
| 28 | fi |
| 29 | echo |
| 30 | |
| 31 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 32 | TTCN3_PCAP_PATH=/tmp |
| 33 | fi |
| 34 | |
| 35 | # Wait for up to 2 seconds if we keep receiving traffinc from packet dumper, |
| 36 | # otherwise we might lose last packets from test. |
| 37 | i=0 |
| 38 | prev_count=-1 |
| 39 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcapng") |
| 40 | while [ $count -gt $prev_count ] && [ $i -lt 2 ] |
| 41 | do |
| 42 | echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)" |
| 43 | sleep 1 |
| 44 | prev_count=$count |
| 45 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcapng") |
| 46 | i=$((i+1)) |
| 47 | done |
| 48 | |
| 49 | kill_rm_pidfile "$PIDFILE_PCAP" |
| 50 | kill_rm_pidfile "$PIDFILE_NETCAT" |
| 51 | |
| 52 | gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcapng" |