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