2 (set -o igncr) 2>/dev/null && set -o igncr; # comment is needed
3 # # hack for cygwin bash
6 # Test various command line testable aspects of the Wireshark tools
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 2005 Ulf Lamping
12 # SPDX-License-Identifier: GPL-2.0-or-later
15 # an existing capture file
20 # Ensure cygwin bin dir is on the path if running under it
21 if [[ $OSTYPE == "cygwin" ]]; then
25 while getopts "chs:" OPTION ; do
29 s) RUN_SUITE="$OPTARG" ;;
30 *) echo "Unknown option: " $OPTION $OPTARG
34 shift $(( $OPTIND - 1 ))
36 if [ $PRINT_USAGE -ne 0 ] ; then
39 Usage: $THIS [-c] [-h] [-s <suite>]
40 -c: Disable color output
41 -h: Print this message and exit
42 -s: Run a suite. Must be one of:
60 if [ -e run/tshark -o -e run/dumpcap -o -e run/rawshark ]; then
61 WS_BIN_PATH=${WS_BIN_PATH:-$(cd run && pwd)}
64 source $MYDIR/test-backend.sh
65 source $MYDIR/config.sh
67 # needed by some tests
68 TEST_OUTDIR="$(mktemp -d 2>/dev/null || mktemp -d ${TMPDIR:-/tmp}/wstest.XXXXXXXXXX)"
69 if [ $? -ne 0 ] || [ ! -d "$TEST_OUTDIR" ] || ! cd "$TEST_OUTDIR"; then
70 # Error out if TEST_OUTDIR cannot be created
71 echo "Failed to create directory '$TEST_OUTDIR'"
74 TEST_OUTDIR_CLEAN=${TEST_OUTDIR_CLEAN:-1}
78 HOME_PATH="$TEST_OUTDIR/home"
79 CONF_PATH="$HOME_PATH/.wireshark"
81 if [ "$WS_SYSTEM" == "Windows" ] ; then
83 HOME_PATH="`cygpath -w $HOME_PATH`"
84 CONF_PATH="$HOME_PATH/Wireshark"
85 CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
86 TESTS_DIR="`cygpath -w $TESTS_DIR`"
91 source $TESTS_DIR/suite-clopts.sh
92 source $TESTS_DIR/suite-io.sh
93 source $TESTS_DIR/suite-capture.sh
94 source $TESTS_DIR/suite-unittests.sh
95 source $TESTS_DIR/suite-fileformats.sh
96 source $TESTS_DIR/suite-decryption.sh
97 source $TESTS_DIR/suite-nameres.sh
98 source $TESTS_DIR/suite-wslua.sh
99 source $TESTS_DIR/suite-mergecap.sh
100 source $TESTS_DIR/suite-text2pcap.sh
101 source $TESTS_DIR/suite-dissection.sh
104 if [ $TEST_OUTDIR_CLEAN = 1 ]; then
105 # display contents of test outputs, ignore directory:
106 # home (decryption suite)
107 grep -r . --exclude-dir=home .
108 rm -rf "$TEST_OUTDIR"
109 elif ! rmdir "$TEST_OUTDIR" 2>/dev/null; then
110 # if directory is non-empty, print directory
111 echo "Test results are available in $TEST_OUTDIR"
114 trap test_cleanup EXIT
117 test_step_prerequisites() {
120 for i in "$WIRESHARK" "$TSHARK" "$CAPINFOS" "$MERGECAP" "$DUMPCAP" ; do
122 echo "Couldn't find $i"
126 if [ $NOTFOUND -eq 1 ]; then
127 test_step_failed "Tool not found"
134 # Dump version information
135 test_step_tshark_version() {
136 test_remark_add "Printing TShark version"
137 $TESTS_DIR/run_and_catch_crashes $TSHARK -v
139 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
140 test_step_failed "Failed to print version information"
147 prerequisites_suite() {
148 test_step_add "Prerequisites settings" test_step_prerequisites
149 test_step_add "Version information" test_step_tshark_version
153 test_suite_add "Prerequisites" prerequisites_suite
154 test_suite_add "Command line options" clopt_suite
155 test_suite_add "File I/O" io_suite
156 test_suite_add "Capture" capture_suite
157 test_suite_add "Unit tests" unittests_suite
158 test_suite_add "Decryption" decryption_suite
159 test_suite_add "Name Resolution" name_resolution_suite
160 test_suite_add "Lua API" wslua_suite
161 test_suite_add "Mergecap" mergecap_suite
162 test_suite_add "File formats" fileformats_suite
163 test_suite_add "Text2pcap" text2pcap_suite
164 test_suite_add "Dissection" dissection_suite
168 #test_set_output OFF # doesn't work
169 #test_set_output DOTTED
170 test_set_output VERBOSE
173 #test_suite_run "TShark command line options" clopt_suite
174 #test_suite_run "TShark capture" capture_suite
178 #test_suite_run "All" test_suite
179 #test_suite_show "All" test_suite
181 if [ -n "$RUN_SUITE" ] ; then
184 test_suite_run "All" test_suite
187 test_suite_run "Capture" capture_suite
190 test_suite_run "Command line options" clopt_suite
193 test_suite_run "Decryption" decryption_suite
196 test_suite_run "File formats" fileformats_suite
199 test_suite_run "File I/O" io_suite
202 test_suite_run "Name Resolution" name_resolution_suite
205 test_suite_run "Prerequisites" prerequisites_suite
208 test_suite_run "Unit tests" unittests_suite
211 test_suite_run "Lua API" wslua_suite
214 test_suite_run "Text2pcap" text2pcap_suite
217 test_suite_run "Dissection" dissection_suite
225 menu_function[0]=test_suite
227 echo "----------------------------------------------------------------------"
229 for ((a=0; a <= 100000000000 ; a++))
231 TEST_STEPS[0]=0 # number of steps of a specific nesting level
233 #echo $current_title $current_function
234 test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
235 if [ $MENU_LEVEL -gt 0 ]; then
236 echo "T or Enter: Run suite"
238 echo "1-$TEST_STEPS : Select suite"
242 #echo "Menu level: $MENU_LEVEL"
243 #echo "Menu Title: ${menu_title[MENU_LEVEL]}"
244 #echo "Menu Function: ${menu_function[MENU_LEVEL]}"
245 #echo "Test title size: ${#test_title[@]}"
248 if [[ ! $MENU_LEVEL -eq 0 ]]; then
255 echo "$newl----------------------------------------------------------------------"
257 TEST_STEPS[0]=0 # number of steps of a specific nesting level
266 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++)) # Double parentheses, and "LIMIT" with no "$".
268 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
270 echo "----------------------------------------------------------------------"
273 if [[ ! $MENU_LEVEL -eq 0 ]]; then
274 let "MENU_LEVEL -= 1"
275 #echo "----------------------------------------------------------------------"
278 ## Now we're only interested in digits when the menu level is at the top (0)
280 if [ $MENU_LEVEL -eq 0 ]; then
281 if [ $key -le ${#test_title[@]} ]; then
282 let "MENU_LEVEL += 1"
283 menu_title[MENU_LEVEL]=${test_title[$key]}
284 menu_function[MENU_LEVEL]=${test_function[$key]}
296 # indent-tabs-mode: t
299 # ex: set shiftwidth=8 tabstop=8 noexpandtab:
300 # :indentSize=8:tabSize=8:noTabs=false: