Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / tools / randpkt-test.sh
blob0eceaa7e40462e96d9334c666acdaf31e9069970
1 #!/bin/bash
3 # $Id$
5 # Randpkt testing script for TShark
7 # This script uses Randpkt to generate capture files with randomized
8 # content. It runs TShark on each generated file and checks for errors.
9 # The files are processed repeatedly until an error is found.
11 TEST_TYPE="randpkt"
12 . `dirname $0`/test-common.sh || exit 1
14 # Trigger an abort if a dissector finds a bug.
15 # Uncomment to disable
16 WIRESHARK_ABORT_ON_DISSECTOR_BUG="True"
18 PKT_TYPES=`$RANDPKT -h | awk '/^\t/ {print $1}'`
20 # To do: add options for file names and limits
21 while getopts ":d:p:t:" OPTCHAR ; do
22 case $OPTCHAR in
23 d) TMP_DIR=$OPTARG ;;
24 p) MAX_PASSES=$OPTARG ;;
25 t) PKT_TYPES=$OPTARG ;;
26 esac
27 done
28 shift $(($OPTIND - 1))
30 ### usually you won't have to change anything below this line ###
32 # TShark arguments (you won't have to change these)
33 # n Disable network object name resolution
34 # V Print a view of the details of the packet rather than a one-line summary of the packet
35 # x Cause TShark to print a hex and ASCII dump of the packet data after printing the summary or details
36 # r Read packet data from the following infile
37 declare -a TSHARK_ARGS=("-nVxr" "-nr")
38 RANDPKT_ARGS="-b 2000 -c 5000"
40 NOTFOUND=0
41 for i in "$TSHARK" "$RANDPKT" "$DATE" "$TMP_DIR" ; do
42 if [ ! -x $i ]; then
43 echo "Couldn't find $i"
44 NOTFOUND=1
46 done
47 if [ $NOTFOUND -eq 1 ]; then
48 exit 1
51 HOWMANY="forever"
52 if [ $MAX_PASSES -gt 0 ]; then
53 HOWMANY="$MAX_PASSES passes"
55 echo -n "Running $TSHARK with args: "
56 printf "\"%s\" " "${TSHARK_ARGS[@]}"
57 echo "($HOWMANY)"
58 echo "Running $RANDPKT with args: $RANDPKT_ARGS"
59 echo ""
61 trap "MAX_PASSES=1; echo 'Caught signal'" HUP INT TERM
64 # Iterate over our capture files.
65 PASS=0
66 while [ $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 ] ; do
67 let PASS=$PASS+1
68 echo "Pass $PASS:"
70 for PKT_TYPE in $PKT_TYPES ; do
71 if [ $PASS -gt $MAX_PASSES -a $MAX_PASSES -ge 1 ] ; then
72 break # We caught a signal
74 echo -n " $PKT_TYPE: "
76 DISSECTOR_BUG=0
78 "$RANDPKT" $RANDPKT_ARGS -t $PKT_TYPE $TMP_DIR/$TMP_FILE \
79 > /dev/null 2>&1
81 for ARGS in "${TSHARK_ARGS[@]}" ; do
82 echo -n "($ARGS) "
83 echo -e "Command and args: $TSHARK $ARGS\n" > $TMP_DIR/$ERR_FILE
85 # Run in a child process with limits, e.g. stop it if it's running
86 # longer then MAX_CPU_TIME seconds. (ulimit may not be supported
87 # well on some platforms, particularly cygwin.)
89 ulimit -S -t $MAX_CPU_TIME -v $MAX_VMEM -s $MAX_STACK
90 ulimit -c unlimited
91 "$TSHARK" $ARGS $TMP_DIR/$TMP_FILE \
92 > /dev/null 2>> $TMP_DIR/$ERR_FILE
94 RETVAL=$?
95 if [ $RETVAL -ne 0 ] ; then break ; fi
96 done
97 grep -i "dissector bug" $TMP_DIR/$ERR_FILE \
98 > /dev/null 2>&1 && DISSECTOR_BUG=1
100 if [ $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 ] ; then
102 exit_error
104 echo " OK"
105 rm -f $TMP_DIR/$TMP_FILE $TMP_DIR/$ERR_FILE
106 done
107 done