802.1ah: call subdissectors even when we have no tree.
[metze/wireshark/wip.git] / test / test.sh
index 879d720088ad3db9783a24392067cf95ed692d99..73a2007b0d751a9f37a7674842c3d7c212d53739 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
-(shopt -s igncr) 2>/dev/null && shopt -s igncr; # comment is needed
-#                                               # hack for cygwin bash
-#                                               #  no-op for other
+(set -o igncr) 2>/dev/null && set -o igncr; # comment is needed
+#                                           # hack for cygwin bash
+#                                           #  no-op for other
 #
 # Test various command line testable aspects of the Wireshark tools
 #
@@ -29,13 +29,18 @@ USE_COLOR=1
 RUN_SUITE=""
 PRINT_USAGE=0
 
+# Ensure cygwin bin dir is on the path if running under it
+if [[ $OSTYPE == "cygwin" ]]; then
+       PATH="$PATH:/usr/bin"
+fi
+
 while getopts "chs:" OPTION ; do
-        case $OPTION in
-          c) USE_COLOR=0 ;;
-          h) PRINT_USAGE=1 ;;
-          s) RUN_SUITE="$OPTARG" ;;
-          *) echo "Unknown option: " $OPTION $OPTARG
-        esac
+       case $OPTION in
+               c) USE_COLOR=0 ;;
+               h) PRINT_USAGE=1 ;;
+               s) RUN_SUITE="$OPTARG" ;;
+               *) echo "Unknown option: " $OPTION $OPTARG
+       esac
 done
 
 shift $(( $OPTIND - 1 ))
@@ -61,9 +66,15 @@ FIN
         exit 0
 fi
 
-source test-backend.sh
-
-source config.sh
+MYDIR=$(dirname $0)
+if [ -d run ]; then
+       if [ -e run/tshark -o -e run/dumpcap -o -e run/rawshark ]; then
+               WS_BIN_PATH=${WS_BIN_PATH:-$(cd run && pwd)}
+               WS_QT_BIN_PATH=${WS_QT_BIN_PATH:-$WS_BIN_PATH}
+       fi
+fi
+source $MYDIR/test-backend.sh
+source $MYDIR/config.sh
 
 # needed by some tests
 TEST_OUTDIR=$(mktemp -d)
@@ -80,10 +91,11 @@ HOME_PATH="$TEST_OUTDIR/home"
 CONF_PATH="$HOME_PATH/.wireshark"
 
 if [ "$WS_SYSTEM" == "Windows" ] ; then
-    HOME_ENV="APPDATA"
-    HOME_PATH="`cygpath -w $HOME_PATH`"
-    CONF_PATH="$HOME_PATH/Wireshark"
-    CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
+       HOME_ENV="APPDATA"
+       HOME_PATH="`cygpath -w $HOME_PATH`"
+       CONF_PATH="$HOME_PATH/Wireshark"
+       CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
+       TESTS_DIR="`cygpath -w $TESTS_DIR`"
 fi
 
 mkdir -p $CONF_PATH
@@ -96,6 +108,8 @@ source $TESTS_DIR/suite-fileformats.sh
 source $TESTS_DIR/suite-decryption.sh
 source $TESTS_DIR/suite-nameres.sh
 source $TESTS_DIR/suite-wslua.sh
+source $TESTS_DIR/suite-mergecap.sh
+source $TESTS_DIR/suite-text2pcap.sh
 
 test_cleanup() {
        if [ $TEST_OUTDIR_CLEAN = 1 ]; then
@@ -114,7 +128,7 @@ trap test_cleanup EXIT
 test_step_prerequisites() {
 
        NOTFOUND=0
-       for i in "$WIRESHARK" "$WIRESHARK_GTK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
+       for i in "$WIRESHARK" "$WIRESHARK_GTK" "$TSHARK" "$CAPINFOS" "$MERGECAP" "$DUMPCAP" ; do
                if [ ! -x $i ]; then
                        echo "Couldn't find $i"
                        NOTFOUND=1
@@ -130,8 +144,8 @@ test_step_prerequisites() {
 
 # Dump version information
 test_step_tshark_version() {
-        test_remark_add "Printing TShark version"
-       $TSHARK -v
+       test_remark_add "Printing TShark version"
+       $TESTS_DIR/run_and_catch_crashes $TSHARK -v
        RETURNVALUE=$?
        if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
                test_step_failed "Failed to print version information"
@@ -152,10 +166,12 @@ test_suite() {
        test_suite_add "File I/O" io_suite
        test_suite_add "Capture" capture_suite
        test_suite_add "Unit tests" unittests_suite
-       test_suite_add "File formats" fileformats_suite
        test_suite_add "Decryption" decryption_suite
        test_suite_add "Name Resolution" name_resolution_suite
        test_suite_add "Lua API" wslua_suite
+       test_suite_add "Mergecap" mergecap_suite
+       test_suite_add "File formats" fileformats_suite
+       test_suite_add "Text2pcap" text2pcap_suite
 }
 
 
@@ -173,38 +189,41 @@ test_set_output VERBOSE
 #test_suite_show "All" test_suite
 
 if [ -n "$RUN_SUITE" ] ; then
-        case $RUN_SUITE in
-          "all")
-            test_suite_run "All" test_suite
-            exit $? ;;
-         "capture")
-            test_suite_run "Capture" capture_suite
-            exit $? ;;
-         "clopts")
-           test_suite_run "Command line options" clopt_suite
-            exit $? ;;
-         "decryption")
-           test_suite_run "Decryption" decryption_suite
-            exit $? ;;
-         "fileformats")
-            test_suite_run "File formats" fileformats_suite
-            exit $? ;;
-         "io")
-           test_suite_run "File I/O" io_suite
-            exit $? ;;
-         "nameres")
-           test_suite_run "Name Resolution" name_resolution_suite
-            exit $? ;;
-         "prerequisites")
-            test_suite_run "Prerequisites" prerequisites_suite
-            exit $? ;;
-         "unittests")
-            test_suite_run "Unit tests" unittests_suite
-            exit $? ;;
-         "wslua")
-            test_suite_run "Lua API" wslua_suite
-            exit $? ;;
-        esac
+       case $RUN_SUITE in
+               "all")
+                       test_suite_run "All" test_suite
+                       exit $? ;;
+               "capture")
+                       test_suite_run "Capture" capture_suite
+                       exit $? ;;
+               "clopts")
+                       test_suite_run "Command line options" clopt_suite
+                       exit $? ;;
+               "decryption")
+                       test_suite_run "Decryption" decryption_suite
+                       exit $? ;;
+               "fileformats")
+                       test_suite_run "File formats" fileformats_suite
+                       exit $? ;;
+               "io")
+                       test_suite_run "File I/O" io_suite
+                       exit $? ;;
+               "nameres")
+                       test_suite_run "Name Resolution" name_resolution_suite
+                       exit $? ;;
+               "prerequisites")
+                       test_suite_run "Prerequisites" prerequisites_suite
+                       exit $? ;;
+               "unittests")
+                       test_suite_run "Unit tests" unittests_suite
+                       exit $? ;;
+               "wslua")
+                       test_suite_run "Lua API" wslua_suite
+                       exit $? ;;
+               "text2pcap")
+                       test_suite_run "Text2pcap" text2pcap_suite
+                       exit $? ;;
+       esac
 fi
 
 MENU_LEVEL=0
@@ -220,14 +239,25 @@ do
 
        #echo $current_title $current_function
        test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
-       echo "1-$TEST_STEPS  : Select item"
-       echo "Enter: Test All"
+       if [ $MENU_LEVEL -gt 0 ]; then
+               echo "T or Enter:  Run suite"
+       else
+       echo "1-$TEST_STEPS : Select suite"
+       fi
+
+       # DBG
+       #echo "Menu level: $MENU_LEVEL"
+       #echo "Menu Title: ${menu_title[MENU_LEVEL]}"
+       #echo "Menu Function: ${menu_function[MENU_LEVEL]}"
+       #echo "Test title size: ${#test_title[@]}"
+       # END DBG
+
        if [[ ! $MENU_LEVEL -eq 0 ]]; then
                echo "U    : Up"
        fi
        echo "Q    : Quit"
        echo ""
-       read -n1 key
+       read key
        newl=$'\x0d'
        echo "$newl----------------------------------------------------------------------"
 
@@ -252,51 +282,26 @@ done
                        #echo "----------------------------------------------------------------------"
                fi
        ;;
-               "1")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[1]}
-               menu_function[MENU_LEVEL]=${test_function[1]}
-       ;;
-               "2")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[2]}
-               menu_function[MENU_LEVEL]=${test_function[2]}
-       ;;
-               "3")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[3]}
-               menu_function[MENU_LEVEL]=${test_function[3]}
-       ;;
-               "4")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[4]}
-               menu_function[MENU_LEVEL]=${test_function[4]}
-       ;;
-               "5")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[5]}
-               menu_function[MENU_LEVEL]=${test_function[5]}
-       ;;
-               "6")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[6]}
-               menu_function[MENU_LEVEL]=${test_function[6]}
-       ;;
-               "7")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[7]}
-               menu_function[MENU_LEVEL]=${test_function[7]}
-       ;;
-               "8")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[8]}
-               menu_function[MENU_LEVEL]=${test_function[8]}
-       ;;
-               "9")
-               let "MENU_LEVEL += 1"
-               menu_title[MENU_LEVEL]=${test_title[9]}
-               menu_function[MENU_LEVEL]=${test_function[9]}
+               ## Now we're only interested in digits when the menu level is at the top (0)
+               [0-9]*)
+               if [ $MENU_LEVEL -eq 0 ]; then
+                       if [ $key -le ${#test_title[@]} ]; then
+                               let "MENU_LEVEL += 1"
+                               menu_title[MENU_LEVEL]=${test_title[$key]}
+                               menu_function[MENU_LEVEL]=${test_function[$key]}
+                       fi
+               fi
        ;;
-
        esac
 done
+
+# Editor modelines
+#
+# Local Variables:
+# sh-basic-offset: 8
+# tab-width: 8
+# indent-tabs-mode: t
+# End:
+#
+# ex: set shiftwidth=8 tabstop=8 noexpandtab:
+# :indentSize=8:tabSize=8:noTabs=false: