Skip to content

Commit

Permalink
Guesswork to make the travis tests more reliable
Browse files Browse the repository at this point in the history
One of the steps is failing unpredictably (to me)
  • Loading branch information
gcla committed Sep 7, 2020
1 parent 3bb9128 commit a6ce236
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions scripts/simple-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +21,7 @@ go install ./...

echo Making a test pcap.

cat <<EOF | xxd -r -p > /tmp/test.pcap
cat <<EOF | xxd -r -p > "${PCAP}"
d4c3b2a102000400
0000000000000000
0000040006000000
Expand Down Expand Up @@ -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 '<packet>' | wc -l) == 2 ]]
[[ $($TS -r "${PCAP}" -T psml -n | grep '<packet>' | 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]+)?" | \
Expand All @@ -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.

0 comments on commit a6ce236

Please sign in to comment.