nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/bin/bash
2  
3 # Randpkt testing script for TShark
4 #
5 # This script uses Randpkt to generate capture files with randomized
6 # content. It runs TShark on each generated file and checks for errors.
7 # The files are processed repeatedly until an error is found.
8  
9 TEST_TYPE="randpkt"
10 . `dirname $0`/test-common.sh || exit 1
11  
12 # Run under AddressSanitizer ?
13 ASAN=$CONFIGURED_WITH_ASAN
14  
15 # Trigger an abort if a dissector finds a bug.
16 # Uncomment to disable
17 WIRESHARK_ABORT_ON_DISSECTOR_BUG="True"
18  
19 # To do: add options for file names and limits
20 while getopts "a:b:d:p:t:" OPTCHAR ; do
21 case $OPTCHAR in
22 a) ASAN=1 ;;
23 b) WIRESHARK_BIN_DIR=$OPTARG ;;
24 d) TMP_DIR=$OPTARG ;;
25 p) MAX_PASSES=$OPTARG ;;
26 t) PKT_TYPES=$OPTARG ;;
27 esac
28 done
29 shift $(($OPTIND - 1))
30  
31 ### usually you won't have to change anything below this line ###
32  
33 ws_bind_exec_paths
34 ws_check_exec "$TSHARK" "$RANDPKT" "$DATE" "$TMP_DIR"
35  
36 [[ -z "$PKT_TYPES" ]] && PKT_TYPES=$($RANDPKT -h | awk '/^\t/ {print $1}')
37  
38 # TShark arguments (you won't have to change these)
39 # n Disable network object name resolution
40 # V Print a view of the details of the packet rather than a one-line summary of the packet
41 # x Cause TShark to print a hex and ASCII dump of the packet data after printing the summary or details
42 # r Read packet data from the following infile
43 declare -a TSHARK_ARGS=("-nVxr" "-nr")
44 RANDPKT_ARGS="-b 2000 -c 5000"
45  
46 if [ $ASAN -ne 0 ]; then
47 echo -n "ASan enabled. Virtual memory limit is "
48 ulimit -v
49 else
50 echo "ASan disabled. Virtual memory limit is $MAX_VMEM"
51 fi
52  
53 HOWMANY="forever"
54 if [ $MAX_PASSES -gt 0 ]; then
55 HOWMANY="$MAX_PASSES passes"
56 fi
57 echo -n "Running $TSHARK with args: "
58 printf "\"%s\" " "${TSHARK_ARGS[@]}"
59 echo "($HOWMANY)"
60 echo "Running $RANDPKT with args: $RANDPKT_ARGS"
61 echo ""
62  
63 trap "MAX_PASSES=1; echo 'Caught signal'" HUP INT TERM
64  
65  
66 # Iterate over our capture files.
67 PASS=0
68 while [ $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 ] ; do
69 let PASS=$PASS+1
70 echo "Pass $PASS:"
71  
72 for PKT_TYPE in $PKT_TYPES ; do
73 if [ $PASS -gt $MAX_PASSES -a $MAX_PASSES -ge 1 ] ; then
74 break # We caught a signal
75 fi
76 echo -n " $PKT_TYPE: "
77  
78 DISSECTOR_BUG=0
79  
80 "$RANDPKT" $RANDPKT_ARGS -t $PKT_TYPE $TMP_DIR/$TMP_FILE \
81 > /dev/null 2>&1
82  
83 for ARGS in "${TSHARK_ARGS[@]}" ; do
84 echo -n "($ARGS) "
85 echo -e "Command and args: $TSHARK $ARGS\n" > $TMP_DIR/$ERR_FILE
86  
87 # Run in a child process with limits.
88 (
89 # Set some limits to the child processes, e.g. stop it if
90 # it's running longer than MAX_CPU_TIME seconds. (ulimit
91 # is not supported well on cygwin - it shows some warnings -
92 # and the features we use may not all be supported on some
93 # UN*X platforms.)
94 ulimit -S -t $MAX_CPU_TIME -s $MAX_STACK
95  
96 # Allow core files to be generated
97 ulimit -c unlimited
98  
99 # Don't enable ulimit -v when using ASAN. See
100 # https://github.com/google/sanitizers/wiki/AddressSanitizer#ulimit--v
101 if [ $ASAN -eq 0 ]; then
102 ulimit -S -v $MAX_VMEM
103 fi
104  
105 "$TSHARK" $ARGS $TMP_DIR/$TMP_FILE \
106 > /dev/null 2>> $TMP_DIR/$ERR_FILE
107 )
108 RETVAL=$?
109 if [ $RETVAL -ne 0 ] ; then break ; fi
110 done
111 grep -i "dissector bug" $TMP_DIR/$ERR_FILE \
112 > /dev/null 2>&1 && DISSECTOR_BUG=1
113  
114 if [ $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 ] ; then
115  
116 ws_exit_error
117 fi
118 echo " OK"
119 rm -f $TMP_DIR/$TMP_FILE $TMP_DIR/$ERR_FILE
120 done
121 done