From a76a17877b2d36dd6578b92b8b6208d8817d7dd9 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Tue, 30 Mar 2021 06:05:49 -0400 Subject: [PATCH] Add a target to reproduce fuzz testcase (#3553) * Add a make target to facilitate fuzz testing locally. Signed-off-by: Cyril Tovena * missing target.... Signed-off-by: Cyril Tovena --- Makefile | 6 ++++++ pkg/logql/fuzz_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 pkg/logql/fuzz_test.go diff --git a/Makefile b/Makefile index 9aeb69e856b2..e8e30d980efc 100644 --- a/Makefile +++ b/Makefile @@ -582,3 +582,9 @@ lint-jsonnet: fmt-jsonnet: @find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ xargs -n 1 -- jsonnetfmt -i + +# usage: FUZZ_TESTCASE_PATH=/tmp/testcase make test-fuzz +# this will run the fuzzing using /tmp/testcase and save benchmark locally. +test-fuzz: + go test -timeout 30s -tags dev,gofuzz -cpuprofile cpu.prof -memprofile mem.prof \ + -run ^Test_Fuzz$$ github.com/grafana/loki/pkg/logql -v -count=1 -timeout=0s diff --git a/pkg/logql/fuzz_test.go b/pkg/logql/fuzz_test.go new file mode 100644 index 000000000000..4a5aa4a1c983 --- /dev/null +++ b/pkg/logql/fuzz_test.go @@ -0,0 +1,20 @@ +// +build gofuzz + +package logql + +import ( + "io/ioutil" + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +const fuzzTestCaseEnvName = "FUZZ_TESTCASE_PATH" + +func Test_Fuzz(t *testing.T) { + fuzzTestPath := os.Getenv(fuzzTestCaseEnvName) + data, err := ioutil.ReadFile(fuzzTestPath) + require.NoError(t, err) + _, _ = ParseExpr(string(data)) +}