HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / test / suite-clopts.sh
blobc474f5fd95d13718763c8c90af43114af9e052b3
1 #!/bin/bash
3 # Test the command line options of the Wireshark tools
5 # $Id$
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 # common exit status values
27 EXIT_OK=0
28 EXIT_COMMAND_LINE=1
29 EXIT_ERROR=2
31 # generic: check against a specific exit status with a single char option
32 # $1 command: tshark or dumpcap
33 # $2 option: a
34 # $3 expected exit status: 0
35 test_single_char_options()
37 #echo "command: "$1" opt1: "$2" opt2: "$3" opt3: "$4" opt4: "$5" opt5: "$6
38 $1 -$2 > ./testout.txt 2>&1
39 RETURNVALUE=$?
40 if [ ! $RETURNVALUE -eq $3 ]; then
41 test_step_failed "exit status: $RETURNVALUE"
42 else
43 test_step_ok
45 rm ./testout.txt
48 # dumpcap
50 # Only with remote capture: A:ru
51 # Only with WinPcap: m:
52 # Only with WinPcap or 1.0.0-or-later libpcap: B:
53 # Only with 1.0.0-or-later libpcap: I
54 # Only with libpcap/WinPcap with bpf_image(): d
56 # check exit status of all invalid single char dumpcap options (must be 1)
57 clopts_suite_dumpcap_invalid_chars() {
58 for index in C E F G H J K N O Q R T U V W X Y e j l o x z
60 test_step_add "Invalid dumpcap parameter -$index, exit status must be $EXIT_COMMAND_LINE" "test_single_char_options $DUMPCAP $index $EXIT_COMMAND_LINE"
61 done
64 # check exit status of all valid single char dumpcap options being (must be 0)
65 # tests only those options that cause dumpcap to do something other than
66 # capture
67 clopts_suite_dumpcap_valid_chars() {
68 for index in h v
70 test_step_add "Valid dumpcap parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $DUMPCAP $index $EXIT_OK"
71 done
74 # special case: interface-specific opts should work under Windows and fail as
75 # a regular user on other systems.
76 clopts_suite_dumpcap_interface_chars() {
77 for index in D L
79 if [ "$SKIP_CAPTURE" -eq 0 ] ; then
80 test_step_add "Valid dumpcap parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $DUMPCAP $index $EXIT_OK"
81 else
82 test_step_add "Invalid permissions for dumpcap parameter -$index, exit status must be $EXIT_ERROR" "test_single_char_options $DUMPCAP $index $EXIT_ERROR"
84 done
87 # check exit status and grep output string of an invalid capture filter
88 clopts_step_dumpcap_invalid_capfilter() {
89 if [ "$WS_SYSTEM" != "Windows" ] ; then
90 test_step_skipped
91 return
94 $DUMPCAP -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
95 RETURNVALUE=$?
96 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
97 test_step_failed "exit status: $RETURNVALUE"
98 else
99 grep -i 'Invalid capture filter "jkghg" for interface' ./testout.txt > /dev/null
100 if [ $? -eq 0 ]; then
101 test_step_output_print ./testout.txt
102 test_step_ok
103 else
104 test_step_output_print ./testout.txt
105 test_step_failed "Error message wasn't what we expected"
110 # check exit status and grep output string of an invalid interface
111 clopts_step_dumpcap_invalid_interfaces() {
112 $DUMPCAP -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
113 RETURNVALUE=$?
114 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
115 test_step_failed "exit status: $RETURNVALUE"
116 else
117 grep -i 'The capture session could not be initiated' ./testout.txt > /dev/null
118 if [ $? -eq 0 ]; then
119 test_step_output_print ./testout.txt
120 test_step_ok
121 else
122 test_step_output_print ./testout.txt
123 test_step_failed "Error message wasn't what we expected"
128 # check exit status and grep output string of an invalid interface index
129 # (valid interface indexes start with 1)
130 clopts_step_dumpcap_invalid_interfaces_index() {
131 $DUMPCAP -i 0 -w './testout.pcap' > ./testout.txt 2>&1
132 RETURNVALUE=$?
133 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
134 test_step_failed "exit status: $RETURNVALUE"
135 else
136 grep -i 'There is no interface with that adapter index' ./testout.txt > /dev/null
137 if [ $? -eq 0 ]; then
138 test_step_ok
139 else
140 test_step_output_print ./testout.txt
141 test_step_failed "Error message wasn't what we expected"
146 # TShark
148 # check exit status when reading an existing file
149 clopts_step_existing_file() {
150 $TSHARK -r "${CAPTURE_DIR}dhcp.pcap" > ./testout.txt 2>&1
151 RETURNVALUE=$?
152 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
153 test_step_failed "exit status: $RETURNVALUE"
154 else
155 test_step_ok
157 rm ./testout.txt
161 # check exit status when reading a non-existing file
162 clopts_step_nonexisting_file() {
163 $TSHARK -r ThisFileDontExist.pcap > ./testout.txt 2>&1
164 RETURNVALUE=$?
165 if [ ! $RETURNVALUE -eq $EXIT_ERROR ]; then
166 test_step_failed "exit status: $RETURNVALUE"
167 else
168 test_step_ok
170 rm ./testout.txt
174 # check exit status of all invalid single char TShark options (must be 1)
175 clopts_suite_tshark_invalid_chars() {
176 for index in A B C E F H J K M N O R T U W X Y Z a b c d e f i j k m o r s t u w y z
178 test_step_add "Invalid TShark parameter -$index, exit status must be $EXIT_COMMAND_LINE" "test_single_char_options $TSHARK $index $EXIT_COMMAND_LINE"
179 done
183 # check exit status of all valid single char TShark options being (must be 0)
184 clopts_suite_tshark_valid_chars() {
185 for index in G h v
187 test_step_add "Valid TShark parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TSHARK $index $EXIT_OK"
188 done
191 # special case: interface-specific opts should work under Windows and fail as
192 # a regular user on other systems.
193 clopts_suite_tshark_interface_chars() {
194 for index in D L
196 if [ "$SKIP_CAPTURE" -eq 0 ] ; then
197 test_step_add "Valid TShark parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TSHARK $index $EXIT_OK"
198 else
199 test_step_add "Invalid permissions for TShark parameter -$index, exit status must be $EXIT_ERROR" "test_single_char_options $TSHARK $index $EXIT_ERROR"
201 done
204 # S V l n p q x
206 # check exit status and grep output string of an invalid capture filter
207 clopts_step_tshark_invalid_capfilter() {
208 if [ "$WS_SYSTEM" != "Windows" ] ; then
209 test_step_skipped
210 return
213 $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
214 RETURNVALUE=$?
215 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
216 test_step_failed "exit status: $RETURNVALUE"
217 else
218 grep -i 'Invalid capture filter "jkghg" for interface' ./testout.txt > /dev/null
219 if [ $? -eq 0 ]; then
220 test_step_output_print ./testout.txt
221 test_step_ok
222 else
223 test_step_output_print ./testout.txt
224 test_step_failed "Error message wasn't what we expected"
229 # check exit status and grep output string of an invalid interface
230 clopts_step_tshark_invalid_interfaces() {
231 $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
232 RETURNVALUE=$?
233 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
234 test_step_failed "exit status: $RETURNVALUE"
235 else
236 grep -i 'The capture session could not be initiated' ./testout.txt > /dev/null
237 if [ $? -eq 0 ]; then
238 test_step_output_print ./testout.txt
239 test_step_ok
240 else
241 test_step_output_print ./testout.txt
242 test_step_failed "Error message wasn't what we expected"
247 # check exit status and grep output string of an invalid interface index
248 # (valid interface indexes start with 1)
249 clopts_step_tshark_invalid_interfaces_index() {
250 $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
251 RETURNVALUE=$?
252 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
253 test_step_failed "exit status: $RETURNVALUE"
254 else
255 grep -i 'There is no interface with that adapter index' ./testout.txt > /dev/null
256 if [ $? -eq 0 ]; then
257 test_step_ok
258 else
259 test_step_output_print ./testout.txt
260 test_step_failed "Error message wasn't what we expected"
265 # check exit status and grep output string of an invalid capture filter
266 # XXX - how to efficiently test the *invalid* flags?
267 clopts_step_valid_name_resolving() {
268 if [ "$WS_SYSTEM" != "Windows" ] ; then
269 test_step_skipped
270 return
273 $TSHARK -N mntC -a duration:1 > ./testout.txt 2>&1
274 RETURNVALUE=$?
275 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
276 test_step_failed "exit status: $RETURNVALUE"
277 else
278 test_step_ok
282 # check exit status of some basic functions
283 clopts_suite_basic() {
284 test_step_add "Exit status for existing file: \"""${CAPTURE_DIR}dhcp.pcap""\" must be 0" clopts_step_existing_file
285 test_step_add "Exit status for none existing files must be 2" clopts_step_nonexisting_file
288 clopts_suite_dumpcap_capture_options() {
289 test_step_add "Invalid dumpcap capture filter -f" clopts_step_dumpcap_invalid_capfilter
290 test_step_add "Invalid dumpcap capture interface -i" clopts_step_dumpcap_invalid_interfaces
291 test_step_add "Invalid dumpcap capture interface index 0" clopts_step_dumpcap_invalid_interfaces_index
294 clopts_suite_tshark_capture_options() {
295 test_step_add "Invalid TShark capture filter -f" clopts_step_tshark_invalid_capfilter
296 test_step_add "Invalid TShark capture interface -i" clopts_step_tshark_invalid_interfaces
297 test_step_add "Invalid TShark capture interface index 0" clopts_step_tshark_invalid_interfaces_index
300 clopts_post_step() {
301 rm -f ./testout.txt ./testout2.txt
304 clopt_suite() {
305 test_step_set_post clopts_post_step
306 test_suite_add "Basic tests" clopts_suite_basic
307 test_suite_add "Invalid dumpcap single char options" clopts_suite_dumpcap_invalid_chars
308 test_suite_add "Valid dumpcap single char options" clopts_suite_dumpcap_valid_chars
309 test_suite_add "Interface-specific dumpcap single char options" clopts_suite_dumpcap_interface_chars
310 test_suite_add "Capture filter/interface options tests" clopts_suite_dumpcap_capture_options
311 test_suite_add "Invalid TShark single char options" clopts_suite_tshark_invalid_chars
312 test_suite_add "Valid TShark single char options" clopts_suite_tshark_valid_chars
313 test_suite_add "Interface-specific TShark single char options" clopts_suite_tshark_interface_chars
314 test_suite_add "Capture filter/interface options tests" clopts_suite_tshark_capture_options
315 test_step_add "Valid name resolution options -N (1s)" clopts_step_valid_name_resolving
316 #test_remark_add "Undocumented command line option: G"
317 #test_remark_add "Options currently unchecked: S, V, l, n, p, q and x"
321 # Editor modelines - http://www.wireshark.org/tools/modelines.html
323 # Local variables:
324 # c-basic-offset: 8
325 # tab-width: 8
326 # indent-tabs-mode: t
327 # End:
329 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
330 # :indentSize=8:tabSize=8:noTabs=false: