mirror of
https://github.com/golang/go
synced 2024-11-17 13:54:46 -07:00
[dev.fuzz] testing: move corpus from testdata/corpus to testdata/fuzz
Fixes golang/go#48128 Change-Id: I04deb17226ff5d5dfcbe408fe089f400d4d3836f Reviewed-on: https://go-review.googlesource.com/c/go/+/349053 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
213d9f9a38
commit
b38e853d04
12
src/cmd/go/testdata/script/test_fuzz.txt
vendored
12
src/cmd/go/testdata/script/test_fuzz.txt
vendored
@ -445,20 +445,20 @@ func FuzzWrongType(f *testing.F) {
|
|||||||
f.Fuzz(func(t *testing.T, b []byte) {})
|
f.Fuzz(func(t *testing.T, b []byte) {})
|
||||||
}
|
}
|
||||||
|
|
||||||
-- corpustesting/testdata/corpus/FuzzFail/1 --
|
-- corpustesting/testdata/fuzz/FuzzFail/1 --
|
||||||
go test fuzz v1
|
go test fuzz v1
|
||||||
[]byte("12345")
|
[]byte("12345")
|
||||||
-- corpustesting/testdata/corpus/FuzzPass/1 --
|
-- corpustesting/testdata/fuzz/FuzzPass/1 --
|
||||||
go test fuzz v1
|
go test fuzz v1
|
||||||
[]byte("00000")
|
[]byte("00000")
|
||||||
-- corpustesting/testdata/corpus/FuzzPassString/1 --
|
-- corpustesting/testdata/fuzz/FuzzPassString/1 --
|
||||||
go test fuzz v1
|
go test fuzz v1
|
||||||
string("hello")
|
string("hello")
|
||||||
-- corpustesting/testdata/corpus/FuzzPanic/1 --
|
-- corpustesting/testdata/fuzz/FuzzPanic/1 --
|
||||||
malformed
|
malformed
|
||||||
-- corpustesting/testdata/corpus/FuzzInNestedDir/anotherdir/1 --
|
-- corpustesting/testdata/fuzz/FuzzInNestedDir/anotherdir/1 --
|
||||||
go test fuzz v1
|
go test fuzz v1
|
||||||
[]byte("12345")
|
[]byte("12345")
|
||||||
-- corpustesting/testdata/corpus/FuzzWrongType/1 --
|
-- corpustesting/testdata/fuzz/FuzzWrongType/1 --
|
||||||
go test fuzz v1
|
go test fuzz v1
|
||||||
int("00000")
|
int("00000")
|
@ -14,7 +14,7 @@ go test -c
|
|||||||
exec ./fuzz.test$GOEXE -test.timeout=10ms -test.fuzz=FuzzFast -test.fuzztime=5s -test.parallel=1 -test.fuzzcachedir=$WORK/cache
|
exec ./fuzz.test$GOEXE -test.timeout=10ms -test.fuzz=FuzzFast -test.fuzztime=5s -test.parallel=1 -test.fuzzcachedir=$WORK/cache
|
||||||
|
|
||||||
# Timeout should not cause inputs to be written as crashers.
|
# Timeout should not cause inputs to be written as crashers.
|
||||||
! exists testdata/corpus
|
! exists testdata/fuzz
|
||||||
|
|
||||||
# When we use fuzztime with an "x" suffix, it runs a specific number of times.
|
# When we use fuzztime with an "x" suffix, it runs a specific number of times.
|
||||||
# This fuzz function creates a file with a unique name ($pid.$count) on each run.
|
# This fuzz function creates a file with a unique name ($pid.$count) on each run.
|
||||||
|
@ -39,7 +39,7 @@ go clean -fuzzcache
|
|||||||
# crash will still be logged and written to testdata.
|
# crash will still be logged and written to testdata.
|
||||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=100x -fuzzminimizetime=1x minimizer_test.go
|
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=100x -fuzzminimizetime=1x minimizer_test.go
|
||||||
! stdout '^ok'
|
! stdout '^ok'
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzMinimizerRecoverable[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzMinimizerRecoverable[/\\]'
|
||||||
! stdout 'got the minimum size!' # it shouldn't have had enough time to minimize it
|
! stdout 'got the minimum size!' # it shouldn't have had enough time to minimize it
|
||||||
stdout FAIL
|
stdout FAIL
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the file in testdata (there should only be one)
|
// Open the file in testdata (there should only be one)
|
||||||
dir := fmt.Sprintf("testdata/corpus/%s", target)
|
dir := fmt.Sprintf("testdata/fuzz/%s", target)
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
@ -14,89 +14,89 @@ go test
|
|||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly.
|
# Running the fuzzer should find a crashing input quickly.
|
||||||
! go test -fuzz=FuzzWithBug -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -fuzz=FuzzWithBug -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithBug[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithBug[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzWithBug
|
go run check_testdata.go FuzzWithBug
|
||||||
|
|
||||||
# Now, the failing bytes should have been added to the seed corpus for
|
# Now, the failing bytes should have been added to the seed corpus for
|
||||||
# the target, and should fail when run without fuzzing.
|
# the target, and should fail when run without fuzzing.
|
||||||
! go test
|
! go test
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithBug[/\\][a-f0-9]{64}'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithBug[/\\][a-f0-9]{64}'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
|
|
||||||
! go test -run=FuzzWithNilPanic -fuzz=FuzzWithNilPanic -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithNilPanic -fuzz=FuzzWithNilPanic -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithNilPanic[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithNilPanic[/\\]'
|
||||||
stdout 'runtime.Goexit'
|
stdout 'runtime.Goexit'
|
||||||
go run check_testdata.go FuzzWithNilPanic
|
go run check_testdata.go FuzzWithNilPanic
|
||||||
|
|
||||||
! go test -run=FuzzWithFail -fuzz=FuzzWithFail -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithFail -fuzz=FuzzWithFail -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithFail[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithFail[/\\]'
|
||||||
go run check_testdata.go FuzzWithFail
|
go run check_testdata.go FuzzWithFail
|
||||||
|
|
||||||
! go test -run=FuzzWithLogFail -fuzz=FuzzWithLogFail -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithLogFail -fuzz=FuzzWithLogFail -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithLogFail[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithLogFail[/\\]'
|
||||||
stdout 'logged something'
|
stdout 'logged something'
|
||||||
go run check_testdata.go FuzzWithLogFail
|
go run check_testdata.go FuzzWithLogFail
|
||||||
|
|
||||||
! go test -run=FuzzWithErrorf -fuzz=FuzzWithErrorf -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithErrorf -fuzz=FuzzWithErrorf -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithErrorf[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithErrorf[/\\]'
|
||||||
stdout 'errorf was called here'
|
stdout 'errorf was called here'
|
||||||
go run check_testdata.go FuzzWithErrorf
|
go run check_testdata.go FuzzWithErrorf
|
||||||
|
|
||||||
! go test -run=FuzzWithFatalf -fuzz=FuzzWithFatalf -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithFatalf -fuzz=FuzzWithFatalf -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithFatalf[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithFatalf[/\\]'
|
||||||
stdout 'fatalf was called here'
|
stdout 'fatalf was called here'
|
||||||
go run check_testdata.go FuzzWithFatalf
|
go run check_testdata.go FuzzWithFatalf
|
||||||
|
|
||||||
! go test -run=FuzzWithBadExit -fuzz=FuzzWithBadExit -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithBadExit -fuzz=FuzzWithBadExit -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithBadExit[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithBadExit[/\\]'
|
||||||
stdout 'unexpectedly'
|
stdout 'unexpectedly'
|
||||||
go run check_testdata.go FuzzWithBadExit
|
go run check_testdata.go FuzzWithBadExit
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for fuzzing two types.
|
# Running the fuzzer should find a crashing input quickly for fuzzing two types.
|
||||||
! go test -run=FuzzWithTwoTypes -fuzz=FuzzWithTwoTypes -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzWithTwoTypes -fuzz=FuzzWithTwoTypes -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzWithTwoTypes[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzWithTwoTypes[/\\]'
|
||||||
stdout 'these inputs caused a crash!'
|
stdout 'these inputs caused a crash!'
|
||||||
go run check_testdata.go FuzzWithTwoTypes
|
go run check_testdata.go FuzzWithTwoTypes
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for an integer.
|
# Running the fuzzer should find a crashing input quickly for an integer.
|
||||||
! go test -run=FuzzInt -fuzz=FuzzInt -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzInt -fuzz=FuzzInt -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzInt[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzInt[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzInt
|
go run check_testdata.go FuzzInt
|
||||||
|
|
||||||
! go test -run=FuzzUint -fuzz=FuzzUint -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzUint -fuzz=FuzzUint -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzUint[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzUint[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzUint
|
go run check_testdata.go FuzzUint
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for a bool.
|
# Running the fuzzer should find a crashing input quickly for a bool.
|
||||||
! go test -run=FuzzBool -fuzz=FuzzBool -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzBool -fuzz=FuzzBool -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzBool[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzBool[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzBool
|
go run check_testdata.go FuzzBool
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for a float.
|
# Running the fuzzer should find a crashing input quickly for a float.
|
||||||
! go test -run=FuzzFloat -fuzz=FuzzFloat -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzFloat -fuzz=FuzzFloat -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzFloat[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzFloat[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzFloat
|
go run check_testdata.go FuzzFloat
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for a byte.
|
# Running the fuzzer should find a crashing input quickly for a byte.
|
||||||
! go test -run=FuzzByte -fuzz=FuzzByte -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzByte -fuzz=FuzzByte -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzByte[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzByte[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzByte
|
go run check_testdata.go FuzzByte
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for a rune.
|
# Running the fuzzer should find a crashing input quickly for a rune.
|
||||||
! go test -run=FuzzRune -fuzz=FuzzRune -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzRune -fuzz=FuzzRune -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzRune[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzRune[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzRune
|
go run check_testdata.go FuzzRune
|
||||||
|
|
||||||
# Running the fuzzer should find a crashing input quickly for a string.
|
# Running the fuzzer should find a crashing input quickly for a string.
|
||||||
! go test -run=FuzzString -fuzz=FuzzString -fuzztime=100x -fuzzminimizetime=1000x
|
! go test -run=FuzzString -fuzz=FuzzString -fuzztime=100x -fuzzminimizetime=1000x
|
||||||
stdout 'testdata[/\\]corpus[/\\]FuzzString[/\\]'
|
stdout 'testdata[/\\]fuzz[/\\]FuzzString[/\\]'
|
||||||
stdout 'this input caused a crash!'
|
stdout 'this input caused a crash!'
|
||||||
go run check_testdata.go FuzzString
|
go run check_testdata.go FuzzString
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
target := os.Args[1]
|
target := os.Args[1]
|
||||||
dir := filepath.Join("testdata/corpus", target)
|
dir := filepath.Join("testdata/fuzz", target)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,7 +15,7 @@ stdout 'fuzzing process terminated by unexpected signal; no crash will be record
|
|||||||
# FuzzCrash sends itself a signal that looks like a crash.
|
# FuzzCrash sends itself a signal that looks like a crash.
|
||||||
# We should save a crasher.
|
# We should save a crasher.
|
||||||
! go test -fuzz=FuzzCrash
|
! go test -fuzz=FuzzCrash
|
||||||
exists testdata/corpus/FuzzCrash
|
exists testdata/fuzz/FuzzCrash
|
||||||
stdout 'fuzzing process terminated unexpectedly'
|
stdout 'fuzzing process terminated unexpectedly'
|
||||||
|
|
||||||
-- go.mod --
|
-- go.mod --
|
||||||
|
@ -13,7 +13,7 @@ go test -run=FuzzSeed
|
|||||||
# TODO(jayconrod): check for the string "after T.Parallel". It's not printed
|
# TODO(jayconrod): check for the string "after T.Parallel". It's not printed
|
||||||
# by 'go test', so we can't distinguish that crasher from some other panic.
|
# by 'go test', so we can't distinguish that crasher from some other panic.
|
||||||
! go test -run=FuzzMutate -fuzz=FuzzMutate
|
! go test -run=FuzzMutate -fuzz=FuzzMutate
|
||||||
exists testdata/corpus/FuzzMutate
|
exists testdata/fuzz/FuzzMutate
|
||||||
|
|
||||||
-- go.mod --
|
-- go.mod --
|
||||||
module fuzz_parallel
|
module fuzz_parallel
|
||||||
|
@ -34,7 +34,7 @@ var (
|
|||||||
|
|
||||||
// corpusDir is the parent directory of the target's seed corpus within
|
// corpusDir is the parent directory of the target's seed corpus within
|
||||||
// the package.
|
// the package.
|
||||||
corpusDir = "testdata/corpus"
|
corpusDir = "testdata/fuzz"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fuzzWorkerExitCode is used as an exit code by fuzz worker processes after an internal error.
|
// fuzzWorkerExitCode is used as an exit code by fuzz worker processes after an internal error.
|
||||||
@ -419,7 +419,7 @@ func (f *F) Fuzz(ff interface{}) {
|
|||||||
fmt.Fprintf(f.w, "%v\n", err)
|
fmt.Fprintf(f.w, "%v\n", err)
|
||||||
if crashErr, ok := err.(fuzzCrashError); ok {
|
if crashErr, ok := err.(fuzzCrashError); ok {
|
||||||
crashName := crashErr.CrashName()
|
crashName := crashErr.CrashName()
|
||||||
fmt.Fprintf(f.w, "Crash written to %s\n", filepath.Join("testdata/corpus", f.name, crashName))
|
fmt.Fprintf(f.w, "Crash written to %s\n", filepath.Join(corpusDir, f.name, crashName))
|
||||||
fmt.Fprintf(f.w, "To re-run:\ngo test %s -run=%s/%s\n", f.fuzzContext.importPath(), f.name, crashName)
|
fmt.Fprintf(f.w, "To re-run:\ngo test %s -run=%s/%s\n", f.fuzzContext.importPath(), f.name, crashName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user