1#!/bin/sh 2CMDLINE="/prg/tests/normal/tiff-4.0.4/tools/thumbnail @@ /dev/null" 3INDIR="/prg/tests/normal/tiff-4.0.4/in-small" 4 5test -z "$1" -o -n "$4" && { 6 echo "Syntax: $0 commit-id <indir> \"<cmdline>\"" 7 echo 8 echo "Switches to the defined commit ID, compiles with profiling and runs" 9 echo "afl-fuzz on a defind target and input directory, saving timing," 10 echo "fuzzer_stats and profiling output to \"<commit-id>.out\"" 11 echo "Honors CFLAGS and LDFLAGS" 12 echo 13 echo "Defaults:" 14 echo " indir: \"$INDIR\"" 15 echo " cmdline: \"$CMDLINE\"" 16 exit 1 17} 18 19C=$1 20test -n "$2" && INDIR=$2 21test -n "$3" && CMDLINE=$3 22 23git checkout "$C" || { echo "CHECKOUT FAIL $C" > $C.out ; exit 1 ; } 24export AFL_BENCH_JUST_ONE=1 25test -z "$CFLAGS" && CFLAGS="-O3 -funroll-loops" 26export CFLAGS="$CFLAGS -pg" 27export LDFLAGS="$LDFLAGS -pg" 28make >/dev/null 2>&1 || echo ERROR: BUILD FAILURE 29test -x ./afl-fuzz || { echo "BUILD FAIL $C" > $C.out ; make clean ; exit 1 ; } 30 31START=`date +%s` 32echo $START > $C.out 33time nice -n -20 ./afl-fuzz -i "$INDIR" -s 123 -o out-profile -- $CMDLINE 2>> $C.out 34STOP=`date +%s` 35echo $STOP >> $C.out 36echo RUNTIME: `expr $STOP - $START` >> $C.out 37cat out-profile/default/fuzzer_stats >> $C.out 38gprof ./afl-fuzz gmon.out >> $C.out 39 40make clean >/dev/null 2>&1 41rm -rf out-profile gmon.out 42