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.
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
39 if [ $USE_COLOR -eq 1 ] ; then
40 color_reset="tput sgr0"
41 color_green='\E[32;40m'
43 color_yellow='\E[33;40m'
44 color_blue='\E[36;40m'
46 color_reset="/bin/true"
55 TEST_OUTPUT="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
58 TEST_NESTING_LEVEL=0 # nesting level of current test
59 TEST_STEPS[0]=0 # number of steps of a specific nesting level
62 TEST_OK=0 # global count of succeeded steps
63 TEST_FAILED=0 # global count of failed steps
64 TEST_SKIPPED=0 # global count of failed steps
69 # level number of this test item (suite or step)
73 for ((a=0; a <= LIMIT_LEVEL ; a++))
75 if [ ! $a -eq 0 ]; then
78 echo -n "${TEST_STEPS[a]}"
79 if [ $a -eq $TEST_NESTING_LEVEL ]; then
87 # $1 - "OUT", "DOTTED", "VERBOSE"
97 echo -n -e $color_blue
104 # run the actual test suite
108 if [ $TEST_RUN = "ON" ]; then
110 if [ $TEST_FAILED -eq 0 ]; then
111 echo -n -e $color_green
113 echo -n -e $color_red
115 echo "### Test suite results ###"
116 echo -n -e $color_green
118 echo -n -e $color_red
119 echo "Failed: $TEST_FAILED"
120 echo -n -e $color_yellow
121 echo "Skipped: $TEST_SKIPPED"
128 if [ $TEST_FAILED -eq 0 ]; then
142 echo -n -e $color_blue
144 echo "### Test suite: $1 ###"
150 # show this test suite subitems
161 # increase step counter of this nesting level
162 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
164 if [ $TEST_RUN = "ON" ]; then
168 # title output if we'll list the subitems
169 if [[ $TEST_RUN = "ON" ]]; then
170 echo -n -e $color_blue
176 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
177 pos=${TEST_STEPS[$TEST_NESTING_LEVEL]}
180 test_function[$pos]=$2
181 #echo ${test_title[1]}
185 # reset test step counter back to zero
188 # call the suites function
189 let "TEST_NESTING_LEVEL += 1"
190 TEST_STEPS[$TEST_NESTING_LEVEL]=0
192 let "TEST_NESTING_LEVEL -= 1"
194 # title output (with subitem counter) if we don't listed the subitems
195 if [[ ! $TEST_RUN = "ON" && $TEST_NESTING_LEVEL -eq 0 ]]; then
196 echo -n -e $color_blue
198 echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
210 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
212 if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
216 if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
217 echo -n -e $color_blue
223 if [ $TEST_RUN = "ON" ]; then
226 #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
228 # actually run the command to test now
230 #"$3" "$4" "$5" "$6" "$7"
231 # post precessing step
234 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
241 # set the preprocessing function
243 test_step_set_pre() {
247 # set the post processing function
249 test_step_set_post() {
257 # test is running or toplevel item? -> show remark
258 if [[ $TEST_RUN = "ON" || $TEST_NESTING_LEVEL -eq 0 ]]; then
259 # test is running and output is dotted -> newline first
260 if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
265 echo -n -e $color_blue
272 # the test step succeeded
278 echo -n -e $color_green
280 if [ $TEST_OUTPUT = "VERBOSE" ]; then
289 # the test step failed
292 let "TEST_FAILED += 1"
295 echo -n -e "$color_red"
298 echo "\"$TEST_STEP_NAME\" Failed!"
305 # XXX - add a mechanism to optionally stop here
308 # the test step skipped (usually not suitable for this machine/platform)
309 test_step_skipped() {
311 let "TEST_SKIPPED += 1"
314 echo -n -e $color_yellow
316 if [ $TEST_OUTPUT = "VERBOSE" ]; then
325 test_step_output_print() {
329 if [[ -f "$f" ]]; then
334 printf " --> $f: doesn't exist (or isn't a file)\n"
342 ## indent-tabs-mode: t
343 ## sh-basic-offset: 8