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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 # common exit status values
31 # generic: check against a specific exit status with a single char option
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"
49 # check exit status when reading an existing file
50 clopts_step_existing_file() {
51 $TSHARK -r $CAPFILE > ./testout.txt 2>&1
53 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
54 test_step_failed "exit status: $RETURNVALUE"
62 # check exit status when reading a non-existing file
63 clopts_step_nonexisting_file() {
64 $TSHARK -r ThisFileDontExist.pcap > ./testout.txt 2>&1
66 if [ ! $RETURNVALUE -eq $EXIT_ERROR ]; then
67 test_step_failed "exit status: $RETURNVALUE"
75 # check exit status of all single char option being invalid
76 clopts_suite_tshark_invalid_chars() {
77 for index in A B C E F H J K M N O Q R T U W X Y Z a b c d e f g i j k m o r s t u w y z
79 test_step_add "Invalid TShark parameter -$index, exit status must be $EXIT_COMMAND_LINE" "test_single_char_options $TSHARK $index $EXIT_COMMAND_LINE"
84 # check exit status of all single char option being valid
85 clopts_suite_valid_chars() {
88 test_step_add "Valid TShark parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TSHARK $index $EXIT_OK"
92 # special case: interface-specific opts should work under Windows and fail as
93 # a regular user on other systems.
94 clopts_suite_interface_chars() {
97 if [ "$SKIP_CAPTURE" -eq 0 ] ; then
98 test_step_add "Valid TShark parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TSHARK $index $EXIT_OK"
100 test_step_add "Invalid permissions for TShark parameter -$index, exit status must be $EXIT_ERROR" "test_single_char_options $TSHARK $index $EXIT_ERROR"
107 # check exit status and grep output string of an invalid capture filter
108 clopts_step_invalid_capfilter() {
109 if [ "$WS_SYSTEM" != "Windows" ] ; then
114 $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
116 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
117 test_step_failed "exit status: $RETURNVALUE"
119 grep -i 'Invalid capture filter "jkghg" for interface' ./testout.txt > /dev/null
120 if [ $? -eq 0 ]; then
121 test_step_output_print ./testout.txt
124 test_step_output_print ./testout.txt
125 test_step_failed "Infos"
130 # check exit status and grep output string of an invalid interface
131 clopts_step_invalid_interface() {
132 $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
134 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
135 test_step_failed "exit status: $RETURNVALUE"
137 grep -i 'The capture session could not be initiated' ./testout.txt > /dev/null
138 if [ $? -eq 0 ]; then
139 test_step_output_print ./testout.txt
142 test_step_output_print ./testout.txt
143 test_step_failed "Infos"
148 # check exit status and grep output string of an invalid interface index
149 # (valid interface indexes start with 1)
150 clopts_step_invalid_interface_index() {
151 $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
153 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
154 test_step_failed "exit status: $RETURNVALUE"
156 grep -i 'there is no interface with that adapter index' ./testout.txt > /dev/null
157 if [ $? -eq 0 ]; then
160 test_step_output_print ./testout.txt
161 test_step_failed "Infos"
166 # check exit status and grep output string of an invalid capture filter
167 # XXX - how to efficiently test the *invalid* flags?
168 clopts_step_valid_name_resolving() {
169 if [ "$WS_SYSTEM" != "Windows" ] ; then
174 $TSHARK -N mntC -a duration:1 > ./testout.txt 2>&1
176 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
177 test_step_failed "exit status: $RETURNVALUE"
183 # check exit status of some basic functions
184 clopts_suite_basic() {
185 test_step_add "Exit status for existing file: \""$CAPFILE"\" must be 0" clopts_step_existing_file
186 test_step_add "Exit status for none existing files must be 2" clopts_step_nonexisting_file
189 clopts_suite_capture_options() {
190 test_step_add "Invalid capture filter -f" clopts_step_invalid_capfilter
191 test_step_add "Invalid capture interface -i" clopts_step_invalid_interface
192 test_step_add "Invalid capture interface index 0" clopts_step_invalid_interface_index
196 rm -f ./testout.txt ./testout2.txt
200 test_step_set_post clopts_post_step
201 test_suite_add "Basic tests" clopts_suite_basic
202 test_suite_add "Invalid TShark single char options" clopts_suite_tshark_invalid_chars
203 test_suite_add "Valid TShark single char options" clopts_suite_valid_chars
204 test_suite_add "Interface-specific TShark single char options" clopts_suite_interface_chars
205 test_suite_add "Capture filter/interface options tests" clopts_suite_capture_options
206 test_step_add "Valid name resolution options -N (1s)" clopts_step_valid_name_resolving
207 #test_remark_add "Undocumented command line option: G"
208 #test_remark_add "Options currently unchecked: S, V, l, n, p, q and x"
214 ## indent-tabs-mode: t
215 ## sh-basic-offset: 8