Skip to content

testing/fuzz.go:put the new corpus that caused the panic into another folder #60838

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions src/testing/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func initFuzzFlags() {
matchFuzz = flag.String("test.fuzz", "", "run the fuzz test matching `regexp`")
flag.Var(&fuzzDuration, "test.fuzztime", "time to spend fuzzing; default is to run indefinitely")
flag.Var(&minimizeDuration, "test.fuzzminimizetime", "time to spend minimizing a value after finding a failing input")

fuzzCacheDir = flag.String("test.fuzzcachedir", "", "directory where interesting fuzzing inputs are stored (for use only by cmd/go)")
testOld = flag.Bool("test.old", false, "whether to test the old corpus")
isFuzzWorker = flag.Bool("test.fuzzworker", false, "coordinate with the parent process to fuzz random values (for use only by cmd/go)")
}

Expand All @@ -32,7 +32,7 @@ var (
minimizeDuration = durationOrCountFlag{d: 60 * time.Second, allowZero: true}
fuzzCacheDir *string
isFuzzWorker *bool

testOld *bool
// corpusDir is the parent directory of the fuzz test's seed corpus within
// the package.
corpusDir = "testdata/fuzz"
Expand Down Expand Up @@ -347,7 +347,9 @@ func (f *F) Fuzz(ff any) {
// Fuzzing is enabled, and this is the test process started by 'go test'.
// Act as the coordinator process, and coordinate workers to perform the
// actual fuzzing.
corpusTargetDir := filepath.Join(corpusDir, f.name)
// corpusTargetDir := filepath.Join(corpusDir, f.name)
newPanicDir := f.name + "Panic"
corpusTargetDir := filepath.Join(corpusDir, newPanicDir)
cacheTargetDir := filepath.Join(*fuzzCacheDir, f.name)
err := f.fuzzContext.deps.CoordinateFuzzing(
fuzzDuration.d,
Expand All @@ -367,7 +369,8 @@ func (f *F) Fuzz(ff any) {
crashPath := crashErr.CrashPath()
fmt.Fprintf(f.w, "Failing input written to %s\n", crashPath)
testName := filepath.Base(crashPath)
fmt.Fprintf(f.w, "To re-run:\ngo test -run=%s/%s\n", f.name, testName)
fmt.Fprintf(f.w, "To re-run:\ngo test -run=%s/%s\n", newPanicDir, testName)
// fmt.Fprintf(f.w, "To re-run:\ngo test -run=%s/%s\n", f.name, testName)
}
}
// TODO(jayconrod,katiehockman): Aggregate statistics across workers
Expand Down Expand Up @@ -497,7 +500,15 @@ func runFuzzTests(deps testDeps, fuzzTests []InternalFuzzTarget, deadline time.T
if shouldFailFast() {
break
}
testName, matched, _ := tctx.match.fullName(nil, ft.Name)
// testName, matched, _ := tctx.match.fullName(nil, ft.Name)
var testName string
var matched bool
if *testOld {
testName, matched, _ = tctx.match.fullName(nil, ft.Name)
} else {
newDir := ft.Name + "Panic"
testName, matched, _ = tctx.match.fullName(nil, newDir)
}
if !matched {
continue
}
Expand Down