5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 2005 Ulf Lamping
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 # http://www.gnu.org/software/bash/manual/bashref.html "Bash Reference Manual"
27 # http://www.tldp.org/LDP/abs/html/ "Advanced Bash-Scripting Guide"
28 # http://www.tldp.org/LDP/abs/html/colorizing.html "Colorizing" Scripts"
29 # http://www.junit.org/junit/javadoc/3.8.1/index.htm "JUnit javadoc"
31 # check undefined variables
32 # http://www.tldp.org/LDP/abs/html/options.html
35 # make sure that tput (part of ncurses) is installed
36 tput -V >/dev/null 2>/dev/null
37 if [ ! $? -eq 0 ]; then
42 if [ $USE_COLOR -eq 1 ] ; then
43 color_reset="tput sgr0"
44 color_green='
\e[32;40m'
46 color_yellow='
\e[33;40m'
47 color_blue='
\e[36;40m'
58 TEST_OUTPUT="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
61 TEST_NESTING_LEVEL=0 # nesting level of current test
62 TEST_STEPS[0]=0 # number of steps of a specific nesting level
65 TEST_OK=0 # global count of succeeded steps
66 TEST_FAILED=0 # global count of failed steps
67 TEST_SKIPPED=0 # global count of failed steps
72 # level number of this test item (suite or step)
76 for ((a=0; a <= LIMIT_LEVEL ; a++))
78 if [ ! $a -eq 0 ]; then
81 echo -n "${TEST_STEPS[a]}"
82 if [ $a -eq $TEST_NESTING_LEVEL ]; then
90 # $1 - "OUT", "DOTTED", "VERBOSE"
100 echo -n -e $color_blue
107 # run the actual test suite
111 if [ $TEST_RUN = "ON" ]; then
113 if [ $TEST_FAILED -eq 0 ]; then
114 echo -n -e $color_green
116 echo -n -e $color_red
118 echo "### Test suite results ###"
119 echo -n -e $color_green
121 echo -n -e $color_red
122 echo "Failed: $TEST_FAILED"
123 echo -n -e $color_yellow
124 echo "Skipped: $TEST_SKIPPED"
131 if [ $TEST_FAILED -eq 0 ]; then
145 echo -n -e $color_blue
147 echo "### Test suite: $1 ###"
153 # show this test suite subitems
164 # increase step counter of this nesting level
165 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
167 if [ $TEST_RUN = "ON" ]; then
171 # title output if we'll list the subitems
172 if [[ $TEST_RUN = "ON" ]]; then
173 echo -n -e $color_blue
179 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
180 pos=${TEST_STEPS[$TEST_NESTING_LEVEL]}
183 test_function[$pos]=$2
184 #echo ${test_title[1]}
188 # reset test step counter back to zero
191 # call the suites function
192 let "TEST_NESTING_LEVEL += 1"
193 TEST_STEPS[$TEST_NESTING_LEVEL]=0
195 let "TEST_NESTING_LEVEL -= 1"
197 # title output (with subitem counter) if we don't listed the subitems
198 if [[ ! $TEST_RUN = "ON" && $TEST_NESTING_LEVEL -eq 0 ]]; then
199 echo -n -e $color_blue
201 echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
212 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
214 if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
218 if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
219 echo -n -e $color_blue
225 if [ $TEST_RUN = "ON" ]; then
228 #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
230 # actually run the command to test now
232 #"$3" "$4" "$5" "$6" "$7"
233 # post precessing step
236 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
243 # set the preprocessing function
245 test_step_set_pre() {
249 # set the post processing function
251 test_step_set_post() {
259 # test is running or toplevel item? -> show remark
260 if [[ $TEST_RUN = "ON" || $TEST_NESTING_LEVEL -eq 0 ]]; then
261 # test is running and output is dotted -> newline first
262 if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
267 echo -n -e $color_blue
274 # the test step succeeded
280 echo -n -e $color_green
282 if [ $TEST_OUTPUT = "VERBOSE" ]; then
291 # the test step failed
294 let "TEST_FAILED += 1"
297 echo -n -e "$color_red"
300 echo "\"$TEST_STEP_NAME\" Failed!"
307 # XXX - add a mechanism to optionally stop here
310 # the test step skipped (usually not suitable for this machine/platform)
311 test_step_skipped() {
313 let "TEST_SKIPPED += 1"
316 echo -n -e $color_yellow
318 if [ $TEST_OUTPUT = "VERBOSE" ]; then
327 test_step_output_print() {
331 if [[ -f "$f" ]]; then
336 printf " --> $f: doesn't exist (or isn't a file)\n"
342 # Editor modelines - http://www.wireshark.org/tools/modelines.html
347 # indent-tabs-mode: t
350 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
351 # :indentSize=8:tabSize=8:noTabs=false: