diff options
author | EuAndreh <eu@euandre.org> | 2024-10-02 08:21:10 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-10-02 08:33:47 -0300 |
commit | c8f256f633d6e94839e95cafc0c18c22886bae01 (patch) | |
tree | d249e20eb5b05c1484899aa28773ce33ad2d8e12 | |
parent | tests/golite.go: Add explicit "deps" variable (diff) | |
download | golite-c8f256f633d6e94839e95cafc0c18c22886bae01.tar.gz golite-c8f256f633d6e94839e95cafc0c18c22886bae01.tar.xz |
Makefile: Add fuzz target setup
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 25 | ||||
-rw-r--r-- | deps.mk | 6 | ||||
-rwxr-xr-x | mkdeps.sh | 13 | ||||
-rw-r--r-- | tests/fuzz/api.go | 34 |
5 files changed, 74 insertions, 6 deletions
@@ -6,3 +6,5 @@ /tests/functional/*.a /tests/functional/*.bin /tests/functional/*.so +/tests/fuzz/*.a +/tests/fuzz/*.bin @@ -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 '.*' @@ -9,15 +9,21 @@ functional-tests-butone.go = \ tests/functional/libbuild.go \ tests/functional/limit.go \ +fuzz-targets.go = \ + tests/fuzz/api.go \ + tests/functional/extension.a: tests/functional/extension.go tests/functional/json.a: tests/functional/json.go tests/functional/libbuild.a: tests/functional/libbuild.go tests/functional/limit.a: tests/functional/limit.go +tests/fuzz/api.a: tests/fuzz/api.go tests/functional/extension.bin: tests/functional/extension.a tests/functional/json.bin: tests/functional/json.a tests/functional/libbuild.bin: tests/functional/libbuild.a tests/functional/limit.bin: tests/functional/limit.a +tests/fuzz/api.bin: tests/fuzz/api.a tests/functional/extension.bin-check: tests/functional/extension.bin tests/functional/json.bin-check: tests/functional/json.bin tests/functional/libbuild.bin-check: tests/functional/libbuild.bin tests/functional/limit.bin-check: tests/functional/limit.bin +tests/fuzz/api.bin-check: tests/fuzz/api.bin @@ -7,6 +7,13 @@ export LANG=POSIX.UTF-8 find tests/functional/*.go | varlist 'functional-tests.go' find tests/functional/*.go -not -name extension.go | varlist 'functional-tests-butone.go' -find tests/functional/*.go | sed 's/^\(.*\)\.go$/\1.a:\t\1.go/' -find tests/functional/*.go | sed 's/^\(.*\)\.go$/\1.bin:\t\1.a/' -find tests/functional/*.go | sed 's/^\(.*\)\.go$/\1.bin-check:\t\1.bin/' +find tests/fuzz/*.go | varlist 'fuzz-targets.go' + + +tfiles() { + find tests/functional/*.go tests/fuzz/*.go | sort +} + +tfiles | sed 's/^\(.*\)\.go$/\1.a:\t\1.go/' +tfiles | sed 's/^\(.*\)\.go$/\1.bin:\t\1.a/' +tfiles | sed 's/^\(.*\)\.go$/\1.bin-check:\t\1.bin/' diff --git a/tests/fuzz/api.go b/tests/fuzz/api.go new file mode 100644 index 0000000..50a19d2 --- /dev/null +++ b/tests/fuzz/api.go @@ -0,0 +1,34 @@ +package main + +import ( + "os" + "testing" + "testing/internal/testdeps" +) + + + +func FuzzAPI(f *testing.F) { + f.Add(123) + f.Fuzz(func(t *testing.T, n int) { + // FIXME + if n == 1234 { + t.Errorf("Failed n: %q\n", n) + } + }) +} + + + +func main() { + fuzzTargets := []testing.InternalFuzzTarget{ + { "FuzzAPI", FuzzAPI }, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples) + os.Exit(m.Run()) +} |