3 # Test the command line options of the Wireshark tools
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
31 # generic: check against a specific exit status with a single char option
32 # $1 command: tshark or dumpcap
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
40 if [ ! $RETURNVALUE -eq $3 ]; then
41 test_step_failed
"exit status: $RETURNVALUE"
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"
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
67 clopts_suite_dumpcap_valid_chars
() {
70 test_step_add
"Valid dumpcap parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $DUMPCAP $index $EXIT_OK"
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
() {
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"
82 test_step_add
"Invalid permissions for dumpcap parameter -$index, exit status must be $EXIT_ERROR" "test_single_char_options $DUMPCAP $index $EXIT_ERROR"
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
94 $DUMPCAP -f 'jkghg' -w './testout.pcap' > .
/testout.txt
2>&1
96 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
97 test_step_failed
"exit status: $RETURNVALUE"
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
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
114 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
115 test_step_failed
"exit status: $RETURNVALUE"
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
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
133 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
134 test_step_failed
"exit status: $RETURNVALUE"
136 grep -i 'There is no interface with that adapter index' .
/testout.txt
> /dev
/null
137 if [ $?
-eq 0 ]; then
140 test_step_output_print .
/testout.txt
141 test_step_failed
"Error message wasn't what we expected"
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
152 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
153 test_step_failed
"exit status: $RETURNVALUE"
161 # check exit status when reading a non-existing file
162 clopts_step_nonexisting_file
() {
163 $TSHARK -r ThisFileDontExist.pcap
> .
/testout.txt
2>&1
165 if [ ! $RETURNVALUE -eq $EXIT_ERROR ]; then
166 test_step_failed
"exit status: $RETURNVALUE"
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"
183 # check exit status of all valid single char TShark options being (must be 0)
184 clopts_suite_tshark_valid_chars
() {
187 test_step_add
"Valid TShark parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TSHARK $index $EXIT_OK"
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
() {
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"
199 test_step_add
"Invalid permissions for TShark parameter -$index, exit status must be $EXIT_ERROR" "test_single_char_options $TSHARK $index $EXIT_ERROR"
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
213 $TSHARK -f 'jkghg' -w './testout.pcap' > .
/testout.txt
2>&1
215 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
216 test_step_failed
"exit status: $RETURNVALUE"
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
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
233 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
234 test_step_failed
"exit status: $RETURNVALUE"
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
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
252 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
253 test_step_failed
"exit status: $RETURNVALUE"
255 grep -i 'There is no interface with that adapter index' .
/testout.txt
> /dev
/null
256 if [ $?
-eq 0 ]; then
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
273 $TSHARK -N mntC
-a duration
:1 > .
/testout.txt
2>&1
275 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
276 test_step_failed
"exit status: $RETURNVALUE"
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
301 rm -f .
/testout.txt .
/testout2.txt
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
326 # indent-tabs-mode: t
329 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
330 # :indentSize=8:tabSize=8:noTabs=false: