Skip to content

Commit

Permalink
[dev.fuzz] Merge remote-tracking branch 'origin/dev.fuzz' into merge-…
Browse files Browse the repository at this point in the history
…fuzz

Change-Id: I3976e624fe2817d06b708005c994f6832f6d4357
  • Loading branch information
Jay Conrod committed Sep 20, 2021
2 parents b0fa2f5 + 113da92 commit 6e81f78
Show file tree
Hide file tree
Showing 65 changed files with 8,593 additions and 106 deletions.
1 change: 1 addition & 0 deletions api/except.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uin
pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr
pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8
pkg testing, func MainStart(func(string, string) (bool, error), []InternalTest, []InternalBenchmark, []InternalExample) *M
pkg testing, func MainStart(testDeps, []InternalTest, []InternalBenchmark, []InternalExample) *M
pkg testing, func RegisterCover(Cover)
pkg text/scanner, const GoTokens = 1012
pkg text/template/parse, type DotNode bool
Expand Down
36 changes: 36 additions & 0 deletions api/next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,39 @@ pkg syscall (windows-386), func WSASendtoInet4(Handle, *WSABuf, uint32, *uint32,
pkg syscall (windows-386), func WSASendtoInet6(Handle, *WSABuf, uint32, *uint32, uint32, SockaddrInet6, *Overlapped, *uint8) error
pkg syscall (windows-amd64), func WSASendtoInet4(Handle, *WSABuf, uint32, *uint32, uint32, SockaddrInet4, *Overlapped, *uint8) error
pkg syscall (windows-amd64), func WSASendtoInet6(Handle, *WSABuf, uint32, *uint32, uint32, SockaddrInet6, *Overlapped, *uint8) error
pkg testing, func Fuzz(func(*F)) FuzzResult
pkg testing, func MainStart(testDeps, []InternalTest, []InternalBenchmark, []InternalFuzzTarget, []InternalExample) *M
pkg testing, func RunFuzzTargets(func(string, string) (bool, error), []InternalFuzzTarget) bool
pkg testing, func RunFuzzing(func(string, string) (bool, error), []InternalFuzzTarget) bool
pkg testing, method (*B) Setenv(string, string)
pkg testing, method (*F) Add(...interface{})
pkg testing, method (*F) Cleanup(func())
pkg testing, method (*F) Error(...interface{})
pkg testing, method (*F) Errorf(string, ...interface{})
pkg testing, method (*F) Fail()
pkg testing, method (*F) FailNow()
pkg testing, method (*F) Failed() bool
pkg testing, method (*F) Fatal(...interface{})
pkg testing, method (*F) Fatalf(string, ...interface{})
pkg testing, method (*F) Fuzz(interface{})
pkg testing, method (*F) Helper()
pkg testing, method (*F) Log(...interface{})
pkg testing, method (*F) Logf(string, ...interface{})
pkg testing, method (*F) Name() string
pkg testing, method (*F) Setenv(string, string)
pkg testing, method (*F) Skip(...interface{})
pkg testing, method (*F) SkipNow()
pkg testing, method (*F) Skipf(string, ...interface{})
pkg testing, method (*F) Skipped() bool
pkg testing, method (*F) TempDir() string
pkg testing, method (*T) Setenv(string, string)
pkg testing, method (FuzzResult) String() string
pkg testing, type F struct
pkg testing, type FuzzResult struct
pkg testing, type FuzzResult struct, Crasher entry
pkg testing, type FuzzResult struct, Error error
pkg testing, type FuzzResult struct, N int
pkg testing, type FuzzResult struct, T time.Duration
pkg testing, type InternalFuzzTarget struct
pkg testing, type InternalFuzzTarget struct, Fn func(*F)
pkg testing, type InternalFuzzTarget struct, Name string
78 changes: 63 additions & 15 deletions src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/cmd/go/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,13 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {

return nil
}

// FuzzDir returns a subdirectory within the cache for storing fuzzing data.
// The subdirectory may not exist.
//
// This directory is managed by the internal/fuzz package. Files in this
// directory aren't removed by the 'go clean -cache' command or by Trim.
// They may be removed with 'go clean -fuzzcache'.
func (c *Cache) FuzzDir() string {
return filepath.Join(c.dir, "fuzz")
}
4 changes: 4 additions & 0 deletions src/cmd/go/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ var (

func defaultContext() build.Context {
ctxt := build.Default

// TODO(#47037): remove this tag before merging to master.
ctxt.BuildTags = []string{"gofuzzbeta"}

ctxt.JoinPath = filepath.Join // back door to say "do not use go command"

ctxt.GOROOT = findGOROOT()
Expand Down
18 changes: 17 additions & 1 deletion src/cmd/go/internal/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ The -modcache flag causes clean to remove the entire module
download cache, including unpacked source code of versioned
dependencies.
The -fuzzcache flag causes clean to remove values used for fuzz testing.
For more about build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
Expand All @@ -85,6 +87,7 @@ var (
cleanI bool // clean -i flag
cleanR bool // clean -r flag
cleanCache bool // clean -cache flag
cleanFuzzcache bool // clean -fuzzcache flag
cleanModcache bool // clean -modcache flag
cleanTestcache bool // clean -testcache flag
)
Expand All @@ -96,6 +99,7 @@ func init() {
CmdClean.Flag.BoolVar(&cleanI, "i", false, "")
CmdClean.Flag.BoolVar(&cleanR, "r", false, "")
CmdClean.Flag.BoolVar(&cleanCache, "cache", false, "")
CmdClean.Flag.BoolVar(&cleanFuzzcache, "fuzzcache", false, "")
CmdClean.Flag.BoolVar(&cleanModcache, "modcache", false, "")
CmdClean.Flag.BoolVar(&cleanTestcache, "testcache", false, "")

Expand All @@ -112,7 +116,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
// or no other target (such as a cache) was requested to be cleaned.
cleanPkg := len(args) > 0 || cleanI || cleanR
if (!modload.Enabled() || modload.HasModRoot()) &&
!cleanCache && !cleanModcache && !cleanTestcache {
!cleanCache && !cleanModcache && !cleanTestcache && !cleanFuzzcache {
cleanPkg = true
}

Expand Down Expand Up @@ -206,6 +210,18 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
}
}
}

if cleanFuzzcache {
fuzzDir := cache.Default().FuzzDir()
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "rm -rf %s", fuzzDir)
}
if !cfg.BuildN {
if err := os.RemoveAll(fuzzDir); err != nil {
base.Errorf("go clean -fuzzcache: %v", err)
}
}
}
}

