add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / test / test.sh
blob3d8b0795a8568f62d96520a6dc4cc8154d855f7f
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
6 # Test various command line testable aspects of the Wireshark tools
8 # $Id$
10 # Wireshark - Network traffic analyzer
11 # By Gerald Combs <gerald@wireshark.org>
12 # Copyright 2005 Ulf Lamping
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 # an existing capture file
30 USE_COLOR=1
31 RUN_SUITE=""
32 PRINT_USAGE=0
34 while getopts "chs:" OPTION ; do
35 case $OPTION in
36 c) USE_COLOR=0 ;;
37 h) PRINT_USAGE=1 ;;
38 s) RUN_SUITE="$OPTARG" ;;
39 *) echo "Unknown option: " $OPTION $OPTARG
40 esac
41 done
43 shift $(( $OPTIND - 1 ))
45 if [ $PRINT_USAGE -ne 0 ] ; then
46 THIS=`basename $0`
47 cat <<FIN
48 Usage: $THIS [-c] [-h] [-s <suite>]
49 -c: Disable color output
50 -h: Print this message and exit
51 -s: Run a suite. Must be one of:
52 all
53 capture
54 clopts
55 decryption
56 fileformats
58 nameres
59 prerequisites
60 unittests
61 FIN
62 exit 0
65 source test-backend.sh
67 source config.sh
69 # needed by some tests
70 TEST_OUTDIR=$(mktemp -d)
71 TEST_OUTDIR_CLEAN=${TEST_OUTDIR_CLEAN:-1}
72 if [ -z "$TEST_OUTDIR" ] || ! cd "$TEST_OUTDIR"; then
73 # If for any reason the temporary tests output directory cannot be created...
74 TEST_OUTDIR=.
75 TEST_OUTDIR_CLEAN=0
78 # Configuration paths
79 HOME_ENV="HOME"
80 HOME_PATH="$TEST_OUTDIR/home"
81 CONF_PATH="$HOME_PATH/.wireshark"
83 if [ "$WS_SYSTEM" == "Windows" ] ; then
84 HOME_ENV="APPDATA"
85 HOME_PATH="`cygpath -w $HOME_PATH`"
86 CONF_PATH="$HOME_PATH/Wireshark"
87 CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
90 mkdir -p $CONF_PATH
92 source $TESTS_DIR/suite-clopts.sh
93 source $TESTS_DIR/suite-io.sh
94 source $TESTS_DIR/suite-capture.sh
95 source $TESTS_DIR/suite-unittests.sh
96 source $TESTS_DIR/suite-fileformats.sh
97 source $TESTS_DIR/suite-decryption.sh
98 source $TESTS_DIR/suite-nameres.sh
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"
111 trap test_cleanup EXIT
113 #check prerequisites
114 test_step_prerequisites() {
116 NOTFOUND=0
117 for i in "$WIRESHARK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
118 if [ ! -x $i ]; then
119 echo "Couldn't find $i"
120 NOTFOUND=1
122 done
123 if [ $NOTFOUND -eq 1 ]; then
124 test_step_failed "Tool not found"
125 exit 1
126 else
127 test_step_ok
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
140 test_step_ok
144 prerequisites_suite() {
145 test_step_add "Prerequisites settings" test_step_prerequisites
146 test_step_add "Version information" test_step_tshark_version
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
161 #test_set_output OFF # doesn't work
162 #test_set_output DOTTED
163 test_set_output VERBOSE
166 #test_suite_run "TShark command line options" clopt_suite
167 #test_suite_run "TShark capture" capture_suite
170 # all
171 #test_suite_run "All" test_suite
172 #test_suite_show "All" test_suite
174 if [ -n "$RUN_SUITE" ] ; then
175 case $RUN_SUITE in
176 "all")
177 test_suite_run "All" test_suite
178 exit $? ;;
179 "capture")
180 test_suite_run "Capture" capture_suite
181 exit $? ;;
182 "clopts")
183 test_suite_run "Command line options" clopt_suite
184 exit $? ;;
185 "decryption")
186 test_suite_run "Decryption" decryption_suite
187 exit $? ;;
188 "fileformats")
189 test_suite_run "File formats" fileformats_suite
190 exit $? ;;
191 "io")
192 test_suite_run "File I/O" io_suite
193 exit $? ;;
194 "nameres")
195 test_suite_run "Name Resolution" name_resolution_suite
196 exit $? ;;
197 "prerequisites")
198 test_suite_run "Prerequisites" prerequisites_suite
199 exit $? ;;
200 "unittests")
201 test_suite_run "Unit tests" unittests_suite
202 exit $? ;;
203 esac
206 MENU_LEVEL=0
208 menu_title[0]="All"
209 menu_function[0]=test_suite
211 echo "----------------------------------------------------------------------"
213 for ((a=0; a <= 100000000000 ; a++))
215 TEST_STEPS[0]=0 # number of steps of a specific nesting level
217 #echo $current_title $current_function
218 test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
219 echo "1-$TEST_STEPS : Select item"
220 echo "Enter: Test All"
221 if [[ ! $MENU_LEVEL -eq 0 ]]; then
222 echo "U : Up"
224 echo "Q : Quit"
225 echo ""
226 read -n1 key
227 newl=$'\x0d'
228 echo "$newl----------------------------------------------------------------------"
230 TEST_STEPS[0]=0 # number of steps of a specific nesting level
232 #echo $key
233 case "$key" in
234 "Q" | "q")
235 exit 0
237 "T" | "t" | "")
238 LIMIT_RUNS=1
239 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++)) # Double parentheses, and "LIMIT" with no "$".
241 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
242 done
243 echo "----------------------------------------------------------------------"
245 "U" | "u")
246 if [[ ! $MENU_LEVEL -eq 0 ]]; then
247 let "MENU_LEVEL -= 1"
248 #echo "----------------------------------------------------------------------"
251 "1")
252 let "MENU_LEVEL += 1"
253 menu_title[MENU_LEVEL]=${test_title[1]}
254 menu_function[MENU_LEVEL]=${test_function[1]}
256 "2")
257 let "MENU_LEVEL += 1"
258 menu_title[MENU_LEVEL]=${test_title[2]}
259 menu_function[MENU_LEVEL]=${test_function[2]}
261 "3")
262 let "MENU_LEVEL += 1"
263 menu_title[MENU_LEVEL]=${test_title[3]}
264 menu_function[MENU_LEVEL]=${test_function[3]}
266 "4")
267 let "MENU_LEVEL += 1"
268 menu_title[MENU_LEVEL]=${test_title[4]}
269 menu_function[MENU_LEVEL]=${test_function[4]}
271 "5")
272 let "MENU_LEVEL += 1"
273 menu_title[MENU_LEVEL]=${test_title[5]}
274 menu_function[MENU_LEVEL]=${test_function[5]}
276 "6")
277 let "MENU_LEVEL += 1"
278 menu_title[MENU_LEVEL]=${test_title[6]}
279 menu_function[MENU_LEVEL]=${test_function[6]}
281 "7")
282 let "MENU_LEVEL += 1"
283 menu_title[MENU_LEVEL]=${test_title[7]}
284 menu_function[MENU_LEVEL]=${test_function[7]}
286 "8")
287 let "MENU_LEVEL += 1"
288 menu_title[MENU_LEVEL]=${test_title[8]}
289 menu_function[MENU_LEVEL]=${test_function[8]}
291 "9")
292 let "MENU_LEVEL += 1"
293 menu_title[MENU_LEVEL]=${test_title[9]}
294 menu_function[MENU_LEVEL]=${test_function[9]}
297 esac
298 done