From c8f256f633d6e94839e95cafc0c18c22886bae01 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 2 Oct 2024 08:21:10 -0300 Subject: Makefile: Add fuzz target setup --- Makefile | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 10af5c8..6ddd223 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,8 @@ include deps.mk functional-tests.a = $(functional-tests.go:.go=.a) functional-tests.bin = $(functional-tests.go:.go=.bin) +fuzz-targets.a = $(fuzz-targets.go:.go=.a) +fuzz-targets.bin = $(fuzz-targets.go:.go=.bin) cgo.go = \ src/_cgo_import.go \ @@ -67,6 +69,8 @@ derived-assets = \ $(functional-tests.a) \ $(functional-tests.bin) \ tests/functional/streq.so \ + $(fuzz-targets.a) \ + $(fuzz-targets.bin) \ side-assets = \ src/_cgo_export.h \ @@ -83,6 +87,8 @@ $(derived-assets): Makefile deps.mk $(cgo.go) $(cgo.c) $(cgo.o): src/_cgo_.o +$(functional-tests.a) $(fuzz-targets.a): src/$(NAME).a + src/_cgo_.o: src/$(NAME).go go tool cgo --objdir $(@D) src/$(NAME).go @@ -107,10 +113,13 @@ tests/main.bin: tests/main.a src/version.go: Makefile echo 'package $(NAME); const Version = "$(VERSION)"' > $@ -$(functional-tests.a): src/$(NAME).a - go tool compile $(GOCFLAGS) -o $@ -p main -I src $*.go +$(functional-tests.a): + go tool compile $(GOCFLAGS) -o $@ -p main -I src $*.go + +$(fuzz-targets.a): + go tool compile -d=libfuzzer $(GOCFLAGS) -o $@ -p main -I src $*.go -$(functional-tests.bin): +$(functional-tests.bin) $(fuzz-targets.bin): go tool link $(GOLDFLAGS) -o $@ -L src --extldflags '$(LDLIBS)' $*.a tests/functional/streq.so: tests/functional/streq.c @@ -152,6 +161,16 @@ check: check-unit check-integration +FUZZSEC=1 +fuzz-targets.bin-check = $(fuzz-targets.go:.go=.bin-check) +$(fuzz-targets.bin-check): + $(EXEC)$*.bin --test.fuzztime=$(FUZZSEC)s \ + --test.fuzz=Fuzz --test.fuzzcachedir=tests/fuzz/corpus + +fuzz: $(fuzz-targets.bin-check) + + + bench: tests/main.bin $(EXEC)tests/main.bin -test.bench '.*' -- cgit v1.2.3