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.
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
37 # make sure that tput (part of ncurses) is installed
38 tput -V >/dev
/null
2>/dev
/null
39 if [ ! $?
-eq 0 ]; then
44 if [ $USE_COLOR -eq 1 ] ; then
45 color_reset
="tput sgr0"
46 color_green
='\e[32;40m'
48 color_yellow
='\e[33;40m'
49 color_blue
='\e[36;40m'
60 TEST_OUTPUT
="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
63 TEST_NESTING_LEVEL
=0 # nesting level of current test
64 TEST_STEPS
[0]=0 # number of steps of a specific nesting level
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
74 # level number of this test item (suite or step)
78 for ((a
=0; a
<= LIMIT_LEVEL
; a
++))
80 if [ ! $a -eq 0 ]; then
83 echo -n "${TEST_STEPS[a]}"
84 if [ $a -eq $TEST_NESTING_LEVEL ]; then
92 # $1 - "OUT", "DOTTED", "VERBOSE"
102 echo -n -e $color_blue
109 # run the actual test suite
113 if [ $TEST_RUN = "ON" ]; then
115 if [ $TEST_FAILED -eq 0 ]; then
116 echo -n -e $color_green
118 echo -n -e $color_red
120 echo "### Test suite results ###"
121 echo -n -e $color_green
123 echo -n -e $color_red
124 echo "Failed: $TEST_FAILED"
125 echo -n -e $color_yellow
126 echo "Skipped: $TEST_SKIPPED"
133 if [ $TEST_FAILED -eq 0 ]; then
147 echo -n -e $color_blue
149 echo "### Test suite: $1 ###"
155 # show this test suite subitems
166 # increase step counter of this nesting level
167 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
169 if [ $TEST_RUN = "ON" ]; then
173 # title output if we'll list the subitems
174 if [[ $TEST_RUN = "ON" ]]; then
175 echo -n -e $color_blue
181 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
182 pos
=${TEST_STEPS[$TEST_NESTING_LEVEL]}
185 test_function
[$pos]=$2
186 #echo ${test_title[1]}
190 # reset test step counter back to zero
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
203 echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
214 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
216 if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
220 if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) ||
$TEST_NESTING_LEVEL -eq 0 ]]; then
221 echo -n -e $color_blue
227 if [ $TEST_RUN = "ON" ]; then
230 #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
232 # actually run the command to test now
234 #"$3" "$4" "$5" "$6" "$7"
235 # post precessing step
238 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
245 # set the preprocessing function
247 test_step_set_pre
() {
251 # set the post processing function
253 test_step_set_post
() {
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
269 echo -n -e $color_blue
276 # the test step succeeded
282 echo -n -e $color_green
284 if [ $TEST_OUTPUT = "VERBOSE" ]; then
293 # the test step failed
296 let "TEST_FAILED += 1"
299 echo -n -e "$color_red"
302 echo "\"$TEST_STEP_NAME\" Failed!"
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
() {
315 let "TEST_SKIPPED += 1"
318 echo -n -e $color_yellow
320 if [ $TEST_OUTPUT = "VERBOSE" ]; then
329 test_step_output_print
() {
333 if [[ -f "$f" ]]; then
338 printf " --> $f: doesn't exist (or isn't a file)\n"
344 # Editor modelines - http://www.wireshark.org/tools/modelines.html
349 # indent-tabs-mode: t
352 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
353 # :indentSize=8:tabSize=8:noTabs=false: