Skip to content

Commit

Permalink
Add a target to reproduce fuzz testcase (#3553)
Browse files Browse the repository at this point in the history
* Add a make target to facilitate fuzz testing locally.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* missing target....

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Mar 30, 2021
1 parent 87ca7a4 commit a76a178
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions pkg/logql/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit a76a178

Please sign in to comment.