5 test_ids
=$
(echo "${llvm_all_ids[*]}" |
sed 's/ /, /g')
10 -l, --llvm <n> Use llvm fuzz tests and run n times 0=just build, -1=skip (default $use_llvm).
11 -a, --afl <n> Use AFL fuzz tests and run n times 0=just build, -1=skip (default $use_afl).
12 -t, --time <n> Run each group of max time <n>[s,h,m,d] - n seconds, hours, minutes or days.
13 -e <exec|rand|all> Run a specific llvm test or [$test_ids, rand, all].
14 -f <file> Use this file as initial raw input. Can be repeated.
15 -d <0,1> Use dump of internal inflate test corpus (default $use_internal_corp).
16 -i <dir> Fuzz input dir (default $fuzzin_dir).
17 -o <dir> Fuzz output dir (default $fuzzout_dir).
29 llvm_opts
=" -print_final_stats=1"
32 llvm_tests
=("igzip_simple_inflate_fuzz_test")
33 llvm_all_ids
=("simple" "checked" "round_trip")
34 llvm_all_tests
=("igzip_simple_inflate_fuzz_test" "igzip_checked_inflate_fuzz_test" "igzip_simple_round_trip_fuzz_test")
37 while [ "$1" != "${1##-}" ]; do
43 run_secs
=$
(echo $2 |
sed -e 's/d$/*24h/' -e 's/h$/*60m/' -e 's/m$/*60/' -e 's/s$//'|
bc)
44 llvm_opts
+=" -max_total_time=$run_secs"
45 afl_timeout_cmd
="timeout --preserve-status $run_secs"
46 echo Run each
for $run_secs seconds
69 llvm_tests
=${llvm_all_tests[@]}
72 llvm_tests
=${llvm_all_tests[$RANDOM % ${#llvm_all_tests[@]} ]}
76 for id_index
in "${!llvm_all_ids[@]}"; do
77 if [[ "${llvm_all_ids[$id_index]}" = "$2" ]]; then
79 llvm_tests
[0]="${llvm_all_tests[$id_index]}"
84 if [ $flag -eq 0 ]; then
85 test_ids
=$
(echo "${llvm_all_ids[*]}" |
sed 's/ /, /g')
86 echo "Invalid test, valid options: $test_ids, rand, or all"
104 set -xe #exit on fail
106 # Optionally build afl fuzz tests
107 if [ $use_afl -ge 0 ]; then
108 echo Build afl fuzz tests
109 if ! command -V afl-gcc
> /dev
/null
; then
110 echo $0 option
--afl requires package afl installed
113 make -f Makefile.unx clean
114 make -f Makefile.unx units
=igzip CC
=afl-gcc other
117 # Optionally build llvm fuzz tests
118 if [ $use_llvm -ge 0 ]; then
119 echo Build llvm fuzz tests
120 if ( command -V clang
++ > /dev
/null
); then
121 if (echo int LLVMFuzzerTestOneInput\
(\
)\
{return 0\
;\
} | clang
++ -x c
- -fsanitize=fuzzer
,address
-lpthread -o /dev
/null
>& /dev
/null
); then
122 echo have modern clang
123 llvm_link_args
='FUZZLINK=-fsanitize=fuzzer,address'
124 elif (echo int LLVMFuzzerTestOneInput\
(\
)\
{return 0\
;\
} | clang
++ -x c
- -lFuzzer -lpthread -o /dev
/null
>& /dev
/null
); then
126 llvm_link_args
='FUZZLINK=-lFuzzer'
128 echo $0 option
--llvm requires clang
++ and libFuzzer
133 make -f Makefile.unx units
=igzip llvm_fuzz_tests igzip_dump_inflate_corpus CC
=clang CXX
=clang
++ ${llvm_link_args}
136 #Create fuzz input/output directories
138 if [ $use_afl -ge 0 ]; then
139 mkdir
-p $fuzzout_dir
142 # Optionally fill fuzz input with internal tests corpus
143 [ $use_internal_corp -gt 0 ] && .
/igzip_dump_inflate_corpus
$fuzzin_dir
145 # Optionally compress input samples as input into fuzz dir
146 for f
in $samp_files; do
147 echo Using sample
file $f
149 .
/igzip_stateless_file_perf
$f -o $fuzzin_dir/samp_
${f_base}_cmp
152 # Optionally run tests alternately one after the other
153 while [ $use_llvm -gt 0 -o $use_afl -gt 0 ]; do
154 if [ $use_afl -gt 0 ]; then
155 echo afl run
$use_afl
157 $afl_timeout_cmd afl-fuzz
-T "Run inflate $run_secs s" -i $fuzzin_dir -o $fuzzout_dir -M fuzzer1
-- .
/igzip_fuzz_inflate @@
158 afl-whatsup
$fuzzout_dir
161 if [ $use_llvm -gt 0 ]; then
162 echo llvm run
$use_llvm
164 for test in $llvm_tests; do
165 echo "Run llvm test $test"
166 .
/$test $fuzzin_dir $llvm_opts
171 make -f Makefile.unx clean