Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a target to reproduce fuzz testcase #3553

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}