From ac5a741420dfeb5c30d17441c4f98c7b6d4bd0ec Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Wed, 6 Jun 2018 10:20:21 -0700 Subject: [PATCH] tests: Improve usability of test_fuzz.sh Change-Id: I595e15d155dc6aa759671da510198c39b2e9c23a Signed-off-by: Roy Oursler --- tools/test_fuzz.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/test_fuzz.sh b/tools/test_fuzz.sh index 43fab45..ff54bbc 100755 --- a/tools/test_fuzz.sh +++ b/tools/test_fuzz.sh @@ -2,6 +2,7 @@ usage () { +test_ids=$(echo "${llvm_all_ids[*]}" | sed 's/ /, /g') cat << EOF usage: $0 options options: @@ -9,7 +10,7 @@ options: -l, --llvm Use llvm fuzz tests and run n times 0=just build, -1=skip (default $use_llvm). -a, --afl Use AFL fuzz tests and run n times 0=just build, -1=skip (default $use_afl). -t, --time Run each group of max time [s,h,m,d] - n seconds, hours, minutes or days. - -e Run a specific llvm test or [test, rand, all]. + -e Run a specific llvm test or [$test_ids, rand, all]. -f Use this file as initial raw input. Can be repeated. -d <0,1> Use dump of internal inflate test corpus (default $use_internal_corp). -i Fuzz input dir (default $fuzzin_dir). @@ -22,13 +23,14 @@ exit 0 use_afl=-1 use_llvm=1 samp_files= -use_internal_corp=1 +use_internal_corp=0 fuzzin_dir=fuzzin fuzzout_dir=fuzzout llvm_opts=" -print_final_stats=1" afl_timeout_cmd="" run_secs=0 llvm_tests=("igzip_simple_inflate_fuzz_test") +llvm_all_ids=("simple" "checked" "round_trip") llvm_all_tests=("igzip_simple_inflate_fuzz_test" "igzip_checked_inflate_fuzz_test" "igzip_simple_round_trip_fuzz_test") # Options @@ -70,7 +72,20 @@ while [ "$1" != "${1##-}" ]; do llvm_tests=${llvm_all_tests[$RANDOM % ${#llvm_all_tests[@]} ]} ;; *) - llvm_tests[0]="$2" + flag=0 + for id_index in "${!llvm_all_ids[@]}"; do + if [[ "${llvm_all_ids[$id_index]}" = "$2" ]]; then + flag=1 + llvm_tests[0]="${llvm_all_tests[$id_index]}" + break; + fi + done + + if [ $flag -eq 0 ]; then + test_ids=$(echo "${llvm_all_ids[*]}" | sed 's/ /, /g') + echo "Invalid test, valid options: $test_ids, rand, or all" + exit 0 + fi ;; esac shift 2 @@ -87,7 +102,6 @@ while [ "$1" != "${1##-}" ]; do done set -xe #exit on fail -mkdir -p $fuzzout_dir $fuzzin_dir # Optionally build afl fuzz tests if [ $use_afl -ge 0 ]; then @@ -119,6 +133,12 @@ if [ $use_llvm -ge 0 ]; then make -f Makefile.unx units=igzip llvm_fuzz_tests igzip_dump_inflate_corpus CC=clang CXX=clang++ ${llvm_link_args} fi +#Create fuzz input/output directories +mkdir -p $fuzzin_dir +if [ $use_afl -ge 0 ]; then + mkdir -p $fuzzout_dir +fi + # Optionally fill fuzz input with internal tests corpus [ $use_internal_corp -gt 0 ] && ./igzip_dump_inflate_corpus $fuzzin_dir