blob: e13fbc0f4ed593cf587bf57a33e2b318e7c2c87f [file] [log] [blame]
Harald Welte7c295362020-12-11 15:30:56 +01001#!/bin/sh
2
3PIDFILE_PCAP=/tmp/pcap.pid
4PIDFILE_NETCAT=/tmp/netcat.pid
5TESTCASE=$1
6VERDICT="$2"
7
8kill_rm_pidfile() {
9if [ -e $1 ]; then
10 PSNAME="$(ps -q "$(cat "$1")" -o comm=)"
11 if [ "$PSNAME" != "sudo" ]; then
12 kill "$(cat "$1")"
13 else
14 # NOTE: This requires you to be root or something like
15 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
16 sudo kill "$(cat "$1")"
17 fi
18 rm $1
19fi
20}
21
22date
23
24if [ x"$VERDICT" = x"pass" ]; then
25 echo -e "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m"
26else
27 echo -e "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m"
28fi
29echo
30
31if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
32 TTCN3_PCAP_PATH=/tmp
33fi
34
35# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
36# otherwise we might lose last packets from test.
37i=0
38prev_count=-1
39count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcapng")
40while [ $count -gt $prev_count ] && [ $i -lt 2 ]
41do
42 echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
43 sleep 1
44 prev_count=$count
45 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcapng")
46 i=$((i+1))
47done
48
49kill_rm_pidfile "$PIDFILE_PCAP"
50kill_rm_pidfile "$PIDFILE_NETCAT"
51
52gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcapng"