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 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 # an existing capture file
32 # Ensure cygwin bin dir is on the path if running under it
33 if [[ $OSTYPE == "cygwin" ]]; then
37 while getopts "chs:" OPTION ; do
41 s) RUN_SUITE="$OPTARG" ;;
42 *) echo "Unknown option: " $OPTION $OPTARG
46 shift $(( $OPTIND - 1 ))
48 if [ $PRINT_USAGE -ne 0 ] ; then
51 Usage: $THIS [-c] [-h] [-s <suite>]
52 -c: Disable color output
53 -h: Print this message and exit
54 -s: Run a suite. Must be one of:
71 if [ -e run/tshark -o -e run/dumpcap -o -e run/rawshark ]; then
72 WS_BIN_PATH=${WS_BIN_PATH:-$(cd run && pwd)}
73 WS_QT_BIN_PATH=${WS_QT_BIN_PATH:-$WS_BIN_PATH}
76 source $MYDIR/test-backend.sh
77 source $MYDIR/config.sh
79 # needed by some tests
80 TEST_OUTDIR=$(mktemp -d)
81 TEST_OUTDIR_CLEAN=${TEST_OUTDIR_CLEAN:-1}
82 if [ -z "$TEST_OUTDIR" ] || ! cd "$TEST_OUTDIR"; then
83 # If for any reason the temporary tests output directory cannot be created...
90 HOME_PATH="$TEST_OUTDIR/home"
91 CONF_PATH="$HOME_PATH/.wireshark"
93 if [ "$WS_SYSTEM" == "Windows" ] ; then
95 HOME_PATH="`cygpath -w $HOME_PATH`"
96 CONF_PATH="$HOME_PATH/Wireshark"
97 CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
98 TESTS_DIR="`cygpath -w $TESTS_DIR`"
103 source $TESTS_DIR/suite-clopts.sh
104 source $TESTS_DIR/suite-io.sh
105 source $TESTS_DIR/suite-capture.sh
106 source $TESTS_DIR/suite-unittests.sh
107 source $TESTS_DIR/suite-fileformats.sh
108 source $TESTS_DIR/suite-decryption.sh
109 source $TESTS_DIR/suite-nameres.sh
110 source $TESTS_DIR/suite-wslua.sh
111 source $TESTS_DIR/suite-mergecap.sh
112 source $TESTS_DIR/suite-text2pcap.sh
115 if [ $TEST_OUTDIR_CLEAN = 1 ]; then
116 # display contents of test outputs, ignore directory:
117 # home (decryption suite)
118 grep -r . --exclude-dir=home .
119 rm -rf "$TEST_OUTDIR"
120 elif ! rmdir "$TEST_OUTDIR" 2>/dev/null; then
121 # if directory is non-empty, print directory
122 echo "Test results are available in $TEST_OUTDIR"
125 trap test_cleanup EXIT
128 test_step_prerequisites() {
131 for i in "$WIRESHARK" "$WIRESHARK_GTK" "$TSHARK" "$CAPINFOS" "$MERGECAP" "$DUMPCAP" ; do
133 echo "Couldn't find $i"
137 if [ $NOTFOUND -eq 1 ]; then
138 test_step_failed "Tool not found"
145 # Dump version information
146 test_step_tshark_version() {
147 test_remark_add "Printing TShark version"
148 $TESTS_DIR/run_and_catch_crashes $TSHARK -v
150 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
151 test_step_failed "Failed to print version information"
158 prerequisites_suite() {
159 test_step_add "Prerequisites settings" test_step_prerequisites
160 test_step_add "Version information" test_step_tshark_version
164 test_suite_add "Prerequisites" prerequisites_suite
165 test_suite_add "Command line options" clopt_suite
166 test_suite_add "File I/O" io_suite
167 test_suite_add "Capture" capture_suite
168 test_suite_add "Unit tests" unittests_suite
169 test_suite_add "Decryption" decryption_suite
170 test_suite_add "Name Resolution" name_resolution_suite
171 test_suite_add "Lua API" wslua_suite
172 test_suite_add "Mergecap" mergecap_suite
173 test_suite_add "File formats" fileformats_suite
174 test_suite_add "Text2pcap" text2pcap_suite
178 #test_set_output OFF # doesn't work
179 #test_set_output DOTTED
180 test_set_output VERBOSE
183 #test_suite_run "TShark command line options" clopt_suite
184 #test_suite_run "TShark capture" capture_suite
188 #test_suite_run "All" test_suite
189 #test_suite_show "All" test_suite
191 if [ -n "$RUN_SUITE" ] ; then
194 test_suite_run "All" test_suite
197 test_suite_run "Capture" capture_suite
200 test_suite_run "Command line options" clopt_suite
203 test_suite_run "Decryption" decryption_suite
206 test_suite_run "File formats" fileformats_suite
209 test_suite_run "File I/O" io_suite
212 test_suite_run "Name Resolution" name_resolution_suite
215 test_suite_run "Prerequisites" prerequisites_suite
218 test_suite_run "Unit tests" unittests_suite
221 test_suite_run "Lua API" wslua_suite
224 test_suite_run "Text2pcap" text2pcap_suite
232 menu_function[0]=test_suite
234 echo "----------------------------------------------------------------------"
236 for ((a=0; a <= 100000000000 ; a++))
238 TEST_STEPS[0]=0 # number of steps of a specific nesting level
240 #echo $current_title $current_function
241 test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
242 if [ $MENU_LEVEL -gt 0 ]; then
243 echo "T or Enter: Run suite"
245 echo "1-$TEST_STEPS : Select suite"
249 #echo "Menu level: $MENU_LEVEL"
250 #echo "Menu Title: ${menu_title[MENU_LEVEL]}"
251 #echo "Menu Function: ${menu_function[MENU_LEVEL]}"
252 #echo "Test title size: ${#test_title[@]}"
255 if [[ ! $MENU_LEVEL -eq 0 ]]; then
262 echo "$newl----------------------------------------------------------------------"
264 TEST_STEPS[0]=0 # number of steps of a specific nesting level
273 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++)) # Double parentheses, and "LIMIT" with no "$".
275 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
277 echo "----------------------------------------------------------------------"
280 if [[ ! $MENU_LEVEL -eq 0 ]]; then
281 let "MENU_LEVEL -= 1"
282 #echo "----------------------------------------------------------------------"
285 ## Now we're only interested in digits when the menu level is at the top (0)
287 if [ $MENU_LEVEL -eq 0 ]; then
288 if [ $key -le ${#test_title[@]} ]; then
289 let "MENU_LEVEL += 1"
290 menu_title[MENU_LEVEL]=${test_title[$key]}
291 menu_function[MENU_LEVEL]=${test_function[$key]}
303 # indent-tabs-mode: t
306 # ex: set shiftwidth=8 tabstop=8 noexpandtab:
307 # :indentSize=8:tabSize=8:noTabs=false: