blob: 9404841121cecc95d2d61f18c928665bb2965a31 [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
7if [ x"$VERDICT" = x"pass" ]; then
8 echo "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
9else
10 echo "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
11fi
12echo
Pau Espin Pedroldada4c52018-02-15 16:07:23 +010013
14if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
15 TTCN3_PCAP_PATH=/tmp
16fi
17
18# Wait for up to 2 seconds if we keep receiving traffinc from tcpdump,
19# otherwise we might lose last packets from test.
20i=0
21prev_count=-1
22count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
23while [ $count -gt $prev_count ] && [ $i -lt 2 ]
24do
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))
30done
Harald Weltee0571462018-02-14 15:42:14 +010031
32if [ -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
41fi