aboutsummaryrefslogtreecommitdiffstats
path: root/ttcn3-tcpdump-stop.sh
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-02-15 16:07:23 +0100
committerHarald Welte <laforge@gnumonks.org>2018-02-15 17:22:52 +0000
commitdada4c5a55de3984e596468a163cedc4d5ac5189 (patch)
treeb1056d59e84426ee3a228c4fd1b02fc4888e539c /ttcn3-tcpdump-stop.sh
parent8fdd3130fe19d813ca9d5779b91f248d0476efc3 (diff)
ttcn3-tcpdump-stop.sh: Wait to receive last packets before stopping tcpdump
There's a time delay between packets are sent through the system and tcpdump reads, buffers and stores them into the pcap file. We need to give it more time to process everything before killing it, otherwise last (or all) packets from the test are not captured. Change-Id: I240d8f1bdb2ca6ad353e60ef15937dc2bd4cbebd
Diffstat (limited to 'ttcn3-tcpdump-stop.sh')
-rwxr-xr-xttcn3-tcpdump-stop.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index 575c0eff..a085bf70 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -1,6 +1,25 @@
#!/bin/sh
PIDFILE=/tmp/tcpdump.pid
+TESTCASE=$1
+
+if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
+ TTCN3_PCAP_PATH=/tmp
+fi
+
+# Wait for up to 2 seconds if we keep receiving traffinc from tcpdump,
+# otherwise we might lose last packets from test.
+i=0
+prev_count=-1
+count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
+while [ $count -gt $prev_count ] && [ $i -lt 2 ]
+do
+ echo "Waiting for tcpdump to finish... $i (prev_count=$prev_count, count=$count)"
+ sleep 1
+ prev_count=$count
+ count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
+ i=$((i+1))
+done
if [ -e $PIDFILE ]; then
# NOTE: This requires you to be root or something like