Qt → wireshark. GTK+ → wireshark-gtk.
[metze/wireshark/wip.git] / test / test.sh
1 #!/bin/bash
2 (shopt -s igncr) 2>/dev/null && shopt -s igncr; # comment is needed
3 #                                               # hack for cygwin bash
4 #                                               #  no-op for other
5 #
6 # Test various command line testable aspects of the Wireshark tools
7 #
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 2005 Ulf Lamping
11 #
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.
16 #
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.
21 #
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.
25 #
26
27 # an existing capture file
28 USE_COLOR=1
29 RUN_SUITE=""
30 PRINT_USAGE=0
31
32 while getopts "chs:" OPTION ; do
33         case $OPTION in
34           c) USE_COLOR=0 ;;
35           h) PRINT_USAGE=1 ;;
36           s) RUN_SUITE="$OPTARG" ;;
37           *) echo "Unknown option: " $OPTION $OPTARG
38         esac
39 done
40
41 shift $(( $OPTIND - 1 ))
42
43 if [ $PRINT_USAGE -ne 0 ] ; then
44         THIS=`basename $0`
45         cat <<FIN
46 Usage: $THIS [-c] [-h] [-s <suite>]
47   -c: Disable color output
48   -h: Print this message and exit
49   -s: Run a suite.  Must be one of:
50       all
51       capture
52       clopts
53       decryption
54       fileformats
55       io
56       nameres
57       prerequisites
58       unittests
59       wslua
60 FIN
61         exit 0
62 fi
63
64 source test-backend.sh
65
66 source config.sh
67
68 # needed by some tests
69 TEST_OUTDIR=$(mktemp -d)
70 TEST_OUTDIR_CLEAN=${TEST_OUTDIR_CLEAN:-1}
71 if [ -z "$TEST_OUTDIR" ] || ! cd "$TEST_OUTDIR"; then
72         # If for any reason the temporary tests output directory cannot be created...
73         TEST_OUTDIR=.
74         TEST_OUTDIR_CLEAN=0
75 fi
76
77 # Configuration paths
78 HOME_ENV="HOME"
79 HOME_PATH="$TEST_OUTDIR/home"
80 CONF_PATH="$HOME_PATH/.wireshark"
81
82 if [ "$WS_SYSTEM" == "Windows" ] ; then
83     HOME_ENV="APPDATA"
84     HOME_PATH="`cygpath -w $HOME_PATH`"
85     CONF_PATH="$HOME_PATH/Wireshark"
86     CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
87 fi
88
89 mkdir -p $CONF_PATH
90
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
100 test_cleanup() {
101         if [ $TEST_OUTDIR_CLEAN = 1 ]; then
102                 # display contents of test outputs, ignore directory:
103                 # home (decryption suite)
104                 grep -r . --exclude-dir=home .
105                 rm -rf "$TEST_OUTDIR"
106         elif ! rmdir "$TEST_OUTDIR" 2>/dev/null; then
107                 # if directory is non-empty, print directory
108                 echo "Test results are available in $TEST_OUTDIR"
109         fi
110 }
111 trap test_cleanup EXIT
112
113 #check prerequisites
114 test_step_prerequisites() {
115
116         NOTFOUND=0
117         for i in "$WIRESHARK_GTK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
118                 if [ ! -x $i ]; then
119                         echo "Couldn't find $i"
120                         NOTFOUND=1
121                 fi
122         done
123         if [ $NOTFOUND -eq 1 ]; then
124                 test_step_failed "Tool not found"
125                 exit 1
126         else
127                 test_step_ok
128         fi
129 }
130
131 # Dump version information
132 test_step_tshark_version() {
133         test_remark_add "Printing TShark version"
134         $TSHARK -v
135         RETURNVALUE=$?
136         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
137                 test_step_failed "Failed to print version information"
138                 return
139         fi
140         test_step_ok
141 }
142
143
144 prerequisites_suite() {
145         test_step_add "Prerequisites settings" test_step_prerequisites
146         test_step_add "Version information" test_step_tshark_version
147 }
148
149 test_suite() {
150         test_suite_add "Prerequisites" prerequisites_suite
151         test_suite_add "Command line options" clopt_suite
152         test_suite_add "File I/O" io_suite
153         test_suite_add "Capture" capture_suite
154         test_suite_add "Unit tests" unittests_suite
155         test_suite_add "File formats" fileformats_suite
156         test_suite_add "Decryption" decryption_suite
157         test_suite_add "Name Resolution" name_resolution_suite
158         test_suite_add "Lua API" wslua_suite
159 }
160
161
162 #test_set_output OFF # doesn't work
163 #test_set_output DOTTED
164 test_set_output VERBOSE
165
166
167 #test_suite_run "TShark command line options" clopt_suite
168 #test_suite_run "TShark capture" capture_suite
169
170
171 # all
172 #test_suite_run "All" test_suite
173 #test_suite_show "All" test_suite
174
175 if [ -n "$RUN_SUITE" ] ; then
176         case $RUN_SUITE in
177           "all")
178             test_suite_run "All" test_suite
179             exit $? ;;
180           "capture")
181             test_suite_run "Capture" capture_suite
182             exit $? ;;
183           "clopts")
184             test_suite_run "Command line options" clopt_suite
185             exit $? ;;
186           "decryption")
187             test_suite_run "Decryption" decryption_suite
188             exit $? ;;
189           "fileformats")
190             test_suite_run "File formats" fileformats_suite
191             exit $? ;;
192           "io")
193             test_suite_run "File I/O" io_suite
194             exit $? ;;
195           "nameres")
196             test_suite_run "Name Resolution" name_resolution_suite
197             exit $? ;;
198           "prerequisites")
199             test_suite_run "Prerequisites" prerequisites_suite
200             exit $? ;;
201           "unittests")
202             test_suite_run "Unit tests" unittests_suite
203             exit $? ;;
204           "wslua")
205             test_suite_run "Lua API" wslua_suite
206             exit $? ;;
207         esac
208 fi
209
210 MENU_LEVEL=0
211
212 menu_title[0]="All"
213 menu_function[0]=test_suite
214
215 echo "----------------------------------------------------------------------"
216
217 for ((a=0; a <= 100000000000 ; a++))
218 do
219         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
220
221         #echo $current_title $current_function
222         test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
223         echo "1-$TEST_STEPS  : Select item"
224         echo "Enter: Test All"
225         if [[ ! $MENU_LEVEL -eq 0 ]]; then
226                 echo "U    : Up"
227         fi
228         echo "Q    : Quit"
229         echo ""
230         read -n1 key
231         newl=$'\x0d'
232         echo "$newl----------------------------------------------------------------------"
233
234         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
235
236         #echo $key
237         case "$key" in
238                 "Q" | "q")
239                 exit 0
240         ;;
241                 "T" | "t" | "")
242 LIMIT_RUNS=1
243 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++))  # Double parentheses, and "LIMIT" with no "$".
244 do
245                 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
246 done
247                 echo "----------------------------------------------------------------------"
248         ;;
249                 "U" | "u")
250                 if [[ ! $MENU_LEVEL -eq 0 ]]; then
251                         let "MENU_LEVEL -= 1"
252                         #echo "----------------------------------------------------------------------"
253                 fi
254         ;;
255                 "1")
256                 let "MENU_LEVEL += 1"
257                 menu_title[MENU_LEVEL]=${test_title[1]}
258                 menu_function[MENU_LEVEL]=${test_function[1]}
259         ;;
260                 "2")
261                 let "MENU_LEVEL += 1"
262                 menu_title[MENU_LEVEL]=${test_title[2]}
263                 menu_function[MENU_LEVEL]=${test_function[2]}
264         ;;
265                 "3")
266                 let "MENU_LEVEL += 1"
267                 menu_title[MENU_LEVEL]=${test_title[3]}
268                 menu_function[MENU_LEVEL]=${test_function[3]}
269         ;;
270                 "4")
271                 let "MENU_LEVEL += 1"
272                 menu_title[MENU_LEVEL]=${test_title[4]}
273                 menu_function[MENU_LEVEL]=${test_function[4]}
274         ;;
275                 "5")
276                 let "MENU_LEVEL += 1"
277                 menu_title[MENU_LEVEL]=${test_title[5]}
278                 menu_function[MENU_LEVEL]=${test_function[5]}
279         ;;
280                 "6")
281                 let "MENU_LEVEL += 1"
282                 menu_title[MENU_LEVEL]=${test_title[6]}
283                 menu_function[MENU_LEVEL]=${test_function[6]}
284         ;;
285                 "7")
286                 let "MENU_LEVEL += 1"
287                 menu_title[MENU_LEVEL]=${test_title[7]}
288                 menu_function[MENU_LEVEL]=${test_function[7]}
289         ;;
290                 "8")
291                 let "MENU_LEVEL += 1"
292                 menu_title[MENU_LEVEL]=${test_title[8]}
293                 menu_function[MENU_LEVEL]=${test_function[8]}
294         ;;
295                 "9")
296                 let "MENU_LEVEL += 1"
297                 menu_title[MENU_LEVEL]=${test_title[9]}
298                 menu_function[MENU_LEVEL]=${test_function[9]}
299         ;;
300
301         esac
302 done