MSWSP: append to proto column instaed of overwriting it
[wireshark-wip.git] / test / test-backend.sh
blobf9173027aff6f703f91688403f719146af54f8ab
1 #!/bin/bash
3 # Test backend
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.
27 # References:
28 # http://www.gnu.org/software/bash/manual/bashref.html "Bash Reference Manual"
29 # http://www.tldp.org/LDP/abs/html/ "Advanced Bash-Scripting Guide"
30 # http://www.tldp.org/LDP/abs/html/colorizing.html "Colorizing" Scripts"
31 # http://www.junit.org/junit/javadoc/3.8.1/index.htm "JUnit javadoc"
33 # check undefined variables
34 # http://www.tldp.org/LDP/abs/html/options.html
35 # bash -u test.sh
37 # make sure that tput (part of ncurses) is installed
38 tput -V >/dev/null 2>/dev/null
39 if [ ! $? -eq 0 ]; then
40 USE_COLOR=0
43 # coloring the output
44 if [ $USE_COLOR -eq 1 ] ; then
45 color_reset="tput sgr0"
46 color_green='\e[32;40m'
47 color_red='\e[31;40m'
48 color_yellow='\e[33;40m'
49 color_blue='\e[36;40m'
50 else
51 color_reset="true"
52 color_green=''
53 color_red=''
54 color_yellow=''
55 color_blue=''
58 # runtime flags
59 TEST_RUN="OFF"
60 TEST_OUTPUT="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
62 # runtime vars
63 TEST_NESTING_LEVEL=0 # nesting level of current test
64 TEST_STEPS[0]=0 # number of steps of a specific nesting level
66 # output counters
67 TEST_OK=0 # global count of succeeded steps
68 TEST_FAILED=0 # global count of failed steps
69 TEST_SKIPPED=0 # global count of failed steps
71 TEST_STEP_PRE_CB=
72 TEST_STEP_POST_CB=
74 # level number of this test item (suite or step)
75 test_level() {
76 LIMIT_LEVEL=100
78 for ((a=0; a <= LIMIT_LEVEL ; a++))
80 if [ ! $a -eq 0 ]; then
81 echo -n "."
83 echo -n "${TEST_STEPS[a]}"
84 if [ $a -eq $TEST_NESTING_LEVEL ]; then
85 #echo "end"
86 return
88 done
91 # set output format
92 # $1 - "OUT", "DOTTED", "VERBOSE"
93 test_set_output() {
94 TEST_OUTPUT=$1
97 # run a test suite
98 # $1 name
99 # $2 command
100 test_suite_run() {
101 # header
102 echo -n -e $color_blue
103 echo ""
104 echo "### $1 ###"
105 $color_reset
107 TEST_RUN="ON"
109 # run the actual test suite
112 # results
113 if [ $TEST_RUN = "ON" ]; then
114 echo ""
115 if [ $TEST_FAILED -eq 0 ]; then
116 echo -n -e $color_green
117 else
118 echo -n -e $color_red
120 echo "### Test suite results ###"
121 echo -n -e $color_green
122 echo "OK : $TEST_OK"
123 echo -n -e $color_red
124 echo "Failed: $TEST_FAILED"
125 echo -n -e $color_yellow
126 echo "Skipped: $TEST_SKIPPED"
127 $color_reset
130 TEST_RUN="OFF"
132 # exit status
133 if [ $TEST_FAILED -eq 0 ]; then
134 return 0
135 else
136 return 1
141 # show a test suite
142 # $1 name
143 # $2 command
144 test_suite_show() {
146 # header
147 echo -n -e $color_blue
148 echo ""
149 echo "### Test suite: $1 ###"
150 echo ""
151 echo "Subitems:"
152 echo "---------"
153 $color_reset
155 # show this test suite subitems
158 echo ""
162 # add a test suite
163 # $1 name
164 # $2 function
165 test_suite_add() {
166 # increase step counter of this nesting level
167 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
169 if [ $TEST_RUN = "ON" ]; then
170 echo ""
173 # title output if we'll list the subitems
174 if [[ $TEST_RUN = "ON" ]]; then
175 echo -n -e $color_blue
176 test_level
177 echo " Suite: $1"
178 $color_reset
181 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
182 pos=${TEST_STEPS[$TEST_NESTING_LEVEL]}
183 #echo "pos " $pos
184 test_title[$pos]=$1
185 test_function[$pos]=$2
186 #echo ${test_title[1]}
190 # reset test step counter back to zero
191 TEST_STEP=0
193 # call the suites function
194 let "TEST_NESTING_LEVEL += 1"
195 TEST_STEPS[$TEST_NESTING_LEVEL]=0
197 let "TEST_NESTING_LEVEL -= 1"
199 # title output (with subitem counter) if we don't listed the subitems
200 if [[ ! $TEST_RUN = "ON" && $TEST_NESTING_LEVEL -eq 0 ]]; then
201 echo -n -e $color_blue
202 test_level
203 echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
204 $color_reset
209 # add a test step
210 # $1 name
211 # $2 function
212 test_step_add() {
214 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
216 if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
217 echo ""
220 if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
221 echo -n -e $color_blue
222 test_level
223 echo -n " Step:" $1
224 $color_reset
227 if [ $TEST_RUN = "ON" ]; then
228 # preprecessing step
229 $TEST_STEP_PRE_CB
230 #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
231 TEST_STEP_NAME=$1
232 # actually run the command to test now
234 #"$3" "$4" "$5" "$6" "$7"
235 # post precessing step
236 $TEST_STEP_POST_CB
237 else
238 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
239 echo ""
245 # set the preprocessing function
246 # $1 remark
247 test_step_set_pre() {
248 TEST_STEP_PRE_CB=$1
251 # set the post processing function
252 # $1 remark
253 test_step_set_post() {
254 TEST_STEP_POST_CB=$1
257 # add a test remark
258 # $1 remark
259 test_remark_add() {
261 # test is running or toplevel item? -> show remark
262 if [[ $TEST_RUN = "ON" || $TEST_NESTING_LEVEL -eq 0 ]]; then
263 # test is running and output is dotted -> newline first
264 if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
265 echo ""
268 # remark
269 echo -n -e $color_blue
270 echo " Remark: $1"
271 $color_reset
276 # the test step succeeded
277 test_step_ok() {
278 # count appearance
279 let "TEST_OK += 1"
281 # output in green
282 echo -n -e $color_green
284 if [ $TEST_OUTPUT = "VERBOSE" ]; then
285 echo " OK"
286 else
287 echo -n .
290 $color_reset
293 # the test step failed
294 # $1 output text
295 test_step_failed() {
296 let "TEST_FAILED += 1"
298 # output in red
299 echo -n -e "$color_red"
301 echo ""
302 echo "\"$TEST_STEP_NAME\" Failed!"
303 echo $1
305 $color_reset
307 exit 1
309 # XXX - add a mechanism to optionally stop here
312 # the test step skipped (usually not suitable for this machine/platform)
313 test_step_skipped() {
314 # count appearance
315 let "TEST_SKIPPED += 1"
317 # output in green
318 echo -n -e $color_yellow
320 if [ $TEST_OUTPUT = "VERBOSE" ]; then
321 echo " Skipped"
322 else
323 echo -n .
326 $color_reset
329 test_step_output_print() {
330 wait
331 printf "\n"
332 for f in "$@"; do
333 if [[ -f "$f" ]]; then
334 printf " --> $f\n"
335 cat "$f"
336 printf " <--\n"
337 else
338 printf " --> $f: doesn't exist (or isn't a file)\n"
340 done
344 # Editor modelines - http://www.wireshark.org/tools/modelines.html
346 # Local variables:
347 # c-basic-offset: 8
348 # tab-width: 8
349 # indent-tabs-mode: t
350 # End:
352 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
353 # :indentSize=8:tabSize=8:noTabs=false: