From a6ce236dfff377cfbfdbb5bcd8fe452c2928180a Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Mon, 7 Sep 2020 18:20:51 -0400 Subject: [PATCH] Guesswork to make the travis tests more reliable One of the steps is failing unpredictably (to me) --- scripts/simple-tests.sh | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/scripts/simple-tests.sh b/scripts/simple-tests.sh index 21eaa88..17d79dd 100755 --- a/scripts/simple-tests.sh +++ b/scripts/simple-tests.sh @@ -2,9 +2,13 @@ set -e +# Safe enough... +PCAP=$(mktemp -u /tmp/testXXXX.pcap) +FIFO=$(mktemp -u /tmp/fifoXXXX) + cleanup() { - rm /tmp/test.pcap - rm /tmp/fifo + rm "${PCAP}" + rm "${FIFO}" } trap cleanup EXIT @@ -17,7 +21,7 @@ go install ./... echo Making a test pcap. -cat < /tmp/test.pcap +cat < "${PCAP}" d4c3b2a102000400 0000000000000000 0000040006000000 @@ -53,28 +57,28 @@ echo Running termshark cli tests. export TS="$GOPATH/bin/termshark" # stdout is not a tty, so falls back to tshark -$TS -r /tmp/test.pcap | grep '192.168.44.213 TFTP 77' +$TS -r "${PCAP}" | grep '192.168.44.213 TFTP 77' # prove that options provided are passed through to tshark -[[ $($TS -r /tmp/test.pcap -T psml -n | grep '' | wc -l) == 2 ]] +[[ $($TS -r "${PCAP}" -T psml -n | grep '' | wc -l) == 2 ]] # Must choose either a file or an interface -! $TS -r /tmp/test.pcap -i eth0 +! $TS -r "${PCAP}" -i eth0 # only display the second line via tshark -[[ $($TS -r /tmp/test.pcap 'frame.number == 2' | wc -l) == 1 ]] +[[ $($TS -r "${PCAP}" 'frame.number == 2' | wc -l) == 1 ]] # test fifos -mkfifo /tmp/fifo -cat /tmp/test.pcap > /tmp/fifo & -$TS -r /tmp/fifo | grep '192.168.44.213 TFTP 77' +mkfifo "${FIFO}" +cat "${PCAP}" > "${FIFO}" & +$TS -r "${FIFO}" | grep '192.168.44.213 TFTP 77' wait -rm /tmp/fifo +rm "${FIFO}" # Check pass-thru option works. Make termshark run in a tty to ensure it's taking effect -[[ $(script -q -e -c "$TS -r /tmp/test.pcap --pass-thru" | wc -l) == 2 ]] +[[ $(script -q -e -c "$TS -r "${PCAP}" --pass-thru" | wc -l) == 2 ]] -[[ $(script -q -e -c "$TS -r /tmp/test.pcap --pass-thru=true" | wc -l) == 2 ]] +[[ $(script -q -e -c "$TS -r "${PCAP}" --pass-thru=true" | wc -l) == 2 ]] # run in script so termshark thinks it's in a tty cat version.go | grep -o -E "v[0-9]+\.[0-9]+(\.[0-9]+)?" | \ @@ -89,40 +93,40 @@ in_tty() { echo UI test 1 # Load a pcap, quit -{ sleep 5s ; echo q ; echo ; } | in_tty $TS -r /tmp/test.pcap +{ sleep 5s ; echo q ; echo ; } | in_tty $TS -r "${PCAP}" echo UI test 2 # Run with stdout not a tty, but disable the pass-thru to tshark -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r /tmp/test.pcap --pass-thru=false | cat" +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r "${PCAP}" --pass-thru=false | cat" echo UI test 3 # Load a pcap, very rudimentary scrape for an IP, quit -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r /tmp/test.pcap" | grep -a 192.168.44.123 > /dev/null +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r "${PCAP}"" | grep -a 192.168.44.123 > /dev/null # Ensure -r flag isn't needed -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS /tmp/test.pcap" | grep -a 192.168.44.123 > /dev/null +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS "${PCAP}"" | grep -a 192.168.44.123 > /dev/null echo UI test 4 # Load a pcap from stdin -{ sleep 5s ; echo q ; echo ; } | in_tty "cat /tmp/test.pcap | TERM=xterm $TS -i -" -{ sleep 5s ; echo q ; echo ; } | in_tty "cat /tmp/test.pcap | TERM=xterm $TS -r -" -{ sleep 5s ; echo q ; echo ; } | in_tty "cat /tmp/test.pcap | TERM=xterm $TS" +{ sleep 5s ; echo q ; echo ; } | in_tty "cat "${PCAP}" | TERM=xterm $TS -i -" +{ sleep 5s ; echo q ; echo ; } | in_tty "cat "${PCAP}" | TERM=xterm $TS -r -" +{ sleep 5s ; echo q ; echo ; } | in_tty "cat "${PCAP}" | TERM=xterm $TS" echo UI test 5 # Display filter at end of command line { sleep 5s ; echo q ; echo ; } | in_tty "$TS -r scripts/pcaps/telnet-cooked.pcap \'frame.number == 2\'" | grep -a "Frame 2: 74 bytes" > /dev/null echo UI test 6 -mkfifo /tmp/fifo -cat /tmp/test.pcap > /tmp/fifo & -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r /tmp/fifo" +mkfifo "${FIFO}" +cat "${PCAP}" > "${FIFO}" & +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -r "${FIFO}"" wait -cat /tmp/test.pcap > /tmp/fifo & -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -i /tmp/fifo" +cat "${PCAP}" > "${FIFO}" & +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS -i "${FIFO}"" wait -cat /tmp/test.pcap > /tmp/fifo & -{ sleep 5s ; echo q ; echo ; } | in_tty "$TS /tmp/fifo" -#{ sleep 5s ; echo q ; echo ; } | in_tty "$TS /tmp/fifo \'frame.number == 2\'" | grep -a "Frame 2: 74 bytes" > /dev/null +cat "${PCAP}" > "${FIFO}" & +{ sleep 5s ; echo q ; echo ; } | in_tty "$TS "${FIFO}"" +#{ sleep 5s ; echo q ; echo ; } | in_tty "$TS "${FIFO}" \'frame.number == 2\'" | grep -a "Frame 2: 74 bytes" > /dev/null wait echo Tests were successful.