var cleaned = map[*load.Package]bool{}
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/go/internal/load/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var (
// that allows specifying different effective flags for different packages.
// See 'go help build' for more details about per-package flags.
type PerPackageFlag struct {
present bool
values []ppfValue
present bool
values []ppfValue
seenPackages map[*Package]bool // the packages for which the flags have already been set
}

// A ppfValue is a single <pattern>=<flags> per-package flag value.
Expand Down
18 changes: 14 additions & 4 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2630,10 +2630,20 @@ func (e *mainPackageError) ImportPath() string {

func setToolFlags(pkgs ...*Package) {
for _, p := range PackageList(pkgs) {
p.Internal.Asmflags = BuildAsmflags.For(p)
p.Internal.Gcflags = BuildGcflags.For(p)
p.Internal.Ldflags = BuildLdflags.For(p)
p.Internal.Gccgoflags = BuildGccgoflags.For(p)
appendFlags(p, &p.Internal.Asmflags, &BuildAsmflags)
appendFlags(p, &p.Internal.Gcflags, &BuildGcflags)
appendFlags(p, &p.Internal.Ldflags, &BuildLdflags)
appendFlags(p, &p.Internal.Gccgoflags, &BuildGccgoflags)
}
}

func appendFlags(p *Package, flags *[]string, packageFlag *PerPackageFlag) {
if !packageFlag.seenPackages[p] {
if packageFlag.seenPackages == nil {
packageFlag.seenPackages = make(map[*Package]bool)
}
packageFlag.seenPackages[p] = true
*flags = append(*flags, packageFlag.For(p)...)
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/cmd/go/internal/load/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func formatTestmain(t *testFuncs) ([]byte, error) {
type testFuncs struct {
Tests []testFunc
Benchmarks []testFunc
FuzzTargets []testFunc
Examples []testFunc
TestMain *testFunc
Package *Package
Expand Down Expand Up @@ -653,6 +654,13 @@ func (t *testFuncs) load(filename, pkg string, doImport, seen *bool) error {
}
t.Benchmarks = append(t.Benchmarks, testFunc{pkg, name, "", false})
*doImport, *seen = true, true
case isTest(name, "Fuzz"):
err := checkTestFunc(n, "F")
if err != nil {
return err
}
t.FuzzTargets = append(t.FuzzTargets, testFunc{pkg, name, "", false})
*doImport, *seen = true, true
}
}
ex := doc.Examples(f)
Expand Down Expand Up @@ -716,6 +724,12 @@ var benchmarks = []testing.InternalBenchmark{
{{end}}
}
var fuzzTargets = []testing.InternalFuzzTarget{
{{range .FuzzTargets}}
{"{{.Name}}", {{.Package}}.{{.Name}}},
{{end}}
}
var examples = []testing.InternalExample{
{{range .Examples}}
{"{{.Name}}", {{.Package}}.{{.Name}}, {{.Output | printf "%q"}}, {{.Unordered}}},
Expand Down Expand Up @@ -774,7 +788,7 @@ func main() {
CoveredPackages: {{printf "%q" .Covered}},
})
{{end}}
m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, examples)
m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, fuzzTargets, examples)
{{with .TestMain}}
{{.Package}}.{{.Name}}(m)
os.Exit(int(reflect.ValueOf(m).Elem().FieldByName("exitCode").Int()))
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/go/internal/test/flagdefs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/flagdefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestPassFlagToTestIncludesAllTestFlags(t *testing.T) {
}
name := strings.TrimPrefix(f.Name, "test.")
switch name {
case "testlogfile", "paniconexit0":
case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker":
// These are internal flags.
default:
if !passFlagToTest[name] {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/genflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testFlags() []string {
name := strings.TrimPrefix(f.Name, "test.")

switch name {
case "testlogfile", "paniconexit0":
case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker":
// These flags are only for use by cmd/go.
default:
names = append(names, name)
Expand Down
Loading

0 comments on commit 6e81f78

Please sign in to comment.