diff options
Diffstat (limited to 'ttcn3-tcpdump-stop.sh')
-rwxr-xr-x | ttcn3-tcpdump-stop.sh | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh index b2a3a3e3..def10d8a 100755 --- a/ttcn3-tcpdump-stop.sh +++ b/ttcn3-tcpdump-stop.sh @@ -2,36 +2,58 @@ PIDFILE_PCAP=/tmp/pcap.pid PIDFILE_NETCAT=/tmp/netcat.pid +FIFO=/tmp/cmderr TESTCASE=$1 VERDICT="$2" +SUDOSTR="" +if ! [ "$(id -u)" = "0" ]; then + SUDOSTR="sudo -n" + # Otherwise, if sudo /usr/bin/kill, sudo /usr/bin/tcpdump cannot be run without a password prompt, + # and this script will hang indefinitely +fi + kill_rm_pidfile() { -if [ -e $1 ]; then - PSNAME="$(ps -q "$(cat "$1")" -o comm=)" - if [ "$PSNAME" != "sudo" ]; then - kill "$(cat "$1")" - else # NOTE: This requires you to be root or something like # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file - sudo kill "$(cat "$1")" + if [ -e "$1" ]; then + if [ -s "$1" ]; then + $SUDOSTR kill "$(cat "$1")" 2>&1 | grep -v "No such process" + fi + rm $1 fi - rm $1 -fi } date if [ x"$VERDICT" = x"pass" ]; then - echo -e "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m" + printf "\033[1;32m====== $TESTCASE $VERDICT ======\033[0m\n\n" else - echo -e "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m" + printf "\033[1;31m------ $TESTCASE $VERDICT ------\033[0m\n\n" fi -echo if [ "z$TTCN3_PCAP_PATH" = "z" ]; then TTCN3_PCAP_PATH=/tmp fi +# Order the SUT to print a talloc report +if [ "z$OSMO_SUT_HOST" != "z" ] && [ "z$OSMO_SUT_PORT" != "z" ]; then + if [ -x "$(command -v osmo_interact_vty.py)" ]; then + echo "Saving talloc report from $OSMO_SUT_HOST:$OSMO_SUT_PORT to $TESTCASE.talloc" + if ! timeout 5 osmo_interact_vty.py \ + -H $OSMO_SUT_HOST -p $OSMO_SUT_PORT \ + -c "en; show talloc-context application full" \ + > "$TTCN3_PCAP_PATH/$TESTCASE.talloc"; then + echo + echo "ERROR: failed to get talloc report via vty" + echo + fi + else + echo "Missing osmo_interact_vty.py from osmo-python-tests!" + echo " -> Unable to obtain talloc report from the SUT" + fi +fi + # Wait for up to 2 seconds if we keep receiving traffinc from packet dumper, # otherwise we might lose last packets from test. i=0 @@ -48,5 +70,18 @@ done kill_rm_pidfile "$PIDFILE_PCAP" kill_rm_pidfile "$PIDFILE_NETCAT" +rm $FIFO + +# Add a numeral suffix to subsequent runs of the same test: +PCAP_FILENAME=$TTCN3_PCAP_PATH/$TESTCASE.pcap +if [ -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap.gz" ]; then + i=1 + while [ -f "$TTCN3_PCAP_PATH/$TESTCASE.$i.pcap.gz" ]; + do i=$((i+1)) + done + mv "$PCAP_FILENAME" "$TTCN3_PCAP_PATH/$TESTCASE.$i.pcap" + PCAP_FILENAME="$TTCN3_PCAP_PATH/$TESTCASE.$i.pcap" +fi +gzip -f "$PCAP_FILENAME" -gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" +rm -f "$TTCN3_PCAP_PATH/.current_test" |