Update linux-x86 Go 1.17 prebuilts from ab/7691198
https://ci.android.com/builds/branches/aosp-build-tools-release/grid?head=7691198&tail=7691198
Update script: toolchain/go/update-prebuilts.sh
Test: Treehugger presubmit
Change-Id: Ieec20a4cc4abea67c51066c8d49d26647b6e5583
diff --git a/test/run.go b/test/run.go
index 624f223..d7f5d02 100644
--- a/test/run.go
+++ b/test/run.go
@@ -12,6 +12,7 @@
"errors"
"flag"
"fmt"
+ "go/build"
"hash/fnv"
"io"
"io/fs"
@@ -56,10 +57,11 @@
var (
goos, goarch string
+ cgoEnabled bool
// dirs are the directories to look for *.go files in.
// TODO(bradfitz): just use all directories?
- dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime"}
+ dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam"}
// ratec controls the max number of tests running at a time.
ratec chan bool
@@ -82,6 +84,10 @@
goos = getenv("GOOS", runtime.GOOS)
goarch = getenv("GOARCH", runtime.GOARCH)
+ cgoEnv, err := exec.Command(goTool(), "env", "CGO_ENABLED").Output()
+ if err == nil {
+ cgoEnabled, _ = strconv.ParseBool(strings.TrimSpace(string(cgoEnv)))
+ }
findExecCmd()
@@ -367,9 +373,10 @@
}
type context struct {
- GOOS string
- GOARCH string
- noOptEnv bool
+ GOOS string
+ GOARCH string
+ cgoEnabled bool
+ noOptEnv bool
}
// shouldTest looks for build tags in a source file and returns
@@ -391,9 +398,10 @@
}
gcFlags := os.Getenv("GO_GCFLAGS")
ctxt := &context{
- GOOS: goos,
- GOARCH: goarch,
- noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
+ GOOS: goos,
+ GOARCH: goarch,
+ cgoEnabled: cgoEnabled,
+ noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
}
words := strings.Fields(line)
@@ -438,6 +446,19 @@
}
}
+ if strings.HasPrefix(name, "goexperiment.") {
+ for _, tag := range build.Default.ToolTags {
+ if tag == name {
+ return true
+ }
+ }
+ return false
+ }
+
+ if name == "cgo" && ctxt.cgoEnabled {
+ return true
+ }
+
if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" {
return true
}
@@ -491,7 +512,7 @@
// Execution recipe stops at first blank line.
pos := strings.Index(t.src, "\n\n")
if pos == -1 {
- t.err = errors.New("double newline not found")
+ t.err = fmt.Errorf("double newline ending execution recipe not found in %s", t.goFileName())
return
}
action := t.src[:pos]
@@ -513,7 +534,7 @@
return
}
- var args, flags []string
+ var args, flags, runenv []string
var tim int
wantError := false
wantAuto := false
@@ -572,6 +593,9 @@
if err != nil {
t.err = fmt.Errorf("need number of seconds for -t timeout, got %s instead", args[0])
}
+ case "-goexperiment": // set GOEXPERIMENT environment
+ args = args[1:]
+ runenv = append(runenv, "GOEXPERIMENT="+args[0])
default:
flags = append(flags, args[0])
@@ -628,6 +652,7 @@
if tempDirIsGOPATH {
cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
}
+ cmd.Env = append(cmd.Env, runenv...)
var err error
@@ -725,7 +750,7 @@
// Fail if wantError is true and compilation was successful and vice versa.
// Match errors produced by gc against errors in comments.
// TODO(gri) remove need for -C (disable printing of columns in error messages)
- cmdline := []string{goTool(), "tool", "compile", "-C", "-e", "-o", "a.o"}
+ cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-C", "-e", "-o", "a.o"}
// No need to add -dynlink even if linkshared if we're just checking for errors...
cmdline = append(cmdline, flags...)
cmdline = append(cmdline, long)
@@ -749,7 +774,66 @@
t.updateErrors(string(out), long)
}
t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
- return
+ if t.err != nil {
+ return // don't hide error if run below succeeds
+ }
+
+ // The following is temporary scaffolding to get types2 typechecker
+ // up and running against the existing test cases. The explicitly
+ // listed files don't pass yet, usually because the error messages
+ // are slightly different (this list is not complete). Any errorcheck
+ // tests that require output from analysis phases past initial type-
+ // checking are also excluded since these phases are not running yet.
+ // We can get rid of this code once types2 is fully plugged in.
+
+ // For now we're done when we can't handle the file or some of the flags.
+ // The first goal is to eliminate the excluded list; the second goal is to
+ // eliminate the flag list.
+
+ // Excluded files.
+ filename := strings.Replace(t.goFileName(), "\\", "/", -1) // goFileName() uses \ on Windows
+ if excluded[filename] {
+ if *verbose {
+ fmt.Printf("excl\t%s\n", filename)
+ }
+ return // cannot handle file yet
+ }
+
+ // Excluded flags.
+ for _, flag := range flags {
+ for _, pattern := range []string{
+ "-m",
+ } {
+ if strings.Contains(flag, pattern) {
+ if *verbose {
+ fmt.Printf("excl\t%s\t%s\n", filename, flags)
+ }
+ return // cannot handle flag
+ }
+ }
+ }
+
+ // Run errorcheck again with -G option (new typechecker).
+ cmdline = []string{goTool(), "tool", "compile", "-G=3", "-C", "-e", "-o", "a.o"}
+ // No need to add -dynlink even if linkshared if we're just checking for errors...
+ cmdline = append(cmdline, flags...)
+ cmdline = append(cmdline, long)
+ out, err = runcmd(cmdline...)
+ if wantError {
+ if err == nil {
+ t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
+ return
+ }
+ } else {
+ if err != nil {
+ t.err = err
+ return
+ }
+ }
+ if *updateErrors {
+ t.updateErrors(string(out), long)
+ }
+ t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
case "compile":
// Compile Go file.
@@ -771,6 +855,7 @@
}
case "errorcheckdir", "errorcheckandrundir":
+ flags = append(flags, "-d=panic")
// Compile and errorCheck all files in the directory as packages in lexicographic order.
// If errorcheckdir and wantError, compilation of the last package must fail.
// If errorcheckandrundir and wantError, compilation of the package prior the last must fail.
@@ -868,9 +953,7 @@
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
}
}
@@ -904,15 +987,14 @@
if *linkshared {
cmd = append(cmd, "-linkshared")
}
+ cmd = append(cmd, flags...)
cmd = append(cmd, ".")
out, err := runcmd(cmd...)
if err != nil {
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "build":
// Build Go file.
@@ -997,9 +1079,7 @@
t.err = err
break
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
}
case "buildrun":
@@ -1025,9 +1105,7 @@
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "run":
// Run Go file if no special go command flags are provided;
@@ -1070,9 +1148,7 @@
t.err = err
return
}
- if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "runoutput":
// Run Go file and write its output into temporary Go file.
@@ -1107,9 +1183,7 @@
t.err = err
return
}
- if string(out) != t.expectedOutput() {
- t.err = fmt.Errorf("incorrect output\n%s", out)
- }
+ t.checkExpectedOutput(out)
case "errorcheckoutput":
// Run Go file and write its output into temporary Go file.
@@ -1131,7 +1205,7 @@
t.err = fmt.Errorf("write tempfile:%s", err)
return
}
- cmdline := []string{goTool(), "tool", "compile", "-e", "-o", "a.o"}
+ cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-e", "-o", "a.o"}
cmdline = append(cmdline, flags...)
cmdline = append(cmdline, tfile)
out, err = runcmd(cmdline...)
@@ -1183,12 +1257,24 @@
}
}
-func (t *test) expectedOutput() string {
+// checkExpectedOutput compares the output from compiling and/or running with the contents
+// of the corresponding reference output file, if any (replace ".go" with ".out").
+// If they don't match, fail with an informative message.
+func (t *test) checkExpectedOutput(gotBytes []byte) {
+ got := string(gotBytes)
filename := filepath.Join(t.dir, t.gofile)
filename = filename[:len(filename)-len(".go")]
filename += ".out"
- b, _ := ioutil.ReadFile(filename)
- return string(b)
+ b, err := ioutil.ReadFile(filename)
+ // File is allowed to be missing (err != nil) in which case output should be empty.
+ got = strings.Replace(got, "\r\n", "\n", -1)
+ if got != string(b) {
+ if err == nil {
+ t.err = fmt.Errorf("output does not match expected in %s. Instead saw\n%s", filename, got)
+ } else {
+ t.err = fmt.Errorf("output should be empty when (optional) expected-output file %s is not present. Instead saw\n%s", filename, got)
+ }
+ }
}
func splitOutput(out string, wantAuto bool) []string {
@@ -1854,3 +1940,67 @@
return err
})
}
+
+// List of files that the compiler cannot errorcheck with the new typechecker (compiler -G option).
+// Temporary scaffolding until we pass all the tests at which point this map can be removed.
+var excluded = map[string]bool{
+ "complit1.go": true, // types2 reports extra errors
+ "const2.go": true, // types2 not run after syntax errors
+ "ddd1.go": true, // issue #42987
+ "directive.go": true, // misplaced compiler directive checks
+ "float_lit3.go": true, // types2 reports extra errors
+ "import1.go": true, // types2 reports extra errors
+ "import5.go": true, // issue #42988
+ "import6.go": true, // issue #43109
+ "initializerr.go": true, // types2 reports extra errors
+ "linkname2.go": true, // error reported by noder (not running for types2 errorcheck test)
+ "notinheap.go": true, // types2 doesn't report errors about conversions that are invalid due to //go:notinheap
+ "shift1.go": true, // issue #42989
+ "typecheck.go": true, // invalid function is not causing errors when called
+ "writebarrier.go": true, // correct diagnostics, but different lines (probably irgen's fault)
+
+ "fixedbugs/bug176.go": true, // types2 reports all errors (pref: types2)
+ "fixedbugs/bug195.go": true, // types2 reports slightly different (but correct) bugs
+ "fixedbugs/bug228.go": true, // types2 not run after syntax errors
+ "fixedbugs/bug231.go": true, // types2 bug? (same error reported twice)
+ "fixedbugs/bug255.go": true, // types2 reports extra errors
+ "fixedbugs/bug351.go": true, // types2 reports extra errors
+ "fixedbugs/bug374.go": true, // types2 reports extra errors
+ "fixedbugs/bug385_32.go": true, // types2 doesn't produce missing error "type .* too large" (32-bit specific)
+ "fixedbugs/bug388.go": true, // types2 not run due to syntax errors
+ "fixedbugs/bug412.go": true, // types2 produces a follow-on error
+
+ "fixedbugs/issue11590.go": true, // types2 doesn't report a follow-on error (pref: types2)
+ "fixedbugs/issue11610.go": true, // types2 not run after syntax errors
+ "fixedbugs/issue11614.go": true, // types2 reports an extra error
+ "fixedbugs/issue13415.go": true, // declared but not used conflict
+ "fixedbugs/issue14520.go": true, // missing import path error by types2
+ "fixedbugs/issue16428.go": true, // types2 reports two instead of one error
+ "fixedbugs/issue17038.go": true, // types2 doesn't report a follow-on error (pref: types2)
+ "fixedbugs/issue17645.go": true, // multiple errors on same line
+ "fixedbugs/issue18331.go": true, // missing error about misuse of //go:noescape (irgen needs code from noder)
+ "fixedbugs/issue18393.go": true, // types2 not run after syntax errors
+ "fixedbugs/issue19012.go": true, // multiple errors on same line
+ "fixedbugs/issue20233.go": true, // types2 reports two instead of one error (pref: compiler)
+ "fixedbugs/issue20245.go": true, // types2 reports two instead of one error (pref: compiler)
+ "fixedbugs/issue20250.go": true, // correct diagnostics, but different lines (probably irgen's fault)
+ "fixedbugs/issue21979.go": true, // types2 doesn't report a follow-on error (pref: types2)
+ "fixedbugs/issue23732.go": true, // types2 reports different (but ok) line numbers
+ "fixedbugs/issue25958.go": true, // types2 doesn't report a follow-on error (pref: types2)
+ "fixedbugs/issue28079b.go": true, // types2 reports follow-on errors
+ "fixedbugs/issue28268.go": true, // types2 reports follow-on errors
+ "fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error
+ "fixedbugs/issue41575.go": true, // types2 reports alternative positions in separate error
+ "fixedbugs/issue42058a.go": true, // types2 doesn't report "channel element type too large"
+ "fixedbugs/issue42058b.go": true, // types2 doesn't report "channel element type too large"
+ "fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors
+ "fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors
+ "fixedbugs/issue5609.go": true, // types2 needs a better error message
+ "fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow
+ "fixedbugs/issue7525.go": true, // types2 reports init cycle error on different line - ok otherwise
+ "fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise
+ "fixedbugs/issue7525c.go": true, // types2 reports init cycle error on different line - ok otherwise
+ "fixedbugs/issue7525d.go": true, // types2 reports init cycle error on different line - ok otherwise
+ "fixedbugs/issue7525e.go": true, // types2 reports init cycle error on different line - ok otherwise
+ "fixedbugs/issue46749.go": true, // types2 reports can not convert error instead of type mismatched
+}