1#!/bin/sh
2#
3# This script is to make a quick check that the fuzzers work,
4# good when working locally developing the fuzzers or making
5# sure code changes still pass the fuzzers.
6#
7# It will download the corpus from bintray (kept up to date
8# by the crontab github actions) unless a local out/ directory
9# already exists.
10#
11# Run it standing in the root of the simdjson repository.
12#
13# By Paul Dreik 20201003
14
15set -eu
16
17for prog in wget tar cmake; do
18  if ! which $prog >/dev/null; then
19   echo please install $prog
20   exit 1
21  fi
22done
23
24#download the corpus if it does not already exist
25if [ ! -d out ] ; then
26  wget --quiet https://dl.bintray.com/pauldreik/simdjson-fuzz-corpus/corpus/corpus.tar
27  tar xf corpus.tar && rm corpus.tar
28fi
29
30# By default, use the debug friendly variant since this script is intended
31# for developers reproducing bugs/validating fixes locally.
32builddir=build-sanitizers-O0
33#...but feel free to use this one instead, if you want to build coverage fast.
34#builddir=build-fast
35
36if [ ! -d $builddir ] ; then
37  fuzz/build_fuzzer_variants.sh
38else
39  cmake --build $builddir --target all_fuzzers
40fi
41
42fuzzernames=$(cmake --build $builddir --target print_all_fuzzernames |tail -n1)
43
44for fuzzer in $fuzzernames ; do
45  exe=$builddir/fuzz/$fuzzer
46  shortname=$(echo $fuzzer |cut -f2- -d_)
47  echo found fuzzer $shortname with executable $exe
48  mkdir -p out/$shortname
49  others=$(find out -type d -not -name $shortname -not -name out -not -name cmin)
50  $exe -max_total_time=20  -max_len=4000 out/$shortname $others
51  echo "*************************************************************************"
52done
53echo "all is good, no errors found in any of these fuzzers: $fuzzernames"
54
55