2005-12-13 23:15:20 +00:00
|
|
|
#!/bin/bash
|
2006-12-28 03:17:28 +00:00
|
|
|
(shopt -s igncr) 2>/dev/null && shopt -s igncr; # comment is needed
|
|
|
|
# # hack for cygwin bash
|
|
|
|
# # no-op for other
|
2005-12-13 23:15:20 +00:00
|
|
|
#
|
2006-05-22 08:21:22 +00:00
|
|
|
# Test various command line testable aspects of the Wireshark tools
|
2005-12-13 23:15:20 +00:00
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
2006-05-21 05:12:17 +00:00
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
2005-12-13 23:15:20 +00:00
|
|
|
# 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
|
2012-06-28 22:56:06 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-10-09 18:47:42 +00:00
|
|
|
#
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
# an existing capture file
|
2006-10-10 20:55:38 +00:00
|
|
|
USE_COLOR=1
|
|
|
|
RUN_SUITE=""
|
|
|
|
PRINT_USAGE=0
|
|
|
|
|
|
|
|
while getopts "chs:" OPTION ; do
|
|
|
|
case $OPTION in
|
|
|
|
c) USE_COLOR=0 ;;
|
|
|
|
h) PRINT_USAGE=1 ;;
|
|
|
|
s) RUN_SUITE="$OPTARG" ;;
|
|
|
|
*) echo "Unknown option: " $OPTION $OPTARG
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
|
|
|
|
if [ $PRINT_USAGE -ne 0 ] ; then
|
|
|
|
THIS=`basename $0`
|
|
|
|
cat <<FIN
|
|
|
|
Usage: $THIS [-c] [-h] [-s <suite>]
|
|
|
|
-c: Disable color output
|
|
|
|
-h: Print this message and exit
|
2012-03-30 17:51:54 +00:00
|
|
|
-s: Run a suite. Must be one of:
|
|
|
|
all
|
|
|
|
capture
|
|
|
|
clopts
|
|
|
|
decryption
|
|
|
|
fileformats
|
|
|
|
io
|
2013-05-31 21:40:26 +00:00
|
|
|
nameres
|
2006-10-10 20:55:38 +00:00
|
|
|
prerequisites
|
2012-03-30 17:51:54 +00:00
|
|
|
unittests
|
2006-10-10 20:55:38 +00:00
|
|
|
FIN
|
|
|
|
exit 0
|
|
|
|
fi
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
source test-backend.sh
|
|
|
|
|
|
|
|
source config.sh
|
|
|
|
|
2013-10-06 12:44:10 +00:00
|
|
|
# needed by some tests
|
|
|
|
TEST_OUTDIR=$(mktemp -d)
|
|
|
|
TEST_OUTDIR_CLEAN=${TEST_OUTDIR_CLEAN:-1}
|
|
|
|
if [ -z "$TEST_OUTDIR" ] || ! cd "$TEST_OUTDIR"; then
|
|
|
|
# If for any reason the temporary tests output directory cannot be created...
|
|
|
|
TEST_OUTDIR=.
|
|
|
|
TEST_OUTDIR_CLEAN=0
|
|
|
|
fi
|
|
|
|
|
2013-10-09 17:24:16 +00:00
|
|
|
# Configuration paths
|
|
|
|
HOME_ENV="HOME"
|
|
|
|
HOME_PATH="$TEST_OUTDIR/home"
|
|
|
|
CONF_PATH="$HOME_PATH/.wireshark"
|
|
|
|
|
|
|
|
if [ "$WS_SYSTEM" == "Windows" ] ; then
|
|
|
|
HOME_ENV="APPDATA"
|
|
|
|
HOME_PATH="`cygpath -w $HOME_PATH`"
|
|
|
|
CONF_PATH="$HOME_PATH/Wireshark"
|
|
|
|
CAPTURE_DIR="`cygpath -w $CAPTURE_DIR`"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p $CONF_PATH
|
2013-10-06 23:29:59 +00:00
|
|
|
|
2013-10-06 23:39:16 +00:00
|
|
|
source $TESTS_DIR/suite-clopts.sh
|
|
|
|
source $TESTS_DIR/suite-io.sh
|
|
|
|
source $TESTS_DIR/suite-capture.sh
|
|
|
|
source $TESTS_DIR/suite-unittests.sh
|
|
|
|
source $TESTS_DIR/suite-fileformats.sh
|
|
|
|
source $TESTS_DIR/suite-decryption.sh
|
|
|
|
source $TESTS_DIR/suite-nameres.sh
|
|
|
|
|
2013-10-06 12:44:10 +00:00
|
|
|
test_cleanup() {
|
|
|
|
if [ $TEST_OUTDIR_CLEAN = 1 ]; then
|
2013-10-06 18:57:01 +00:00
|
|
|
# display contents of test outputs, ignore directory:
|
|
|
|
# home (decryption suite)
|
|
|
|
grep -r . --exclude-dir=home .
|
2013-10-06 12:44:10 +00:00
|
|
|
rm -rf "$TEST_OUTDIR"
|
2013-10-06 18:57:01 +00:00
|
|
|
elif ! rmdir "$TEST_OUTDIR" 2>/dev/null; then
|
|
|
|
# if directory is non-empty, print directory
|
2013-10-06 12:44:10 +00:00
|
|
|
echo "Test results are available in $TEST_OUTDIR"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
trap test_cleanup EXIT
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
#check prerequisites
|
|
|
|
test_step_prerequisites() {
|
|
|
|
|
|
|
|
NOTFOUND=0
|
2006-05-31 19:12:15 +00:00
|
|
|
for i in "$WIRESHARK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ ! -x $i ]; then
|
|
|
|
echo "Couldn't find $i"
|
|
|
|
NOTFOUND=1
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
done
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ $NOTFOUND -eq 1 ]; then
|
|
|
|
test_step_failed "Tool not found"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
test_step_ok
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-04-12 01:48:44 +00:00
|
|
|
# Dump version information
|
|
|
|
test_step_tshark_version() {
|
|
|
|
test_remark_add "Printing TShark version"
|
|
|
|
$TSHARK -v
|
|
|
|
RETURNVALUE=$?
|
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
|
|
|
test_step_failed "Failed to print version information"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
test_step_ok
|
|
|
|
}
|
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
prerequisites_suite() {
|
|
|
|
test_step_add "Prerequisites settings" test_step_prerequisites
|
2012-04-12 01:48:44 +00:00
|
|
|
test_step_add "Version information" test_step_tshark_version
|
2005-12-13 23:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_suite() {
|
|
|
|
test_suite_add "Prerequisites" prerequisites_suite
|
2006-01-07 01:15:35 +00:00
|
|
|
test_suite_add "Command line options" clopt_suite
|
|
|
|
test_suite_add "File I/O" io_suite
|
2005-12-13 23:15:20 +00:00
|
|
|
test_suite_add "Capture" capture_suite
|
2010-03-01 22:53:15 +00:00
|
|
|
test_suite_add "Unit tests" unittests_suite
|
2012-03-13 19:58:19 +00:00
|
|
|
test_suite_add "File formats" fileformats_suite
|
2012-03-30 17:51:54 +00:00
|
|
|
test_suite_add "Decryption" decryption_suite
|
2013-05-31 22:32:14 +00:00
|
|
|
test_suite_add "Name Resolution" name_resolution_suite
|
2005-12-13 23:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#test_set_output OFF # doesn't work
|
|
|
|
#test_set_output DOTTED
|
|
|
|
test_set_output VERBOSE
|
|
|
|
|
|
|
|
|
2006-05-31 17:38:42 +00:00
|
|
|
#test_suite_run "TShark command line options" clopt_suite
|
|
|
|
#test_suite_run "TShark capture" capture_suite
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
# all
|
|
|
|
#test_suite_run "All" test_suite
|
|
|
|
#test_suite_show "All" test_suite
|
|
|
|
|
2006-10-10 20:55:38 +00:00
|
|
|
if [ -n "$RUN_SUITE" ] ; then
|
|
|
|
case $RUN_SUITE in
|
|
|
|
"all")
|
|
|
|
test_suite_run "All" test_suite
|
|
|
|
exit $? ;;
|
|
|
|
"capture")
|
|
|
|
test_suite_run "Capture" capture_suite
|
|
|
|
exit $? ;;
|
|
|
|
"clopts")
|
|
|
|
test_suite_run "Command line options" clopt_suite
|
|
|
|
exit $? ;;
|
2012-03-30 17:51:54 +00:00
|
|
|
"decryption")
|
|
|
|
test_suite_run "Decryption" decryption_suite
|
|
|
|
exit $? ;;
|
|
|
|
"fileformats")
|
|
|
|
test_suite_run "File formats" fileformats_suite
|
|
|
|
exit $? ;;
|
2006-10-10 20:55:38 +00:00
|
|
|
"io")
|
|
|
|
test_suite_run "File I/O" io_suite
|
|
|
|
exit $? ;;
|
2013-05-31 21:40:26 +00:00
|
|
|
"nameres")
|
|
|
|
test_suite_run "Name Resolution" name_resolution_suite
|
|
|
|
exit $? ;;
|
2006-10-10 20:55:38 +00:00
|
|
|
"prerequisites")
|
|
|
|
test_suite_run "Prerequisites" prerequisites_suite
|
|
|
|
exit $? ;;
|
2012-03-30 17:51:54 +00:00
|
|
|
"unittests")
|
|
|
|
test_suite_run "Unit tests" unittests_suite
|
|
|
|
exit $? ;;
|
2006-10-10 20:55:38 +00:00
|
|
|
esac
|
2006-10-09 18:47:42 +00:00
|
|
|
fi
|
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
MENU_LEVEL=0
|
|
|
|
|
|
|
|
menu_title[0]="All"
|
|
|
|
menu_function[0]=test_suite
|
|
|
|
|
|
|
|
echo "----------------------------------------------------------------------"
|
|
|
|
|
2006-10-09 18:47:42 +00:00
|
|
|
for ((a=0; a <= 100000000000 ; a++))
|
2005-12-13 23:15:20 +00:00
|
|
|
do
|
|
|
|
TEST_STEPS[0]=0 # number of steps of a specific nesting level
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
#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" | "")
|
2006-08-29 21:01:05 +00:00
|
|
|
LIMIT_RUNS=1
|
|
|
|
for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++)) # Double parentheses, and "LIMIT" with no "$".
|
2006-02-17 22:40:54 +00:00
|
|
|
do
|
2005-12-13 23:15:20 +00:00
|
|
|
test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
|
2006-02-17 22:40:54 +00:00
|
|
|
done
|
2005-12-13 23:15:20 +00:00
|
|
|
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]}
|
|
|
|
;;
|
2006-01-05 00:26:37 +00:00
|
|
|
"4")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[4]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[4]}
|
|
|
|
;;
|
|
|
|
"5")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[5]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[5]}
|
|
|
|
;;
|
|
|
|
"6")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[6]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[6]}
|
|
|
|
;;
|
|
|
|
"7")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[7]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[7]}
|
|
|
|
;;
|
|
|
|
"8")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[8]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[8]}
|
|
|
|
;;
|
|
|
|
"9")
|
|
|
|
let "MENU_LEVEL += 1"
|
|
|
|
menu_title[MENU_LEVEL]=${test_title[9]}
|
|
|
|
menu_function[MENU_LEVEL]=${test_function[9]}
|
|
|
|
;;
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
esac
|
2006-05-31 17:38:42 +00:00
|
|
|
done
|