aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2005-12-13 23:15:20 +0000
committerUlf Lamping <ulf.lamping@web.de>2005-12-13 23:15:20 +0000
commit0922a2b922646a831c9ff3c6d8f8b43700ef6edc (patch)
treebd8e7343f1749d610fa756b75bd7c3dfd44d3596 /test
parent79217bab2ebb0d2811e130bea6334c8227a88a28 (diff)
add a new directory 'test', currently containing an alpha test (using some simple bash scripts) of the ethereal/tethereal command line parameters. See the file README.test for details.
svn path=/trunk/; revision=16788
Diffstat (limited to 'test')
-rw-r--r--test/README.test57
-rw-r--r--test/config.sh42
-rw-r--r--test/dhcp.pcapbin0 -> 1400 bytes
-rw-r--r--test/suite-capture.sh193
-rw-r--r--test/suite-clopts.sh164
-rw-r--r--test/test-backend.sh285
-rw-r--r--test/test.sh138
7 files changed, 879 insertions, 0 deletions
diff --git a/test/README.test b/test/README.test
new file mode 100644
index 0000000000..7734036256
--- /dev/null
+++ b/test/README.test
@@ -0,0 +1,57 @@
+$Id$
+
+WARNING: these tests are in alpha state!
+
+What is it?
+-----------
+This is basically a collection of bash scripts to test the command line options of:
+
+ - Ethereal
+ - Tethereal
+ - Dumpcap
+
+Motivation
+----------
+
+The command line options of Ethereal and the companion command line tools are
+numerous. This makes it hard to find newly introduced bugs doing manual testing
+(try and error) with source code changes.
+
+The current way is to do some changes, testing some scenarios by hand and
+commit the code so other users will complain about new problems. This obviously
+is far from being optimal.
+
+Limitations
+-----------
+
+The test set currently provided will only do some basic tests, but even that
+is far better than nothing. This may involve in time as new tests can be added
+to fix problems reported by users. This will hopefully lead to a "complete"
+and reliable testset in the future.
+
+The tests are limited to command line tests, other things like unit tests or
+GUI test are not included.
+
+Prerequisites
+-------------
+
+What you'll need (to do):
+
+ - THE LATEST DEVELOPER BUILDS (the 0.10.13 release won't work)!
+ - obviously, compile the programs (ethereal, ...) to be tested
+ - have a bash (cygwin should do well)
+ - you'll need a network interface with some network traffic
+ (so you can run the capture tests)
+ - edit the file config.sh to suit your configuration
+
+A Test Ride
+-----------
+
+Start test.sh which should provide a basic menu. Just press Enter to start
+all tests.
+
+It should start all the available tests. Each test will throw out a line
+which should end with a green "Ok". If one of the tests fail, the script
+will report it and stop at this test step.
+
+PLEASE REMEMBER TO HAVE SOME TRAFFIC ON YOUR NETWORK INTERFACE!!!
diff --git a/test/config.sh b/test/config.sh
new file mode 100644
index 0000000000..fe0cf48b30
--- /dev/null
+++ b/test/config.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Configuration of the command line tests
+#
+# $Id$
+#
+# Ethereal - Network traffic analyzer
+# By Gerald Combs <gerald@ethereal.com>
+# Copyright 2005 Ulf Lamping
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+# path to the Ethereal binaries, only used for the settings below
+ETH_BIN_PATH=../Debug_GTK2
+
+# Tweak the following to your liking.
+ETHEREAL=$ETH_BIN_PATH/ethereal
+TETHEREAL=$ETH_BIN_PATH/tethereal
+CAPINFOS=$ETH_BIN_PATH/capinfos
+DUMPCAP=$ETH_BIN_PATH/dumpcap
+
+# interface with at least a few packets/sec traffic on it
+# (e.g. start a web radio to generate some traffic :-)
+# an interfaces index (1 based) should do well for recent devbuilds
+TRAFFIC_CAPTURE_IFACE=2
+
+# time to capture some traffic (in seconds)
+# (you may increase this if you get errors caused by very low traffic)
+TRAFFIC_CAPTURE_DURATION=3
diff --git a/test/dhcp.pcap b/test/dhcp.pcap
new file mode 100644
index 0000000000..a42d6102e8
--- /dev/null
+++ b/test/dhcp.pcap
Binary files differ
diff --git a/test/suite-capture.sh b/test/suite-capture.sh
new file mode 100644
index 0000000000..9d8f606d08
--- /dev/null
+++ b/test/suite-capture.sh
@@ -0,0 +1,193 @@
+#!/bin/bash
+#
+# Test the capture engine of the Ethereal tools
+#
+# $Id$
+#
+# Ethereal - Network traffic analyzer
+# By Gerald Combs <gerald@ethereal.com>
+# Copyright 2005 Ulf Lamping
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+
+# common exit status values
+EXIT_OK=0
+EXIT_COMMAND_LINE=1
+EXIT_ERROR=2
+
+
+# capture exactly 10 packets
+capture_step_10packets() {
+ $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -c 10 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ # part of the Prerequisite checks
+ # probably wrong interface, output the possible interfaces
+ $TETHEREAL -D
+ return
+ fi
+
+ # we should have an output file now
+ if [ ! -f "./testout.pcap" ]; then
+ test_step_failed "No output file!"
+ return
+ fi
+
+ # ok, we got a capture file, does it contain exactly 10 packets?
+ $CAPINFOS ./testout.pcap > ./testout.txt
+ grep -i 'Number of packets: 10' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "Probably the wrong interface (no traffic captured)!"
+ fi
+}
+
+# capture exactly 2 times 10 packets
+capture_step_2multi_10packets() {
+ $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -c 10 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ # part of the Prerequisite checks
+ # probably wrong interface, output the possible interfaces
+ $TETHEREAL -D
+ return
+ fi
+
+ # we should have an output file now
+ if [ ! -f "./testout.pcap" ]; then
+ test_step_failed "No output file!"
+ return
+ fi
+
+ # ok, we got a capture file, does it contain exactly 10 packets?
+ $CAPINFOS ./testout.pcap > ./testout.txt
+ grep -i 'Number of packets: 10' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "Probably the wrong interface (no traffic captured)!"
+ fi
+}
+
+# capture with a very unlikely read filter, packets must be zero afterwards
+capture_step_read_filter() {
+ # valid, but very unlikely filter
+ $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -a duration:$TRAFFIC_CAPTURE_DURATION -R 'dcerpc.cn_call_id==123456' -c 10 > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ return
+ fi
+
+ # we should have an output file now
+ if [ ! -f "./testout.pcap" ]; then
+ test_step_failed "No output file!"
+ return
+ fi
+
+ # ok, we got a capture file, does it contain exactly 0 packets?
+ $CAPINFOS ./testout.pcap > ./testout.txt
+ grep -i 'Number of packets: 0' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "Capture file should contain zero packets!"
+ fi
+}
+
+
+# capture with a snapshot length
+capture_step_snapshot() {
+ # capture with a snapshot length of 68 bytes for $TRAFFIC_CAPTURE_DURATION seconds
+ # this should result in no packets
+ $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -s 68 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ return
+ fi
+
+ # we should have an output file now
+ if [ ! -f "./testout.pcap" ]; then
+ test_step_failed "No output file!"
+ return
+ fi
+
+ # use tethereal to filter out all packets, which are larger than 68 bytes
+ $TETHEREAL -r ./testout.pcap -w ./testout2.pcap -R 'frame.cap_len>68' > ./testout.txt 2>&1
+
+ # ok, we got a capture file, does it contain exactly 0 packets?
+ $CAPINFOS ./testout2.pcap > ./testout.txt
+ grep -i 'Number of packets: 0' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "Capture file should contain zero packets!"
+ return
+ fi
+}
+
+ethereal_capture_suite() {
+ # Q: quit after cap, k: start capture immediately
+ DUT="$ETHEREAL -Q -k"
+ test_step_add "Capture 10 packets" capture_step_10packets
+ # read filter doesn't work with Ethereal and capturing!
+ #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
+ # the snapshot length test is also based on the read filters
+ test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
+}
+
+tethereal_capture_suite() {
+ DUT=$TETHEREAL
+ test_step_add "Capture 10 packets" capture_step_10packets
+ test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
+ test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
+}
+
+dumpcap_capture_suite() {
+ #DUT="$DUMPCAP -Q"
+ DUT=$DUMPCAP
+ test_step_add "Capture 10 packets" capture_step_10packets
+ # read filter doesn't work with dumpcap!
+ #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
+ test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
+}
+
+capture_post_step() {
+ rm -f ./testout.txt
+ rm -f ./testout.pcap
+ rm -f ./testout2.pcap
+}
+
+capture_suite() {
+ test_step_set_post capture_post_step
+ test_remark_add "Capture - need some traffic on: \"$TRAFFIC_CAPTURE_IFACE\""
+ test_suite_add "Tethereal capture" tethereal_capture_suite
+ test_suite_add "Ethereal capture" ethereal_capture_suite
+ test_suite_add "Dumpcap capture" dumpcap_capture_suite
+}
diff --git a/test/suite-clopts.sh b/test/suite-clopts.sh
new file mode 100644
index 0000000000..2c5833dd56
--- /dev/null
+++ b/test/suite-clopts.sh
@@ -0,0 +1,164 @@
+#!/bin/bash
+#
+# Test the command line options of the Ethereal tools
+#
+# $Id$
+#
+# Ethereal - Network traffic analyzer
+# By Gerald Combs <gerald@ethereal.com>
+# Copyright 2005 Ulf Lamping
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+# common exit status values
+EXIT_OK=0
+EXIT_COMMAND_LINE=1
+EXIT_ERROR=2
+
+
+# generic: check against a specific exit status with a single char option
+# $1 command: tethereal
+# $2 option: a
+# $3 expected exit status: 0
+test_single_char_options()
+{
+ #echo "command: "$1" opt1: "$2" opt2: "$3" opt3: "$4" opt4: "$5" opt5: "$6
+ $1 -$2 > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $3 ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ test_step_ok
+ fi
+ rm ./testout.txt
+}
+
+
+# check exit status when reading an existing file
+clopts_step_existing_file() {
+ $TETHEREAL -r $CAPFILE > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ test_step_ok
+ fi
+ rm ./testout.txt
+}
+
+
+# check exit status when reading a none existing file
+clopts_step_nonexisting_file() {
+ $TETHEREAL -r ThisFileDontExist.pcap > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_ERROR ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ test_step_ok
+ fi
+ rm ./testout.txt
+}
+
+
+# check exit status of all single char option being invalid
+clopts_suite_tethereal_invalid_chars() {
+ for index in A B C E F H I J K M N O P Q R T U W X Y Z a b c d e f g i j k m o r s t u w y z
+ do
+ test_step_add "Invalid Tethereal parameter -$index, exit status must be $EXIT_COMMAND_LINE" "test_single_char_options $TETHEREAL $index $EXIT_COMMAND_LINE"
+ done
+}
+
+
+# check exit status of all single char option being valid
+clopts_suite_valid_chars() {
+ for index in D G L h v
+ do
+ test_step_add "Valid Tethereal parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TETHEREAL $index $EXIT_OK"
+ done
+}
+
+
+# S V l n p q x
+
+# check exit status and grep output string of an invalid capture filter
+clopts_step_invalid_capfilter() {
+ $TETHEREAL -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ grep -i 'Invalid capture filter: "jkghg"' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ cat ./testout.txt
+ test_step_failed "Infos"
+ fi
+ fi
+}
+
+# check exit status and grep output string of an invalid capture filter
+clopts_step_invalid_interface() {
+ $TETHEREAL -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ grep -i 'The capture session could not be initiated!' ./testout.txt > /dev/null
+ if [ $? -eq 0 ]; then
+ test_step_ok
+ else
+ cat ./testout.txt
+ test_step_failed "Infos"
+ fi
+ fi
+}
+
+# check exit status and grep output string of an invalid capture filter
+# XXX - how to efficiently test the *invalid* flags?
+clopts_step_valid_name_resolving() {
+ $TETHEREAL -N mntC -a duration:1 > ./testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ test_step_failed "exit status: $RETURNVALUE"
+ else
+ test_step_ok
+ fi
+}
+
+# check exit status of some basic functions
+clopts_suite_basic() {
+ test_step_add "Exit status for existing file: \""$CAPFILE"\" must be 0" clopts_step_existing_file
+ test_step_add "Exit status for none existing files must be 2" clopts_step_nonexisting_file
+}
+
+
+clopts_post_step() {
+ rm -f ./testout.txt
+}
+
+clopt_suite() {
+ test_step_set_post clopts_post_step
+ test_suite_add "Basic tests" clopts_suite_basic
+ test_suite_add "Invalid Tethereal single char options" clopts_suite_tethereal_invalid_chars
+ test_suite_add "Valid Tethereal single char options" clopts_suite_valid_chars
+ test_step_add "Invalid capture filter -f" clopts_step_invalid_capfilter
+ test_step_add "Invalid capture interface -i" clopts_step_invalid_interface
+ test_step_add "Valid name resolution options -N (1s)" clopts_step_valid_name_resolving
+ #test_remark_add "Undocumented command line option: G"
+ #test_remark_add "Options currently unchecked: S, V, l, n, p, q and x"
+}
+
diff --git a/test/test-backend.sh b/test/test-backend.sh
new file mode 100644
index 0000000000..66dccc5176
--- /dev/null
+++ b/test/test-backend.sh
@@ -0,0 +1,285 @@
+#!/bin/bash
+#
+# Test backend
+#
+# $Id$
+#
+# Ethereal - Network traffic analyzer
+# By Gerald Combs <gerald@ethereal.com>
+# Copyright 2005 Ulf Lamping
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+
+# References:
+# http://www.gnu.org/software/bash/manual/bashref.html "Bash Reference Manual"
+# http://www.tldp.org/LDP/abs/html/ "Advanced Bash-Scripting Guide"
+# http://www.tldp.org/LDP/abs/html/colorizing.html "Colorizing" Scripts"
+# http://www.junit.org/junit/javadoc/3.8.1/index.htm "JUnit javadoc"
+
+# check undefined variables
+# http://www.tldp.org/LDP/abs/html/options.html
+# bash -u test.sh
+
+
+# coloring the output
+color_reset="tput sgr0"
+color_green='\E[32;40m'
+color_red='\E[31;40m'
+color_blue='\E[36;40m'
+
+# runtime flags
+TEST_RUN="OFF"
+TEST_OUTPUT="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
+
+# runtime vars
+TEST_NESTING_LEVEL=0 # nesting level of current test
+TEST_STEPS[0]=0 # number of steps of a specific nesting level
+
+# output counters
+TEST_OK=0 # global count of succeeded steps
+TEST_FAILED=0 # global count of failed steps
+
+TEST_STEP_POST_CB=
+
+# level number of this test item (suite or step)
+test_level() {
+ LIMIT=100
+
+ for ((a=0; a <= LIMIT ; a++))
+ do
+ if [ ! $a -eq 0 ]; then
+ echo -n "."
+ fi
+ echo -n "${TEST_STEPS[a]}"
+ if [ $a -eq $TEST_NESTING_LEVEL ]; then
+ #echo "end"
+ return
+ fi
+ done
+}
+
+# set output format
+# $1 - "OUT", "DOTTED", "VERBOSE"
+test_set_output() {
+ TEST_OUTPUT=$1
+}
+
+# run a test suite
+# $1 name
+# $2 command
+test_suite_run() {
+ # header
+ echo -n -e $color_blue
+ echo ""
+ echo "### $1 ###"
+ $color_reset
+
+ TEST_RUN="ON"
+
+ # run the actual test suite
+ $2
+
+ # results
+ if [ $TEST_RUN = "ON" ]; then
+ echo ""
+ if [ $TEST_FAILED -eq 0 ]; then
+ echo -n -e $color_green
+ else
+ echo -n -e $color_red
+ fi
+ echo "### Test suite results ###"
+ echo -n -e $color_green
+ echo "Ok : $TEST_OK"
+ echo -n -e $color_red
+ echo "Failed: $TEST_FAILED"
+ $color_reset
+ fi
+
+ # exit status
+ #if [ $TEST_FAILED -eq 0 ]; then
+ # exit 0
+ #else
+ # exit 1
+ #fi
+
+ TEST_RUN="OFF"
+}
+
+
+# show a test suite
+# $1 name
+# $2 command
+test_suite_show() {
+
+ # header
+ echo -n -e $color_blue
+ echo ""
+ echo "### Test suite: $1 ###"
+ echo ""
+ echo "Subitems:"
+ echo "---------"
+ $color_reset
+
+ # show this test suite subitems
+ $2
+
+ echo ""
+}
+
+
+# add a test suite
+# $1 name
+# $2 function
+test_suite_add() {
+ # increase step counter of this nesting level
+ let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
+
+ if [ $TEST_RUN = "ON" ]; then
+ echo ""
+ fi
+
+ # title output if we'll list the subitems
+ if [[ $TEST_RUN = "ON" ]]; then
+ echo -n -e $color_blue
+ test_level
+ echo " Suite: $1"
+ $color_reset
+ fi
+
+ if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
+ pos=${TEST_STEPS[$TEST_NESTING_LEVEL]}
+ #echo "pos " $pos
+ test_title[$pos]=$1
+ test_function[$pos]=$2
+ #echo ${test_title[1]}
+
+ fi
+
+ # reset test step counter back to zero
+ TEST_STEP=0
+
+ # call the suites function
+ let "TEST_NESTING_LEVEL += 1"
+ TEST_STEPS[$TEST_NESTING_LEVEL]=0
+ $2
+ let "TEST_NESTING_LEVEL -= 1"
+
+ # title output (with subitem counter) if we don't listed the subitems
+ if [[ ! $TEST_RUN = "ON" && $TEST_NESTING_LEVEL -eq 0 ]]; then
+ echo -n -e $color_blue
+ test_level
+ echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
+ $color_reset
+ fi
+
+}
+
+
+# add a test step
+# $1 name
+# $2 function
+test_step_add() {
+
+ let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
+
+ if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
+ echo ""
+ fi
+
+ if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
+ echo -n -e $color_blue
+ test_level
+ echo -n " Step:" $1
+ $color_reset
+ fi
+
+ if [ $TEST_RUN = "ON" ]; then
+ #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
+ TEST_STEP_NAME=$1
+ # actually run the command to test now
+ $2
+ #"$3" "$4" "$5" "$6" "$7"
+ $TEST_STEP_POST_CB
+ else
+ if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
+ echo ""
+ fi
+ fi
+}
+
+
+# set the a post processing function
+# $1 remark
+test_step_set_post() {
+ TEST_STEP_POST_CB=$1
+}
+
+# add a test remark
+# $1 remark
+test_remark_add() {
+
+ # test is running or toplevel item? -> show remark
+ if [[ $TEST_RUN = "ON" || $TEST_NESTING_LEVEL -eq 0 ]]; then
+ # test is running and output is dotted -> newline first
+ if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
+ echo ""
+ fi
+
+ # remark
+ echo -n -e $color_blue
+ echo " Remark: $1"
+ $color_reset
+ fi
+}
+
+
+# the test step succeeded
+test_step_ok() {
+ # count appearance
+ let "TEST_OK += 1"
+
+ # output in green
+ echo -n -e $color_green
+
+ if [ $TEST_OUTPUT = "VERBOSE" ]; then
+ echo " Ok"
+ else
+ echo -n .
+ fi
+
+ $color_reset
+}
+
+# the test step failed
+# $1 output text
+test_step_failed() {
+ let "TEST_FAILED += 1"
+
+ # output in red
+ echo -n -e "$color_red"
+
+ echo ""
+ echo "\"$TEST_STEP_NAME\" Failed!"
+ echo $1
+
+ $color_reset
+
+ exit 1
+
+ # XXX - add a mechanism to optionally stop here
+}
+
diff --git a/test/test.sh b/test/test.sh
new file mode 100644
index 0000000000..8e43a2fb0d
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,138 @@
+#!/bin/bash
+#
+# Test various command line testable aspects of the Ethereal tools
+#
+# $Id$
+#
+# Ethereal - Network traffic analyzer
+# By Gerald Combs <gerald@ethereal.com>
+# Copyright 2005 Ulf Lamping
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+# an existing capture file
+CAPFILE=./dhcp.pcap
+
+
+source test-backend.sh
+
+source config.sh
+source suite-clopts.sh
+source suite-capture.sh
+
+
+#check prerequisites
+test_step_prerequisites() {
+
+ NOTFOUND=0
+ for i in "$ETHEREAL" "$TETHEREAL" "$CAPINFOS" "$DUMPCAP" ; do
+ if [ ! -x $i ]; then
+ echo "Couldn't find $i"
+ NOTFOUND=1
+ fi
+ done
+ if [ $NOTFOUND -eq 1 ]; then
+ test_step_failed "Tool not found"
+ exit 1
+ else
+ test_step_ok
+ fi
+}
+
+
+prerequisites_suite() {
+ test_step_add "Prerequisites settings" test_step_prerequisites
+}
+
+test_suite() {
+ test_suite_add "Prerequisites" prerequisites_suite
+ test_suite_add "Basic command line options" clopt_suite
+ test_suite_add "Capture" capture_suite
+}
+
+
+#test_set_output OFF # doesn't work
+#test_set_output DOTTED
+test_set_output VERBOSE
+
+
+#test_suite_run "Tethereal command line options" clopt_suite
+#test_suite_run "Tethereal capture" capture_suite
+
+
+# all
+#test_suite_run "All" test_suite
+#test_suite_show "All" test_suite
+
+MENU_LEVEL=0
+
+menu_title[0]="All"
+menu_function[0]=test_suite
+
+echo "----------------------------------------------------------------------"
+
+for ((a=0; a <= 100000000000 ; a++))
+do
+ TEST_STEPS[0]=0 # number of steps of a specific nesting level
+
+ #echo $current_title $current_function
+ test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
+ echo "1-$TEST_STEPS : Select item"
+ echo "Enter: Test All"
+ if [[ ! $MENU_LEVEL -eq 0 ]]; then
+ echo "U : Up"
+ fi
+ echo "Q : Quit"
+ echo ""
+ read -n1 key
+ newl=$'\x0d'
+ echo "$newl----------------------------------------------------------------------"
+
+ TEST_STEPS[0]=0 # number of steps of a specific nesting level
+
+ #echo $key
+ case "$key" in
+ "Q" | "q")
+ exit 0
+ ;;
+ "T" | "t" | "")
+ test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
+ echo "----------------------------------------------------------------------"
+ ;;
+ "U" | "u")
+ if [[ ! $MENU_LEVEL -eq 0 ]]; then
+ let "MENU_LEVEL -= 1"
+ #echo "----------------------------------------------------------------------"
+ fi
+ ;;
+ "1")
+ let "MENU_LEVEL += 1"
+ menu_title[MENU_LEVEL]=${test_title[1]}
+ menu_function[MENU_LEVEL]=${test_function[1]}
+ ;;
+ "2")
+ let "MENU_LEVEL += 1"
+ menu_title[MENU_LEVEL]=${test_title[2]}
+ menu_function[MENU_LEVEL]=${test_function[2]}
+ ;;
+ "3")
+ let "MENU_LEVEL += 1"
+ menu_title[MENU_LEVEL]=${test_title[3]}
+ menu_function[MENU_LEVEL]=${test_function[3]}
+ ;;
+
+ esac
+done \ No newline at end of file