Capture tests using Wireshark seem to be causing a problem; disable them for now.
[obnox/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 # $Id$
9 #
10 # Wireshark - Network traffic analyzer
11 # By Gerald Combs <gerald@wireshark.org>
12 # Copyright 2005 Ulf Lamping
13 #
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.
18 #
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.
23 #
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28
29 # an existing capture file
30 CAPFILE=./dhcp.pcap
31 USE_COLOR=1
32 RUN_SUITE=""
33 PRINT_USAGE=0
34
35 while getopts "chs:" OPTION ; do
36         case $OPTION in
37           c) USE_COLOR=0 ;;
38           h) PRINT_USAGE=1 ;;
39           s) RUN_SUITE="$OPTARG" ;;
40           *) echo "Unknown option: " $OPTION $OPTARG
41         esac
42 done
43
44 shift $(( $OPTIND - 1 ))
45
46 if [ $PRINT_USAGE -ne 0 ] ; then
47         THIS=`basename $0`
48         cat <<FIN
49 Usage: $THIS [-c] [-h] [-s <suite>]
50   -c: Disable color output
51   -h: Print this message and exit
52   -s: Run a suite.  Must be one of: all, capture, clopts, io, or
53       prerequisites
54 FIN
55         exit 0
56 fi
57
58 source test-backend.sh
59
60 source config.sh
61 source suite-clopts.sh
62 source suite-io.sh
63 source suite-capture.sh
64 source suite-unittests.sh
65
66
67 #check prerequisites
68 test_step_prerequisites() {
69
70         NOTFOUND=0
71         for i in "$WIRESHARK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
72                 if [ ! -x $i ]; then
73                         echo "Couldn't find $i"
74                         NOTFOUND=1
75                 fi
76         done
77         if [ $NOTFOUND -eq 1 ]; then
78                 test_step_failed "Tool not found"
79                 exit 1
80         else
81                 test_step_ok
82         fi
83 }
84
85
86 prerequisites_suite() {
87         test_step_add "Prerequisites settings" test_step_prerequisites
88 }
89
90 test_suite() {
91         test_suite_add "Prerequisites" prerequisites_suite
92         test_suite_add "Command line options" clopt_suite
93         test_suite_add "File I/O" io_suite
94         test_suite_add "Capture" capture_suite
95         test_suite_add "Unittests" unittests_suite
96 }
97
98
99 #test_set_output OFF # doesn't work
100 #test_set_output DOTTED
101 test_set_output VERBOSE
102
103
104 #test_suite_run "TShark command line options" clopt_suite
105 #test_suite_run "TShark capture" capture_suite
106
107
108 # all
109 #test_suite_run "All" test_suite
110 #test_suite_show "All" test_suite
111
112 if [ -n "$RUN_SUITE" ] ; then
113         case $RUN_SUITE in
114           "all")
115             test_suite_run "All" test_suite
116             exit $? ;;
117           "capture")
118             test_suite_run "Capture" capture_suite
119             exit $? ;;
120           "clopts")
121             test_suite_run "Command line options" clopt_suite
122             exit $? ;;
123           "io")
124             test_suite_run "File I/O" io_suite
125             exit $? ;;
126           "prerequisites")
127             test_suite_run "Prerequisites" prerequisites_suite
128             exit $? ;;
129         esac
130 fi
131
132 MENU_LEVEL=0
133
134 menu_title[0]="All"
135 menu_function[0]=test_suite
136
137 echo "----------------------------------------------------------------------"
138
139 for ((a=0; a <= 100000000000 ; a++))
140 do
141         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
142
143         #echo $current_title $current_function
144         test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
145         echo "1-$TEST_STEPS  : Select item"
146         echo "Enter: Test All"
147         if [[ ! $MENU_LEVEL -eq 0 ]]; then
148                 echo "U    : Up"
149         fi
150         echo "Q    : Quit"
151         echo ""
152         read -n1 key
153         newl=$'\x0d'
154         echo "$newl----------------------------------------------------------------------"
155
156         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
157
158         #echo $key
159         case "$key" in
160                 "Q" | "q")
161                 exit 0
162         ;;
163                 "T" | "t" | "")
164 LIMIT_RUNS=1
165 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++))  # Double parentheses, and "LIMIT" with no "$".
166 do
167                 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
168 done
169                 echo "----------------------------------------------------------------------"
170         ;;
171                 "U" | "u")
172                 if [[ ! $MENU_LEVEL -eq 0 ]]; then
173                         let "MENU_LEVEL -= 1"
174                         #echo "----------------------------------------------------------------------"
175                 fi
176         ;;
177                 "1")
178                 let "MENU_LEVEL += 1"
179                 menu_title[MENU_LEVEL]=${test_title[1]}
180                 menu_function[MENU_LEVEL]=${test_function[1]}
181         ;;
182                 "2")
183                 let "MENU_LEVEL += 1"
184                 menu_title[MENU_LEVEL]=${test_title[2]}
185                 menu_function[MENU_LEVEL]=${test_function[2]}
186         ;;
187                 "3")
188                 let "MENU_LEVEL += 1"
189                 menu_title[MENU_LEVEL]=${test_title[3]}
190                 menu_function[MENU_LEVEL]=${test_function[3]}
191         ;;
192                 "4")
193                 let "MENU_LEVEL += 1"
194                 menu_title[MENU_LEVEL]=${test_title[4]}
195                 menu_function[MENU_LEVEL]=${test_function[4]}
196         ;;
197                 "5")
198                 let "MENU_LEVEL += 1"
199                 menu_title[MENU_LEVEL]=${test_title[5]}
200                 menu_function[MENU_LEVEL]=${test_function[5]}
201         ;;
202                 "6")
203                 let "MENU_LEVEL += 1"
204                 menu_title[MENU_LEVEL]=${test_title[6]}
205                 menu_function[MENU_LEVEL]=${test_function[6]}
206         ;;
207                 "7")
208                 let "MENU_LEVEL += 1"
209                 menu_title[MENU_LEVEL]=${test_title[7]}
210                 menu_function[MENU_LEVEL]=${test_function[7]}
211         ;;
212                 "8")
213                 let "MENU_LEVEL += 1"
214                 menu_title[MENU_LEVEL]=${test_title[8]}
215                 menu_function[MENU_LEVEL]=${test_function[8]}
216         ;;
217                 "9")
218                 let "MENU_LEVEL += 1"
219                 menu_title[MENU_LEVEL]=${test_title[9]}
220                 menu_function[MENU_LEVEL]=${test_function[9]}
221         ;;
222
223         esac
224 done