Don't use PCRE if we have GRegex.
[obnox/wireshark/wip.git] / test / suite-capture.sh
old mode 100644 (file)
new mode 100755 (executable)
index 453b90f..4033cb8
@@ -29,32 +29,67 @@ EXIT_OK=0
 EXIT_COMMAND_LINE=1
 EXIT_ERROR=2
 
+capture_test_output_print() {
+       wait
+       for f in "$@"; do
+               if [[ -f "$f" ]]; then
+               printf " --> $f\n"
+               cat "$f"
+                printf "\n"
+               fi
+       done
+}
+
 traffic_gen_ping() {
        # Generate some traffic for quiet networks.
        # This will have to be adjusted for non-Windows systems.
-       ping -n 20 www.wireshark.org > ./pingout.txt 2>&1 &
+       
+       # the following will run in the background and return immediately
+       {
+       date
+       for (( x=28; x<=58; x++ )) # in effect: number the packets
+       do
+               # How does ping _not_ have a standard set of arguments?
+               case $WS_SYSTEM in
+                       Windows)
+                               ping -n 1 -l $x www.wireshark.org       ;;
+                       SunOS)
+                               /usr/sbin/ping www.wireshark.org $x 1           ;;
+                       *) # *BSD, Linux
+                               ping -c 1 -s $x www.wireshark.org       ;;
+               esac
+               sleep 1
+       done
+       date
+       } > ./testout_ping.txt 2>&1 &
+}
+
+ping_cleanup() {
+       wait
+       rm -f ./testout_ping.txt
 }
 
 # capture exactly 10 packets
 capture_step_10packets() {
-       if [ "$WS_SYSTEM" != "Windows" ] ; then
+       if [ $SKIP_CAPTURE -ne 0 ] ; then
                test_step_skipped
                return
        fi
 
        traffic_gen_ping
+
+       date > ./testout.txt
        $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
                -w ./testout.pcap \
                -c 10  \
                -a duration:$TRAFFIC_CAPTURE_DURATION \
-               icmp \
-               > ./testout.txt 2>&1
+               -f icmp \
+               >> ./testout.txt 2>&1
        RETURNVALUE=$?
+       date >> ./testout.txt
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
-               wait  # for ping to complete
                echo
-               cat ./testout.txt
-               cat ./pingout.txt
+               capture_test_output_print ./testout.txt
                # part of the Prerequisite checks
                # wrong interface ? output the possible interfaces
                $TSHARK -D
@@ -64,20 +99,20 @@ capture_step_10packets() {
 
        # we should have an output file now
        if [ ! -f "./testout.pcap" ]; then
+       capture_test_output ./testout.txt
                test_step_failed "No output file!"
                return
        fi
 
        # ok, we got a capture file, does it contain exactly 10 packets?
-       $CAPINFOS ./testout.pcap > ./testout.txt
-       grep -i 'Number of packets: 10' ./testout.txt > /dev/null
+       $CAPINFOS ./testout.pcap > ./testout2.txt
+       grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
-               wait  # for ping to complete
                echo
-               cat ./testout.txt
-               cat ./pingout.txt
+                $TSHARK -ta -r ./testout.pcap >> ./testout2.txt
+               capture_test_output_print ./testout_ping.txt ./testout.txt ./testout2.txt
                # part of the Prerequisite checks
                # probably wrong interface, output the possible interfaces
                $TSHARK -D
@@ -87,24 +122,25 @@ capture_step_10packets() {
 
 # capture exactly 10 packets using "-w -" (piping to stdout)
 capture_step_10packets_stdout() {
-        if [ "$WS_SYSTEM" != "Windows" ] ; then
+        if [ $SKIP_CAPTURE -ne 0 ] ; then
                 test_step_skipped
                 return
         fi
 
        traffic_gen_ping
+
+       date > ./testout.txt
        $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
                -c 10 \
                -a duration:$TRAFFIC_CAPTURE_DURATION \
                -w - \
-               icmp \
-               > ./testout.pcap 2>./testout.txt
+               -f icmp \
+               > ./testout.pcap 2>>./testout.txt
        RETURNVALUE=$?
+       date >> ./testout.txt
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
-               wait  # for ping to complete
                echo
                cat ./testout.txt
-               cat ./pingout.txt
                $TSHARK -D
                test_step_failed "exit status of $DUT: $RETURNVALUE"
                return
@@ -118,15 +154,13 @@ capture_step_10packets_stdout() {
 
        # ok, we got a capture file, does it contain exactly 10 packets?
        $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
-       grep -i 'Number of packets: 10' ./testout2.txt > /dev/null
+       grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
                echo
-               wait  # for ping to complete
                cat ./testout.txt
                cat ./testout2.txt
-               cat ./pingout.txt
                $TSHARK -D
                test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
        fi
@@ -155,7 +189,7 @@ capture_step_fifo() {
 
        # ok, we got a capture file, does it contain exactly 8 packets?
        $CAPINFOS ./testout.pcap > ./testout.txt
-       grep -i 'Number of packets: 8' ./testout.txt > /dev/null
+       grep -Ei 'Number of packets:[[:blank:]]+8' ./testout.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
@@ -167,25 +201,26 @@ capture_step_fifo() {
 
 # capture exactly 2 times 10 packets (multiple files)
 capture_step_2multi_10packets() {
-        if [ "$WS_SYSTEM" != "Windows" ] ; then
+        if [ $SKIP_CAPTURE -ne 0 ] ; then
                 test_step_skipped
                 return
         fi
 
        traffic_gen_ping
+
+       date > ./testout.txt
        $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
                -w ./testout.pcap \
                -c 10 \
                -a duration:$TRAFFIC_CAPTURE_DURATION \
-               icmp
-               > ./testout.txt 2>&1
+               -f icmp \
+               >> ./testout.txt 2>&1
 
        RETURNVALUE=$?
+       date >> ./testout.txt
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
-               wait  # for ping to complete
                echo
                cat ./testout.txt
-               cat ./pingout.txt
                # part of the Prerequisite checks
                # probably wrong interface, output the possible interfaces
                $TSHARK -D
@@ -201,7 +236,7 @@ capture_step_2multi_10packets() {
 
        # ok, we got a capture file, does it contain exactly 10 packets?
        $CAPINFOS ./testout.pcap > ./testout.txt
-       grep -i 'Number of packets: 10' ./testout.txt > /dev/null
+       grep -Ei 'Number of packets:[[:blank:]]+10' ./testout.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
@@ -213,26 +248,27 @@ capture_step_2multi_10packets() {
 
 # capture with a very unlikely read filter, packets must be zero afterwards
 capture_step_read_filter() {
-        if [ "$WS_SYSTEM" != "Windows" ] ; then
+        if [ $SKIP_CAPTURE -ne 0 ] ; then
                 test_step_skipped
                 return
         fi
 
        traffic_gen_ping
+
        # valid, but very unlikely filter
+       date > ./testout.txt
        $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
                -w ./testout.pcap \
                -a duration:$TRAFFIC_CAPTURE_DURATION \
                -R 'dcerpc.cn_call_id==123456' \
                -c 10 \
-               icmp
-               > ./testout.txt 2>&1
+               -f icmp \
+               >> ./testout.txt 2>&1
        RETURNVALUE=$?
+       date >> ./testout.txt
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
-               wait  # for ping to complete
                echo
                cat ./testout.txt
-               cat ./pingout.txt
                # part of the Prerequisite checks
                # wrong interface ? output the possible interfaces
                $TSHARK -D
@@ -248,7 +284,7 @@ capture_step_read_filter() {
 
        # ok, we got a capture file, does it contain exactly 0 packets?
        $CAPINFOS ./testout.pcap > ./testout.txt
-       grep -i 'Number of packets: 0' ./testout.txt > /dev/null
+       grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
@@ -261,7 +297,7 @@ capture_step_read_filter() {
 
 # capture with a snapshot length
 capture_step_snapshot() {
-        if [ "$WS_SYSTEM" != "Windows" ] ; then
+        if [ $SKIP_CAPTURE -ne 0 ] ; then
                 test_step_skipped
                 return
         fi
@@ -269,19 +305,19 @@ capture_step_snapshot() {
        traffic_gen_ping
 
        # capture with a snapshot length of 68 bytes for $TRAFFIC_CAPTURE_DURATION seconds
-       # this should result in no packets
+       # this should result in no packets greater than 68 bytes
+       date > ./testout.txt
        $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
                -w ./testout.pcap \
                -s 68 \
-               -a duration:$TRAFFIC_CAPTURE_DURATION
-               icmp \
-               > ./testout.txt 2>&1
+               -a duration:$TRAFFIC_CAPTURE_DURATION \
+               -f icmp \
+               >> ./testout.txt 2>&1
        RETURNVALUE=$?
+       date >> ./testout.txt
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
-               wait  # for ping to complete
                echo
                cat ./testout.txt
-               cat ./pingout.txt
                # part of the Prerequisite checks
                # wrong interface ? output the possible interfaces
                $TSHARK -D
@@ -300,7 +336,7 @@ capture_step_snapshot() {
 
        # ok, we got a capture file, does it contain exactly 0 packets?
        $CAPINFOS ./testout2.pcap > ./testout.txt
-       grep -i 'Number of packets: 0' ./testout.txt > /dev/null
+       grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
        if [ $? -eq 0 ]; then
                test_step_ok
        else
@@ -329,7 +365,8 @@ tshark_capture_suite() {
        if [ $TEST_FIFO ]; then
                test_step_add "Capture via fifo" capture_step_fifo
        fi
-       test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
+    # tshark now using dumpcap for capturing, read filters won't work by definition
+       #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
        test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
 }
 
@@ -347,18 +384,18 @@ dumpcap_capture_suite() {
 }
 
 capture_cleanup_step() {
+       ping_cleanup
        rm -f ./testout.txt
        rm -f ./testout2.txt
        rm -f ./testout.pcap
        rm -f ./testout2.pcap
-       rm -f ./pingout.txt
 }
 
 capture_suite() {
        test_step_set_pre capture_cleanup_step
        test_step_set_post capture_cleanup_step
        test_remark_add "Capture - need some traffic on interface: \"$TRAFFIC_CAPTURE_IFACE\""
+       test_suite_add "Dumpcap capture" dumpcap_capture_suite
        test_suite_add "TShark capture" tshark_capture_suite
        test_suite_add "Wireshark capture" wireshark_capture_suite
-       test_suite_add "Dumpcap capture" dumpcap_capture_suite
 }