aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-02 08:21:10 -0300
committerEuAndreh <eu@euandre.org>2024-10-02 08:33:47 -0300
commitc8f256f633d6e94839e95cafc0c18c22886bae01 (patch)
treed249e20eb5b05c1484899aa28773ce33ad2d8e12
parenttests/golite.go: Add explicit "deps" variable (diff)
downloadgolite-c8f256f633d6e94839e95cafc0c18c22886bae01.tar.gz
golite-c8f256f633d6e94839e95cafc0c18c22886bae01.tar.xz
Makefile: Add fuzz target setup
-rw-r--r--.gitignore2
-rw-r--r--Makefile25
-rw-r--r--deps.mk6
-rwxr-xr-xmkdeps.sh13
-rw-r--r--tests/fuzz/api.go34
5 files changed, 74 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 3bb73dd..3d9fb8b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@
/tests/functional/*.a
/tests/functional/*.bin
/tests/functional/*.so
+/tests/fuzz/*.a
+/tests/fuzz/*.bin
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 '.*'
diff --git a/deps.mk b/deps.mk
index 5f458e5..9de79a9 100644
--- a/deps.mk
+++ b/deps.mk
@@ -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
diff --git a/mkdeps.sh b/mkdeps.sh
index ceb57af..8ccfc69 100755
--- a/mkdeps.sh
+++ b/mkdeps.sh
@@ -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())
+}