diff options
author | Evan Huus <eapache@gmail.com> | 2013-07-25 23:28:38 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-07-25 23:28:38 +0000 |
commit | 7d73903af6209ef1b013c6ed61c866291bfb3785 (patch) | |
tree | 052cb33bf8ce4a06fb7217bc622a3f50d69af857 /tools/fuzz-test.sh | |
parent | 7b1aa041810aeda0c44ea243d34f140153a74987 (diff) |
Multiple improvements and bug-fixes for the fuzz-test script:
- fix a few pieces of bad indentation
- exit cleanly in all cases where we receive a SIGINT or other signal
- check for valgrind bugs and dissector errors with every set of arguments (-nr
vs -nVxr etc) not just the last
- consider it an error if valgrind reports more than 500KB of leaked memory
For the last point, 500KB is hopefully a safe choice for now since we only leak
about 2KB "by default" and I have no idea what the state of most "non-default"
code is with respect to memory leaks. I would like to eventually work this
down to 0 of course :)
svn path=/trunk/; revision=50895
Diffstat (limited to 'tools/fuzz-test.sh')
-rwxr-xr-x | tools/fuzz-test.sh | 125 |
1 files changed, 67 insertions, 58 deletions
diff --git a/tools/fuzz-test.sh b/tools/fuzz-test.sh index 4e77eb9714..6916d3cbf8 100755 --- a/tools/fuzz-test.sh +++ b/tools/fuzz-test.sh @@ -50,6 +50,10 @@ CONFIG_PROFILE= # Run under valgrind ? VALGRIND=0 +# The maximum permitted amount of memory leaked. Eventually this should be +# worked down to zero, but right now that would fail on every single capture. +# Only has effect when running under valgrind. +MAX_LEAK=`expr 1024 \* 500` # To do: add options for file names and limits while getopts ":2b:C:d:e:gp:P:" OPTCHAR ; do @@ -70,7 +74,7 @@ shift $(($OPTIND - 1)) if [ $VALGRIND -eq 1 ]; then RUNNER="$BIN_DIR/tools/valgrind-wireshark.sh" - declare -a RUNNER_ARGS=("${CONFIG_PROFILE}${TWO_PASS}-T" "${CONFIG_PROFILE}${TWO_PASS} ") + declare -a RUNNER_ARGS=("${CONFIG_PROFILE}${TWO_PASS}" "${CONFIG_PROFILE}${TWO_PASS}-T") else # Not using valgrind, use regular tshark. # TShark arguments (you won't have to change these) @@ -125,7 +129,7 @@ fi HOWMANY="forever" if [ $MAX_PASSES -gt 0 ]; then - HOWMANY="$MAX_PASSES passes" + HOWMANY="$MAX_PASSES passes" fi echo -n "Running $RUNNER with args: " printf "\"%s\" " "${RUNNER_ARGS[@]}" @@ -144,9 +148,9 @@ while [ \( $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 \) -a $DONE -ne 1 ] ; do RUN=0 for CF in "$@" ; do - if [ $DONE -eq 1 ]; then - break # We caught a signal - fi + if [ $DONE -eq 1 ]; then + break # We caught a signal + fi RUN=$(( $RUN + 1 )) if [ $(( $RUN % 50 )) -eq 0 ] ; then echo " [Pass $PASS]" @@ -154,35 +158,38 @@ while [ \( $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 \) -a $DONE -ne 1 ] ; do if [ "$OSTYPE" == "cygwin" ] ; then CF=`cygpath --windows "$CF"` fi - echo -n " $CF: " - - "$CAPINFOS" "$CF" > /dev/null 2> $TMP_DIR/$ERR_FILE - RETVAL=$? - if [ $RETVAL -eq 1 ] ; then - echo "Not a valid capture file" - rm -f $TMP_DIR/$ERR_FILE - continue - elif [ $RETVAL -ne 0 -a $DONE -ne 1 ] ; then - # Some other error - exit_error - fi - - DISSECTOR_BUG=0 - VG_ERR_CNT=0 - - "$EDITCAP" -E $ERR_PROB "$CF" $TMP_DIR/$TMP_FILE > /dev/null 2>&1 - if [ $? -ne 0 ] ; then - "$EDITCAP" -E $ERR_PROB -T ether "$CF" $TMP_DIR/$TMP_FILE \ - > /dev/null 2>&1 - if [ $? -ne 0 ] ; then - echo "Invalid format for editcap" - continue - fi - fi - - for ARGS in "${RUNNER_ARGS[@]}" ; do - echo -n "($ARGS) " - echo -e "Command and args: $RUNNER $ARGS\n" > $TMP_DIR/$ERR_FILE + echo -n " $CF: " + + "$CAPINFOS" "$CF" > /dev/null 2> $TMP_DIR/$ERR_FILE + RETVAL=$? + if [ $RETVAL -eq 1 ] ; then + echo "Not a valid capture file" + rm -f $TMP_DIR/$ERR_FILE + continue + elif [ $RETVAL -ne 0 -a $DONE -ne 1 ] ; then + # Some other error + exit_error + fi + + DISSECTOR_BUG=0 + VG_ERR_CNT=0 + + "$EDITCAP" -E $ERR_PROB "$CF" $TMP_DIR/$TMP_FILE > /dev/null 2>&1 + if [ $? -ne 0 ] ; then + "$EDITCAP" -E $ERR_PROB -T ether "$CF" $TMP_DIR/$TMP_FILE \ + > /dev/null 2>&1 + if [ $? -ne 0 ] ; then + echo "Invalid format for editcap" + continue + fi + fi + + for ARGS in "${RUNNER_ARGS[@]}" ; do + if [ $DONE -eq 1 ]; then + break # We caught a signal + fi + echo -n "($ARGS) " + echo -e "Command and args: $RUNNER $ARGS\n" > $TMP_DIR/$ERR_FILE # Run in a child process with limits, e.g. stop it if it's running # longer then MAX_CPU_TIME seconds. (ulimit may not be supported @@ -194,29 +201,31 @@ while [ \( $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 \) -a $DONE -ne 1 ] ; do "$RUNNER" $ARGS $TMP_DIR/$TMP_FILE \ > /dev/null 2>> $TMP_DIR/$ERR_FILE ) - RETVAL=$? - if [ $RETVAL -ne 0 ] ; then break ; fi - done - - # Uncomment the next two lines to enable dissector bug - # checking. - #grep -i "dissector bug" $TMP_DIR/$ERR_FILE \ - # > /dev/null 2>&1 && DISSECTOR_BUG=1 - - if [ $VALGRIND -eq 1 ]; then - VG_ERR_CNT="`grep "ERROR SUMMARY:" $TMP_DIR/$ERR_FILE | cut -f4 -d' '`" - if grep -q "Valgrind cannot continue" $TMP_DIR/$ERR_FILE; then - VG_ERR_CNT=-1 - fi - fi - - if [ \( $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 -o $VG_ERR_CNT -ne 0 \) \ - -a $DONE -ne 1 ] ; then - - exit_error - fi - - echo " OK" - rm -f $TMP_DIR/$TMP_FILE $TMP_DIR/$ERR_FILE + RETVAL=$? + + # Uncomment the next two lines to enable dissector bug + # checking. + #grep -i "dissector bug" $TMP_DIR/$ERR_FILE \ + # > /dev/null 2>&1 && DISSECTOR_BUG=1 + + if [ $VALGRIND -eq 1 -a $DONE -ne 1 ]; then + VG_ERR_CNT=`grep "ERROR SUMMARY:" $TMP_DIR/$ERR_FILE | cut -f4 -d' '` + VG_DEF_LEAKED=`grep "definitely lost:" $TMP_DIR/$ERR_FILE | cut -f7 -d' ' | tr -d ,` + VG_IND_LEAKED=`grep "indirectly lost:" $TMP_DIR/$ERR_FILE | cut -f7 -d' ' | tr -d ,` + if [ "`expr $VG_DEF_LEAKED + $VG_IND_LEAKED`" -gt "$MAX_LEAK" ] ; then + VG_ERR_CNT=1 + fi + if grep -q "Valgrind cannot continue" $TMP_DIR/$ERR_FILE; then + VG_ERR_CNT=-1 + fi + fi + + if [ $DONE -ne 1 -a \( $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 -o $VG_ERR_CNT -ne 0 \) ] ; then + exit_error + fi + done + + echo " OK" + rm -f $TMP_DIR/$TMP_FILE $TMP_DIR/$ERR_FILE done done |