blob: a085bf70ffe959d01e54b922d0db9f271d9dfad0 [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
5
6if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
7 TTCN3_PCAP_PATH=/tmp
8fi
9
10# Wait for up to 2 seconds if we keep receiving traffinc from tcpdump,
11# otherwise we might lose last packets from test.
12i=0
13prev_count=-1
14count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
15while [ $count -gt $prev_count ] && [ $i -lt 2 ]
16do
17 echo "Waiting for tcpdump to finish... $i (prev_count=$prev_count, count=$count)"
18 sleep 1
19 prev_count=$count
20 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
21 i=$((i+1))
22done
Harald Weltee0571462018-02-14 15:42:14 +010023
24if [ -e $PIDFILE ]; then
25 # NOTE: This requires you to be root or something like
26 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
27 if [ "$(id -u)" = "0" ]; then
28 kill "$(cat "$PIDFILE")"
29 else
30 sudo kill "$(cat "$PIDFILE")"
31 fi
32 rm $PIDFILE
33fi