Whitespace changes: Convert spaces to tabs. Add modelines.
[metze/wireshark/wip.git] / test / suite-io.sh
1 #!/bin/bash
2 #
3 # Test the file I/O of the Wireshark tools
4 #
5 # $Id$
6 #
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
10 #
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.
15 #
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.
20 #
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.
24 #
25
26
27 # common exit status values
28 EXIT_OK=0
29 EXIT_COMMAND_LINE=1
30 EXIT_ERROR=2
31
32
33 # input of file
34 io_step_input_file() {
35         $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
36         RETURNVALUE=$?
37         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
38                 test_step_failed "exit status of $DUT: $RETURNVALUE"
39                 # part of the Prerequisite checks
40                 # probably wrong interface, output the possible interfaces
41                 $TSHARK -D
42                 return
43         fi
44
45         # we should have an output file now
46         if [ ! -f "./testout.pcap" ]; then
47                 test_step_failed "No output file!"
48                 return
49         fi
50
51         # ok, we got a capture file, does it contain exactly 10 packets?
52         $CAPINFOS ./testout.pcap > ./testout.txt
53         grep -Ei 'Number of packets:[[:blank:]]+4' ./testout.txt > /dev/null
54         if [ $? -eq 0 ]; then
55                 test_step_ok
56         else
57                 echo
58                 cat ./testout.txt
59                 # part of the Prerequisite checks
60                 # probably wrong interface, output the possible interfaces
61                 $TSHARK -D
62                 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
63         fi
64 }
65
66 # piping input file to stdout using "-w -"
67 io_step_output_piping() {
68         $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
69         RETURNVALUE=$?
70         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
71                 test_step_failed "exit status of $DUT: $RETURNVALUE"
72                 $TSHARK -D
73                 return
74         fi
75
76         # we should have an output file now
77         if [ ! -f "./testout.pcap" ]; then
78                 test_step_failed "No output file!"
79                 return
80         fi
81
82         # ok, we got a capture file, does it contain exactly 10 packets?
83         $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
84         grep -Ei 'Number of packets:[[:blank:]]+4' ./testout2.txt > /dev/null
85         if [ $? -eq 0 ]; then
86                 test_step_ok
87         else
88                 echo
89                 cat ./testout.txt
90                 cat ./testout2.txt
91                 $TSHARK -D
92                 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
93         fi
94 }
95
96 # piping input file to stdout using "-w -"
97 io_step_input_piping() {
98         cat -B "${CAPTURE_DIR}dhcp.pcap" | $DUT -r - -w ./testout.pcap 2>./testout.txt
99         RETURNVALUE=$?
100         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
101                 $TSHARK -D
102                 echo
103                 cat ./testout.txt
104                 test_step_failed "exit status of $DUT: $RETURNVALUE"
105                 return
106         fi
107
108         # we should have an output file now
109         if [ ! -f "./testout.pcap" ]; then
110                 test_step_failed "No output file!"
111                 return
112         fi
113
114         # ok, we got a capture file, does it contain exactly 10 packets?
115         $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
116         grep -Ei 'Number of packets:[[:blank:]]+4' ./testout2.txt > /dev/null
117         if [ $? -eq 0 ]; then
118                 test_step_ok
119         else
120                 echo
121                 cat ./testout.txt
122                 cat ./testout2.txt
123                 $TSHARK -D
124                 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
125         fi
126 }
127
128 wireshark_io_suite() {
129         # Q: quit after cap, k: start capture immediately
130         DUT="$WIRESHARK"
131         test_step_add "Input file" io_step_input_file
132 }
133
134 tshark_io_suite() {
135         DUT=$TSHARK
136         test_step_add "Input file" io_step_input_file
137         test_step_add "Output piping" io_step_output_piping
138         #test_step_add "Piping" io_step_input_piping
139 }
140
141 dumpcap_io_suite() {
142         #DUT="$DUMPCAP -Q"
143         DUT=$DUMPCAP
144
145         test_step_add "Input file" io_step_input_file
146 }
147
148 io_cleanup_step() {
149         rm -f ./testout.txt
150         rm -f ./testout2.txt
151         rm -f ./testout.pcap
152         rm -f ./testout2.pcap
153 }
154
155 io_suite() {
156         test_step_set_pre io_cleanup_step
157         test_step_set_post io_cleanup_step
158         test_suite_add "TShark file I/O" tshark_io_suite
159         #test_suite_add "Wireshark file I/O" wireshark_io_suite
160         #test_suite_add "Dumpcap file I/O" dumpcap_io_suite
161 }
162 #
163 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
164 #
165 # Local variables:
166 # c-basic-offset: 8
167 # tab-width: 8
168 # indent-tabs-mode: t
169 # End:
170 #
171 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
172 # :indentSize=8:tabSize=8:noTabs=false:
173 #