[MERGED] osmo-ttcn3-hacks[master]: ttcn3-tcpdump-start.sh: Wait for tcpdump to start recording

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Feb 15 17:22:53 UTC 2018

Harald Welte has submitted this change and it was merged.

Change subject: ttcn3-tcpdump-start.sh: Wait for tcpdump to start recording

ttcn3-tcpdump-start.sh: Wait for tcpdump to start recording

We generate some fake transit and we wait until we catch tcpdump already
saved some packet into the pcap file, this way making sure it is already
recording before starting the test.

The -U flag (--packet-buffered) is added to increase the chances to
sleep less time waiting for stuff being saved into the pcap file.
According to tcpdump manual:
If  the  -w option is specified, make the saved raw packet output ``packet-buffered''; i.e., as each packet is saved, it will
              be written to the output file, rather than being written only when the output buffer fills.

Change-Id: I91cfd84ff5356857a13af1901abfe2204a93f76d
M ttcn3-tcpdump-start.sh
1 file changed, 14 insertions(+), 5 deletions(-)

  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index 10e8ab4..0ce88e9 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -1,6 +1,7 @@
 if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
@@ -15,20 +16,28 @@
 # NOTE: This requires you to be root or something like
 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
 if [ "$(id -u)" = "0" ]; then
-	CMD=/usr/sbin/tcpdump
-	CMD="sudo /usr/sbin/tcpdump"
+	CMD="sudo $TCPDUMP"
-$CMD -s 0 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.log 2>&1 &
+$CMD -U -s 0 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.log 2>&1 &
 echo $PID > $PIDFILE
-# Wait until tcpdump creates the pcap file to give it some time to start listenting.
+# Wait until tcpdump creates the pcap file and starts recording.
+# We generate some traffic until we see tcpdump catches it.
 # Timeout is 10 seconds.
+ping >/dev/null 2>&1 &
-while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] && [ $i -lt 10 ]
+while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] ||
+      [ "$($TCPDUMP -r "$TTCN3_PCAP_PATH/$TESTCASE.pcap" 2>/dev/null | wc -l)" -eq 0 ]
 	echo "Waiting for tcpdump to start... $i"
 	sleep 1
+	if [ $i -eq 10 ]; then
+		break
+	fi
+kill $PID

To view, visit https://gerrit.osmocom.org/6482
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I91cfd84ff5356857a13af1901abfe2204a93f76d
Gerrit-PatchSet: 2
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

More information about the gerrit-log mailing list