]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[fuzz] Add regressiontest targets
authorNick Terrell <terrelln@fb.com>
Mon, 25 Sep 2017 20:29:50 +0000 (13:29 -0700)
committerNick Terrell <terrelln@fb.com>
Mon, 25 Sep 2017 22:31:33 +0000 (15:31 -0700)
Makefile
tests/fuzz/Makefile

index e8bdcea331744417fbd840f8b952804091555427..7baff751c75b261bc816b900ca7aa917313037f8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@ ZSTDDIR  = lib
 BUILDIR  = build
 ZWRAPDIR = zlibWrapper
 TESTDIR  = tests
+FUZZDIR  = $(TESTDIR)/fuzz
 
 # Define nul output
 VOID = /dev/null
@@ -215,6 +216,15 @@ arm-ppc-compilation:
        $(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
        $(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
 
+regressiontest:
+       $(MAKE) -C $(FUZZDIR) regressiontest
+
+uasanregressiontest:
+       $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
+
+msanregressiontest:
+       $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
+
 # run UBsan with -fsanitize-recover=signed-integer-overflow
 # due to a bug in UBsan when doing pointer subtraction
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
index 60822d4987e5ca9a33a28b031b13c617db102adc..6d2a0cfa996ca96a7d2306f2f67f40b39d7971c7 100644 (file)
@@ -14,6 +14,13 @@ CPPFLAGS ?=
 LDFLAGS ?=
 ARFLAGS ?=
 LIB_FUZZING_ENGINE ?= libregression.a
+PYTHON ?= python
+ifeq ($(shell uname), Darwin)
+       DOWNLOAD?=curl -L -o
+else
+       DOWNLOAD?=wget -O
+endif
+CORPORA_URL_PREFIX:=https://github.com/facebook/zstd/releases/download/fuzz-corpora/
 
 ZSTDDIR = ../../lib
 PRGDIR = ../../programs
@@ -48,18 +55,20 @@ FUZZ_SRC       := \
 FUZZ_OBJ := $(patsubst %.c,%.o, $(wildcard $(FUZZ_SRC)))
 
 
-.PHONY: default all clean
+.PHONY: default all clean cleanall
 
 default: all
 
-all: \
+FUZZ_TARGETS :=       \
        simple_round_trip \
        stream_round_trip \
-       block_round_trip \
+       block_round_trip  \
        simple_decompress \
        stream_decompress \
        block_decompress
 
+all: $(FUZZ_TARGETS)
+
 %.o: %.c
        $(CC) $(FUZZ_CPPFLAGS) $(FUZZ_CFLAGS) $^ -c -o $@
 
@@ -93,7 +102,25 @@ libFuzzer:
        @git clone https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer
        @cd Fuzzer && ./build.sh
 
+corpora/%_seed_corpus.zip:
+       @mkdir -p corpora
+       $(DOWNLOAD) $@ $(CORPORA_URL_PREFIX)$*_seed_corpus.zip
+
+corpora/%: corpora/%_seed_corpus.zip
+       unzip -q $^ -d $@
+
+.PHONY: corpora
+corpora: $(patsubst %,corpora/%,$(FUZZ_TARGETS))
+
+regressiontest: corpora
+       CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" $(PYTHON) ./fuzz.py build all
+       $(PYTHON) ./fuzz.py regression all
+
 clean:
        @$(MAKE) -C $(ZSTDDIR) clean
        @$(RM) -f *.a *.o
        @$(RM) -f simple_round_trip stream_round_trip simple_decompress stream_decompress
+
+cleanall:
+       @$(RM) -rf Fuzzer
+       @$(RM) -rf corpora