3 // Copyright 2012 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Run runs tests in the test directory.
34 verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.")
35 keep = flag.Bool("k", false, "keep. keep temporary directory.")
36 numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
37 summary = flag.Bool("summary", false, "show summary of results")
38 allCodegen = flag.Bool("all_codegen", defaultAllCodeGen(), "run all goos/goarch for codegen")
39 showSkips = flag.Bool("show_skips", false, "show skipped tests")
40 runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)")
41 linkshared = flag.Bool("linkshared", false, "")
42 updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output")
43 runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run")
45 shard = flag.Int("shard", 0, "shard index to run. Only applicable if -shards is non-zero.")
46 shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.")
49 // defaultAllCodeGen returns the default value of the -all_codegen
50 // flag. By default, we prefer to be fast (returning false), except on
51 // the linux-amd64 builder that's already very fast, so we get more
52 // test coverage on trybots. See https://golang.org/issue/34297.
53 func defaultAllCodeGen() bool {
54 return os.Getenv("GO_BUILDER_NAME") == "linux-amd64"
60 // dirs are the directories to look for *.go files in.
61 // TODO(bradfitz): just use all directories?
62 dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam"}
64 // ratec controls the max number of tests running at a time.
67 // toRun is the channel of tests to run.
68 // It is nil until the first test is started.
71 // rungatec controls the max number of runoutput tests
72 // executed in parallel as they can each consume a lot of memory.
76 // maxTests is an upper bound on the total number of tests.
77 // It is used as a channel buffer size to make sure sends don't block.
83 goos = getenv("GOOS", runtime.GOOS)
84 goarch = getenv("GOARCH", runtime.GOARCH)
88 // Disable parallelism if printing or if using a simulator.
89 if *verbose || len(findExecCmd()) > 0 {
94 ratec = make(chan bool, *numParallel)
95 rungatec = make(chan bool, *runoutputLimit)
99 for _, arg := range flag.Args() {
100 if arg == "-" || arg == "--" {
102 // $ go run run.go - env.go
103 // $ go run run.go -- env.go
104 // $ go run run.go - ./fixedbugs
105 // $ go run run.go -- ./fixedbugs
108 if fi, err := os.Stat(arg); err == nil && fi.IsDir() {
109 for _, baseGoFile := range goFiles(arg) {
110 tests = append(tests, startTest(arg, baseGoFile))
112 } else if strings.HasSuffix(arg, ".go") {
113 dir, file := filepath.Split(arg)
114 tests = append(tests, startTest(dir, file))
116 log.Fatalf("can't yet deal with non-directory and non-go file %q", arg)
120 for _, dir := range dirs {
121 for _, baseGoFile := range goFiles(dir) {
122 tests = append(tests, startTest(dir, baseGoFile))
128 resCount := map[string]int{}
129 for _, test := range tests {
133 if e, isSkip := test.err.(skipError); isSkip {
135 errStr = "unexpected skip for " + path.Join(test.dir, test.gofile) + ": " + string(e)
140 errStr = test.err.Error()
142 if status == "FAIL" {
146 dt := fmt.Sprintf("%.3fs", test.dt.Seconds())
147 if status == "FAIL" {
148 fmt.Printf("# go run run.go -- %s\n%s\nFAIL\t%s\t%s\n",
149 path.Join(test.dir, test.gofile),
150 errStr, test.goFileName(), dt)
156 fmt.Printf("%s\t%s\t%s\n", status, test.goFileName(), dt)
160 for k, v := range resCount {
161 fmt.Printf("%5d %s\n", v, k)
170 // goTool reports the path of the go tool to use to run the tests.
171 // If possible, use the same Go used to run run.go, otherwise
172 // fallback to the go version found in the PATH.
173 func goTool() string {
175 if runtime.GOOS == "windows" {
178 path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
179 if _, err := os.Stat(path); err == nil {
182 // Just run "go" from PATH
186 func shardMatch(name string) bool {
191 io.WriteString(h, name)
192 return int(h.Sum32()%uint32(*shards)) == *shard
195 func goFiles(dir string) []string {
196 f, err := os.Open(dir)
200 dirnames, err := f.Readdirnames(-1)
206 for _, name := range dirnames {
207 if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") && shardMatch(name) {
208 names = append(names, name)
215 type runCmd func(...string) ([]byte, error)
217 func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
218 cmd := []string{goTool(), "tool", "compile", "-e"}
219 cmd = append(cmd, flags...)
221 cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
223 cmd = append(cmd, longname)
224 return runcmd(cmd...)
227 func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) {
228 cmd := []string{goTool(), "tool", "compile", "-e"}
230 // Set relative path for local imports and import search path to current dir.
231 cmd = append(cmd, "-D", ".", "-I", ".")
233 cmd = append(cmd, flags...)
235 cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
237 for _, name := range names {
238 cmd = append(cmd, filepath.Join(dir, name))
240 return runcmd(cmd...)
243 func linkFile(runcmd runCmd, goname string, ldflags []string) (err error) {
244 pfile := strings.Replace(goname, ".go", ".o", -1)
245 cmd := []string{goTool(), "tool", "link", "-w", "-o", "a.exe", "-L", "."}
247 cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
250 cmd = append(cmd, ldflags...)
252 cmd = append(cmd, pfile)
253 _, err = runcmd(cmd...)
257 // skipError describes why a test was skipped.
258 type skipError string
260 func (s skipError) Error() string { return string(s) }
262 // test holds the state of a test.
265 donec chan bool // closed when done
275 func startTest(dir, gofile string) *test {
279 donec: make(chan bool, 1),
282 toRun = make(chan *test, maxTests)
288 panic("toRun buffer size (maxTests) is too small")
293 // runTests runs tests in parallel, but respecting the order they
294 // were enqueued on the toRun channel.
306 var cwd, _ = os.Getwd()
308 func (t *test) goFileName() string {
309 return filepath.Join(t.dir, t.gofile)
312 func (t *test) goDirName() string {
313 return filepath.Join(t.dir, strings.Replace(t.gofile, ".go", ".dir", -1))
316 func goDirFiles(longdir string) (filter []os.FileInfo, err error) {
317 files, dirErr := ioutil.ReadDir(longdir)
321 for _, gofile := range files {
322 if filepath.Ext(gofile.Name()) == ".go" {
323 filter = append(filter, gofile)
329 var packageRE = regexp.MustCompile(`(?m)^package ([\p{Lu}\p{Ll}\w]+)`)
331 func getPackageNameFromSource(fn string) (string, error) {
332 data, err := ioutil.ReadFile(fn)
336 pkgname := packageRE.FindStringSubmatch(string(data))
338 return "", fmt.Errorf("cannot find package name in %s", fn)
340 return pkgname[1], nil
343 // If singlefilepkgs is set, each file is considered a separate package
344 // even if the package names are the same.
345 func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) {
346 files, err := goDirFiles(longdir)
351 m := make(map[string]int)
352 for _, file := range files {
354 pkgname, err := getPackageNameFromSource(filepath.Join(longdir, name))
359 if singlefilepkgs || !ok {
361 pkgs = append(pkgs, nil)
364 pkgs[i] = append(pkgs[i], name)
369 type context struct {
375 // shouldTest looks for build tags in a source file and returns
376 // whether the file should be used according to the tags.
377 func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
381 for _, line := range strings.Split(src, "\n") {
382 line = strings.TrimSpace(line)
383 if strings.HasPrefix(line, "//") {
388 line = strings.TrimSpace(line)
389 if len(line) == 0 || line[0] != '+' {
392 gcFlags := os.Getenv("GO_GCFLAGS")
396 noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
399 words := strings.Fields(line)
400 if words[0] == "+build" {
402 for _, word := range words[1:] {
403 if ctxt.match(word) {
409 // no matching tag found.
418 func (ctxt *context) match(name string) bool {
422 if i := strings.Index(name, ","); i >= 0 {
423 // comma-separated list
424 return ctxt.match(name[:i]) && ctxt.match(name[i+1:])
426 if strings.HasPrefix(name, "!!") { // bad syntax, reject always
429 if strings.HasPrefix(name, "!") { // negation
430 return len(name) > 1 && !ctxt.match(name[1:])
433 // Tags must be letters, digits, underscores or dots.
434 // Unlike in Go identifiers, all digits are fine (e.g., "386").
435 for _, c := range name {
436 if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' {
441 if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" {
445 if ctxt.noOptEnv && name == "gcflags_noopt" {
449 if name == "test_run" {
456 func init() { checkShouldTest() }
458 // goGcflags returns the -gcflags argument to use with go build / go run.
459 // This must match the flags used for building the standard library,
460 // or else the commands will rebuild any needed packages (like runtime)
462 func goGcflags() string {
463 return "-gcflags=all=" + os.Getenv("GO_GCFLAGS")
466 func goGcflagsIsEmpty() bool {
467 return "" == os.Getenv("GO_GCFLAGS")
470 var errTimeout = errors.New("command exceeded time limit")
473 func (t *test) run() {
476 t.dt = time.Since(start)
480 srcBytes, err := ioutil.ReadFile(t.goFileName())
485 t.src = string(srcBytes)
486 if t.src[0] == '\n' {
487 t.err = skipError("starts with newline")
491 // Execution recipe stops at first blank line.
492 pos := strings.Index(t.src, "\n\n")
494 t.err = fmt.Errorf("double newline ending execution recipe not found in %s", t.goFileName())
497 action := t.src[:pos]
498 if nl := strings.Index(action, "\n"); nl >= 0 && strings.Contains(action[:nl], "+build") {
500 action = action[nl+1:]
502 action = strings.TrimPrefix(action, "//")
504 // Check for build constraints only up to the actual code.
505 pkgPos := strings.Index(t.src, "\npackage")
507 pkgPos = pos // some files are intentionally malformed
509 if ok, why := shouldTest(t.src[:pkgPos], goos, goarch); !ok {
511 fmt.Printf("%-20s %-20s: %s\n", "skip", t.goFileName(), why)
516 var args, flags []string
520 singlefilepkgs := false
523 f := strings.Fields(action)
529 // TODO: Clean up/simplify this switch statement.
531 case "compile", "compiledir", "build", "builddir", "buildrundir", "run", "buildrun", "runoutput", "rundir", "runindir", "asmcheck":
533 case "errorcheckandrundir":
534 wantError = false // should be no error if also will run
535 case "errorcheckwithauto":
536 action = "errorcheck"
539 case "errorcheck", "errorcheckdir", "errorcheckoutput":
547 t.err = skipError("skipped; unknown pattern: " + action)
552 for len(args) > 0 && strings.HasPrefix(args[0], "-") {
559 singlefilepkgs = true
563 // Do not set relative path for local imports to current dir,
564 // e.g. do not pass -D . -I . to the compiler.
565 // Used in fixedbugs/bug345.go to allow compilation and import of local pkg.
566 // See golang.org/issue/25635
568 case "-t": // timeout in seconds
571 tim, err = strconv.Atoi(args[0])
573 t.err = fmt.Errorf("need number of seconds for -t timeout, got %s instead", args[0])
577 flags = append(flags, args[0])
581 if action == "errorcheck" {
583 for i, f := range flags {
584 if strings.HasPrefix(f, "-d=") {
585 flags[i] = f + ",ssa/check/on"
591 flags = append(flags, "-d=ssa/check/on")
597 defer os.RemoveAll(t.tempDir)
600 err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
605 // A few tests (of things like the environment) require these to be set.
606 if os.Getenv("GOOS") == "" {
607 os.Setenv("GOOS", runtime.GOOS)
609 if os.Getenv("GOARCH") == "" {
610 os.Setenv("GOARCH", runtime.GOARCH)
615 tempDirIsGOPATH = false
617 runcmd := func(args ...string) ([]byte, error) {
618 cmd := exec.Command(args[0], args[1:]...)
622 cmd.Env = append(os.Environ(), "GOENV=off", "GOFLAGS=")
625 // Set PWD to match Dir to speed up os.Getwd in the child process.
626 cmd.Env = append(cmd.Env, "PWD="+cmd.Dir)
629 cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
636 // This command-timeout code adapted from cmd/go/test.go
638 tick := time.NewTimer(time.Duration(tim) * time.Second)
639 done := make(chan error)
647 cmd.Process.Signal(os.Interrupt)
648 time.Sleep(1 * time.Second)
658 if err != nil && err != errTimeout {
659 err = fmt.Errorf("%s\n%s", err, buf.Bytes())
661 return buf.Bytes(), err
664 long := filepath.Join(cwd, t.goFileName())
667 t.err = fmt.Errorf("unimplemented action %q", action)
670 // Compile Go file and match the generated assembly
671 // against a set of regexps in comments.
672 ops := t.wantedAsmOpcodes(long)
673 self := runtime.GOOS + "/" + runtime.GOARCH
674 for _, env := range ops.Envs() {
675 // Only run checks relevant to the current GOOS/GOARCH,
676 // to avoid triggering a cross-compile of the runtime.
677 if string(env) != self && !strings.HasPrefix(string(env), self+"/") && !*allCodegen {
680 // -S=2 forces outermost line numbers when disassembling inlined code.
681 cmdline := []string{"build", "-gcflags", "-S=2"}
683 // Append flags, but don't override -gcflags=-S=2; add to it instead.
684 for i := 0; i < len(flags); i++ {
687 case strings.HasPrefix(flag, "-gcflags="):
688 cmdline[2] += " " + strings.TrimPrefix(flag, "-gcflags=")
689 case strings.HasPrefix(flag, "--gcflags="):
690 cmdline[2] += " " + strings.TrimPrefix(flag, "--gcflags=")
691 case flag == "-gcflags", flag == "--gcflags":
694 cmdline[2] += " " + flags[i]
697 cmdline = append(cmdline, flag)
701 cmdline = append(cmdline, long)
702 cmd := exec.Command(goTool(), cmdline...)
703 cmd.Env = append(os.Environ(), env.Environ()...)
704 if len(flags) > 0 && flags[0] == "-race" {
705 cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
709 cmd.Stdout, cmd.Stderr = &buf, &buf
710 if err := cmd.Run(); err != nil {
711 fmt.Println(env, "\n", cmd.Stderr)
716 t.err = t.asmCheck(buf.String(), long, env, ops[env])
725 // Fail if wantError is true and compilation was successful and vice versa.
726 // Match errors produced by gc against errors in comments.
727 // TODO(gri) remove need for -C (disable printing of columns in error messages)
728 cmdline := []string{goTool(), "tool", "compile", "-C", "-e", "-o", "a.o"}
729 // No need to add -dynlink even if linkshared if we're just checking for errors...
730 cmdline = append(cmdline, flags...)
731 cmdline = append(cmdline, long)
732 out, err := runcmd(cmdline...)
735 t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
738 if err == errTimeout {
739 t.err = fmt.Errorf("compilation timed out")
749 t.updateErrors(string(out), long)
751 t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
753 return // don't hide error if run below succeeds
756 // The following is temporary scaffolding to get types2 typechecker
757 // up and running against the existing test cases. The explicitly
758 // listed files don't pass yet, usually because the error messages
759 // are slightly different (this list is not complete). Any errorcheck
760 // tests that require output from analysis phases past intial type-
761 // checking are also excluded since these phases are not running yet.
762 // We can get rid of this code once types2 is fully plugged in.
764 // For now we're done when we can't handle the file or some of the flags.
765 // The first goal is to eliminate the excluded list; the second goal is to
766 // eliminate the flag list.
769 filename := strings.Replace(t.goFileName(), "\\", "/", -1) // goFileName() uses \ on Windows
770 if excluded[filename] {
772 fmt.Printf("excl\t%s\n", filename)
774 return // cannot handle file yet
778 for _, flag := range flags {
779 for _, pattern := range []string{
782 if strings.Contains(flag, pattern) {
784 fmt.Printf("excl\t%s\t%s\n", filename, flags)
786 return // cannot handle flag
791 // Run errorcheck again with -G option (new typechecker).
792 cmdline = []string{goTool(), "tool", "compile", "-G=3", "-C", "-e", "-o", "a.o"}
793 // No need to add -dynlink even if linkshared if we're just checking for errors...
794 cmdline = append(cmdline, flags...)
795 cmdline = append(cmdline, long)
796 out, err = runcmd(cmdline...)
799 t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
809 t.updateErrors(string(out), long)
811 t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
815 _, t.err = compileFile(runcmd, long, flags)
818 // Compile all files in the directory as packages in lexicographic order.
819 longdir := filepath.Join(cwd, t.goDirName())
820 pkgs, err := goDirPackages(longdir, singlefilepkgs)
825 for _, gofiles := range pkgs {
826 _, t.err = compileInDir(runcmd, longdir, flags, localImports, gofiles...)
832 case "errorcheckdir", "errorcheckandrundir":
833 // Compile and errorCheck all files in the directory as packages in lexicographic order.
834 // If errorcheckdir and wantError, compilation of the last package must fail.
835 // If errorcheckandrundir and wantError, compilation of the package prior the last must fail.
836 longdir := filepath.Join(cwd, t.goDirName())
837 pkgs, err := goDirPackages(longdir, singlefilepkgs)
842 errPkg := len(pkgs) - 1
843 if wantError && action == "errorcheckandrundir" {
844 // The last pkg should compiled successfully and will be run in next case.
845 // Preceding pkg must return an error from compileInDir.
848 for i, gofiles := range pkgs {
849 out, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
851 if wantError && err == nil {
852 t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
854 } else if !wantError && err != nil {
858 } else if err != nil {
862 var fullshort []string
863 for _, name := range gofiles {
864 fullshort = append(fullshort, filepath.Join(longdir, name), name)
866 t.err = t.errorCheck(string(out), wantAuto, fullshort...)
871 if action == "errorcheckdir" {
877 // Compile all files in the directory as packages in lexicographic order.
878 // In case of errorcheckandrundir, ignore failed compilation of the package before the last.
879 // Link as if the last file is the main package, run it.
880 // Verify the expected output.
881 longdir := filepath.Join(cwd, t.goDirName())
882 pkgs, err := goDirPackages(longdir, singlefilepkgs)
887 // Split flags into gcflags and ldflags
888 ldflags := []string{}
889 for i, fl := range flags {
890 if fl == "-ldflags" {
891 ldflags = flags[i+1:]
897 for i, gofiles := range pkgs {
899 pflags = append(pflags, flags...)
901 fp := filepath.Join(longdir, gofiles[0])
902 pkgname, err := getPackageNameFromSource(fp)
906 pflags = append(pflags, "-p", pkgname)
908 _, err := compileInDir(runcmd, longdir, pflags, localImports, gofiles...)
909 // Allow this package compilation fail based on conditions below;
910 // its errors were checked in previous case.
911 if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
915 if i == len(pkgs)-1 {
916 err = linkFile(runcmd, gofiles[0], ldflags)
922 cmd = append(cmd, findExecCmd()...)
923 cmd = append(cmd, filepath.Join(t.tempDir, "a.exe"))
924 cmd = append(cmd, args...)
925 out, err := runcmd(cmd...)
930 t.checkExpectedOutput(out)
935 // Make a shallow copy of t.goDirName() in its own module and GOPATH, and
936 // run "go run ." in it. The module path (and hence import path prefix) of
937 // the copy is equal to the basename of the source directory.
939 // It's used when test a requires a full 'go build' in order to compile
940 // the sources, such as when importing multiple packages (issue29612.dir)
941 // or compiling a package containing assembly files (see issue15609.dir),
942 // but still needs to be run to verify the expected output.
943 tempDirIsGOPATH = true
944 srcDir := t.goDirName()
945 modName := filepath.Base(srcDir)
946 gopathSrcDir := filepath.Join(t.tempDir, "src", modName)
947 runInDir = gopathSrcDir
949 if err := overlayDir(gopathSrcDir, srcDir); err != nil {
954 modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName)
955 if err := ioutil.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil {
960 cmd := []string{goTool(), "run", goGcflags()}
962 cmd = append(cmd, "-linkshared")
964 cmd = append(cmd, flags...)
965 cmd = append(cmd, ".")
966 out, err := runcmd(cmd...)
971 t.checkExpectedOutput(out)
975 _, err := runcmd(goTool(), "build", goGcflags(), "-o", "a.exe", long)
980 case "builddir", "buildrundir":
981 // Build an executable from all the .go and .s files in a subdirectory.
982 // Run it and verify its output in the buildrundir case.
983 longdir := filepath.Join(cwd, t.goDirName())
984 files, dirErr := ioutil.ReadDir(longdir)
991 for _, file := range files {
992 switch filepath.Ext(file.Name()) {
994 gos = append(gos, filepath.Join(longdir, file.Name()))
996 asms = append(asms, filepath.Join(longdir, file.Name()))
1001 emptyHdrFile := filepath.Join(t.tempDir, "go_asm.h")
1002 if err := ioutil.WriteFile(emptyHdrFile, nil, 0666); err != nil {
1003 t.err = fmt.Errorf("write empty go_asm.h: %s", err)
1006 cmd := []string{goTool(), "tool", "asm", "-gensymabis", "-o", "symabis"}
1007 cmd = append(cmd, asms...)
1008 _, err = runcmd(cmd...)
1015 cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"}
1017 cmd = append(cmd, "-asmhdr", "go_asm.h", "-symabis", "symabis")
1019 cmd = append(cmd, gos...)
1020 _, err := runcmd(cmd...)
1025 objs = append(objs, "go.o")
1027 cmd = []string{goTool(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"}
1028 cmd = append(cmd, asms...)
1029 _, err = runcmd(cmd...)
1034 objs = append(objs, "asm.o")
1036 cmd = []string{goTool(), "tool", "pack", "c", "all.a"}
1037 cmd = append(cmd, objs...)
1038 _, err = runcmd(cmd...)
1043 cmd = []string{goTool(), "tool", "link", "-o", "a.exe", "all.a"}
1044 _, err = runcmd(cmd...)
1049 if action == "buildrundir" {
1050 cmd = append(findExecCmd(), filepath.Join(t.tempDir, "a.exe"))
1051 out, err := runcmd(cmd...)
1056 t.checkExpectedOutput(out)
1060 // Build an executable from Go file, then run it, verify its output.
1061 // Useful for timeout tests where failure mode is infinite loop.
1062 // TODO: not supported on NaCl
1063 cmd := []string{goTool(), "build", goGcflags(), "-o", "a.exe"}
1065 cmd = append(cmd, "-linkshared")
1067 longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile)
1068 cmd = append(cmd, flags...)
1069 cmd = append(cmd, longdirgofile)
1070 _, err := runcmd(cmd...)
1075 cmd = []string{"./a.exe"}
1076 out, err := runcmd(append(cmd, args...)...)
1082 t.checkExpectedOutput(out)
1085 // Run Go file if no special go command flags are provided;
1086 // otherwise build an executable and run it.
1087 // Verify the output.
1091 if len(flags)+len(args) == 0 && goGcflagsIsEmpty() && !*linkshared && goarch == runtime.GOARCH && goos == runtime.GOOS {
1092 // If we're not using special go command flags,
1093 // skip all the go command machinery.
1094 // This avoids any time the go command would
1095 // spend checking whether, for example, the installed
1096 // package runtime is up to date.
1097 // Because we run lots of trivial test programs,
1098 // the time adds up.
1099 pkg := filepath.Join(t.tempDir, "pkg.a")
1100 if _, err := runcmd(goTool(), "tool", "compile", "-o", pkg, t.goFileName()); err != nil {
1104 exe := filepath.Join(t.tempDir, "test.exe")
1105 cmd := []string{goTool(), "tool", "link", "-s", "-w"}
1106 cmd = append(cmd, "-o", exe, pkg)
1107 if _, err := runcmd(cmd...); err != nil {
1111 out, err = runcmd(append([]string{exe}, args...)...)
1113 cmd := []string{goTool(), "run", goGcflags()}
1115 cmd = append(cmd, "-linkshared")
1117 cmd = append(cmd, flags...)
1118 cmd = append(cmd, t.goFileName())
1119 out, err = runcmd(append(cmd, args...)...)
1125 t.checkExpectedOutput(out)
1128 // Run Go file and write its output into temporary Go file.
1129 // Run generated Go file and verify its output.
1135 cmd := []string{goTool(), "run", goGcflags()}
1137 cmd = append(cmd, "-linkshared")
1139 cmd = append(cmd, t.goFileName())
1140 out, err := runcmd(append(cmd, args...)...)
1145 tfile := filepath.Join(t.tempDir, "tmp__.go")
1146 if err := ioutil.WriteFile(tfile, out, 0666); err != nil {
1147 t.err = fmt.Errorf("write tempfile:%s", err)
1150 cmd = []string{goTool(), "run", goGcflags()}
1152 cmd = append(cmd, "-linkshared")
1154 cmd = append(cmd, tfile)
1155 out, err = runcmd(cmd...)
1160 t.checkExpectedOutput(out)
1162 case "errorcheckoutput":
1163 // Run Go file and write its output into temporary Go file.
1164 // Compile and errorCheck generated Go file.
1166 cmd := []string{goTool(), "run", goGcflags()}
1168 cmd = append(cmd, "-linkshared")
1170 cmd = append(cmd, t.goFileName())
1171 out, err := runcmd(append(cmd, args...)...)
1176 tfile := filepath.Join(t.tempDir, "tmp__.go")
1177 err = ioutil.WriteFile(tfile, out, 0666)
1179 t.err = fmt.Errorf("write tempfile:%s", err)
1182 cmdline := []string{goTool(), "tool", "compile", "-e", "-o", "a.o"}
1183 cmdline = append(cmdline, flags...)
1184 cmdline = append(cmdline, tfile)
1185 out, err = runcmd(cmdline...)
1188 t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
1197 t.err = t.errorCheck(string(out), false, tfile, "tmp__.go")
1202 var execCmd []string
1204 func findExecCmd() []string {
1208 execCmd = []string{} // avoid work the second time
1209 if goos == runtime.GOOS && goarch == runtime.GOARCH {
1212 path, err := exec.LookPath(fmt.Sprintf("go_%s_%s_exec", goos, goarch))
1214 execCmd = []string{path}
1219 func (t *test) String() string {
1220 return filepath.Join(t.dir, t.gofile)
1223 func (t *test) makeTempDir() {
1225 t.tempDir, err = ioutil.TempDir("", "")
1230 log.Printf("Temporary directory is %s", t.tempDir)
1234 // checkExpectedOutput compares the output from compiling and/or running with the contents
1235 // of the corresponding reference output file, if any (replace ".go" with ".out").
1236 // If they don't match, fail with an informative message.
1237 func (t *test) checkExpectedOutput(gotBytes []byte) {
1238 got := string(gotBytes)
1239 filename := filepath.Join(t.dir, t.gofile)
1240 filename = filename[:len(filename)-len(".go")]
1242 b, err := ioutil.ReadFile(filename)
1243 // File is allowed to be missing (err != nil) in which case output should be empty.
1244 got = strings.Replace(got, "\r\n", "\n", -1)
1245 if got != string(b) {
1247 t.err = fmt.Errorf("output does not match expected in %s. Instead saw\n%s", filename, got)
1249 t.err = fmt.Errorf("output should be empty when (optional) expected-output file %s is not present. Instead saw\n%s", filename, got)
1254 func splitOutput(out string, wantAuto bool) []string {
1255 // gc error messages continue onto additional lines with leading tabs.
1256 // Split the output at the beginning of each line that doesn't begin with a tab.
1257 // <autogenerated> lines are impossible to match so those are filtered out.
1259 for _, line := range strings.Split(out, "\n") {
1260 if strings.HasSuffix(line, "\r") { // remove '\r', output by compiler on windows
1261 line = line[:len(line)-1]
1263 if strings.HasPrefix(line, "\t") {
1264 res[len(res)-1] += "\n" + line
1265 } else if strings.HasPrefix(line, "go tool") || strings.HasPrefix(line, "#") || !wantAuto && strings.HasPrefix(line, "<autogenerated>") {
1267 } else if strings.TrimSpace(line) != "" {
1268 res = append(res, line)
1274 // errorCheck matches errors in outStr against comments in source files.
1275 // For each line of the source files which should generate an error,
1276 // there should be a comment of the form // ERROR "regexp".
1277 // If outStr has an error for a line which has no such comment,
1278 // this function will report an error.
1279 // Likewise if outStr does not have an error for a line which has a comment,
1280 // or if the error message does not match the <regexp>.
1281 // The <regexp> syntax is Perl but it's best to stick to egrep.
1283 // Sources files are supplied as fullshort slice.
1284 // It consists of pairs: full path to source file and its base name.
1285 func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err error) {
1287 if *verbose && err != nil {
1288 log.Printf("%s gc output:\n%s", t, outStr)
1292 out := splitOutput(outStr, wantAuto)
1294 // Cut directory name.
1295 for i := range out {
1296 for j := 0; j < len(fullshort); j += 2 {
1297 full, short := fullshort[j], fullshort[j+1]
1298 out[i] = strings.Replace(out[i], full, short, -1)
1302 var want []wantedError
1303 for j := 0; j < len(fullshort); j += 2 {
1304 full, short := fullshort[j], fullshort[j+1]
1305 want = append(want, t.wantedErrors(full, short)...)
1308 for _, we := range want {
1309 var errmsgs []string
1311 errmsgs, out = partitionStrings("<autogenerated>", out)
1313 errmsgs, out = partitionStrings(we.prefix, out)
1315 if len(errmsgs) == 0 {
1316 errs = append(errs, fmt.Errorf("%s:%d: missing error %q", we.file, we.lineNum, we.reStr))
1321 for _, errmsg := range errmsgs {
1322 // Assume errmsg says "file:line: foo".
1323 // Cut leading "file:line: " to avoid accidental matching of file name instead of message.
1325 if i := strings.Index(text, " "); i >= 0 {
1328 if we.re.MatchString(text) {
1331 out = append(out, errmsg)
1335 errs = append(errs, fmt.Errorf("%s:%d: no match for %#q in:\n\t%s", we.file, we.lineNum, we.reStr, strings.Join(out[n:], "\n\t")))
1341 errs = append(errs, fmt.Errorf("Unmatched Errors:"))
1342 for _, errLine := range out {
1343 errs = append(errs, fmt.Errorf("%s", errLine))
1353 var buf bytes.Buffer
1354 fmt.Fprintf(&buf, "\n")
1355 for _, err := range errs {
1356 fmt.Fprintf(&buf, "%s\n", err.Error())
1358 return errors.New(buf.String())
1361 func (t *test) updateErrors(out, file string) {
1362 base := path.Base(file)
1363 // Read in source file.
1364 src, err := ioutil.ReadFile(file)
1366 fmt.Fprintln(os.Stderr, err)
1369 lines := strings.Split(string(src), "\n")
1370 // Remove old errors.
1371 for i, ln := range lines {
1372 pos := strings.Index(ln, " // ERROR ")
1377 // Parse new errors.
1378 errors := make(map[int]map[string]bool)
1379 tmpRe := regexp.MustCompile(`autotmp_[0-9]+`)
1380 for _, errStr := range splitOutput(out, false) {
1381 colon1 := strings.Index(errStr, ":")
1382 if colon1 < 0 || errStr[:colon1] != file {
1385 colon2 := strings.Index(errStr[colon1+1:], ":")
1389 colon2 += colon1 + 1
1390 line, err := strconv.Atoi(errStr[colon1+1 : colon2])
1392 if err != nil || line < 0 || line >= len(lines) {
1395 msg := errStr[colon2+2:]
1396 msg = strings.Replace(msg, file, base, -1) // normalize file mentions in error itself
1397 msg = strings.TrimLeft(msg, " \t")
1398 for _, r := range []string{`\`, `*`, `+`, `?`, `[`, `]`, `(`, `)`} {
1399 msg = strings.Replace(msg, r, `\`+r, -1)
1401 msg = strings.Replace(msg, `"`, `.`, -1)
1402 msg = tmpRe.ReplaceAllLiteralString(msg, `autotmp_[0-9]+`)
1403 if errors[line] == nil {
1404 errors[line] = make(map[string]bool)
1406 errors[line][msg] = true
1409 for line, errs := range errors {
1411 for e := range errs {
1412 sorted = append(sorted, e)
1414 sort.Strings(sorted)
1415 lines[line] += " // ERROR"
1416 for _, e := range sorted {
1417 lines[line] += fmt.Sprintf(` "%s$"`, e)
1421 err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640)
1423 fmt.Fprintln(os.Stderr, err)
1427 exec.Command(goTool(), "fmt", file).CombinedOutput()
1430 // matchPrefix reports whether s is of the form ^(.*/)?prefix(:|[),
1431 // That is, it needs the file name prefix followed by a : or a [,
1432 // and possibly preceded by a directory name.
1433 func matchPrefix(s, prefix string) bool {
1434 i := strings.Index(s, ":")
1438 j := strings.LastIndex(s[:i], "/")
1440 if len(s) <= len(prefix) || s[:len(prefix)] != prefix {
1443 switch s[len(prefix)] {
1450 func partitionStrings(prefix string, strs []string) (matched, unmatched []string) {
1451 for _, s := range strs {
1452 if matchPrefix(s, prefix) {
1453 matched = append(matched, s)
1455 unmatched = append(unmatched, s)
1461 type wantedError struct {
1465 auto bool // match <autogenerated> line
1471 errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
1472 errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
1473 errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
1474 lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
1477 func (t *test) wantedErrors(file, short string) (errs []wantedError) {
1478 cache := make(map[string]*regexp.Regexp)
1480 src, _ := ioutil.ReadFile(file)
1481 for i, line := range strings.Split(string(src), "\n") {
1483 if strings.Contains(line, "////") {
1484 // double comment disables ERROR
1488 m := errAutoRx.FindStringSubmatch(line)
1492 m = errRx.FindStringSubmatch(line)
1498 mm := errQuotesRx.FindAllStringSubmatch(all, -1)
1500 log.Fatalf("%s:%d: invalid errchk line: %s", t.goFileName(), lineNum, line)
1502 for _, m := range mm {
1503 rx := lineRx.ReplaceAllStringFunc(m[1], func(m string) string {
1505 if strings.HasPrefix(m, "LINE+") {
1506 delta, _ := strconv.Atoi(m[5:])
1508 } else if strings.HasPrefix(m, "LINE-") {
1509 delta, _ := strconv.Atoi(m[5:])
1512 return fmt.Sprintf("%s:%d", short, n)
1517 re, err = regexp.Compile(rx)
1519 log.Fatalf("%s:%d: invalid regexp \"%s\" in ERROR line: %v", t.goFileName(), lineNum, rx, err)
1523 prefix := fmt.Sprintf("%s:%d", short, lineNum)
1524 errs = append(errs, wantedError{
1539 // Regexp to match a single opcode check: optionally begin with "-" (to indicate
1540 // a negative check), followed by a string literal enclosed in "" or ``. For "",
1541 // backslashes must be handled.
1542 reMatchCheck = `-?(?:\x60[^\x60]*\x60|"(?:[^"\\]|\\.)*")`
1546 // Regexp to split a line in code and comment, trimming spaces
1547 rxAsmComment = regexp.MustCompile(`^\s*(.*?)\s*(?://\s*(.+)\s*)?$`)
1549 // Regexp to extract an architecture check: architecture name (or triplet),
1550 // followed by semi-colon, followed by a comma-separated list of opcode checks.
1551 // Extraneous spaces are ignored.
1552 rxAsmPlatform = regexp.MustCompile(`(\w+)(/\w+)?(/\w*)?\s*:\s*(` + reMatchCheck + `(?:\s*,\s*` + reMatchCheck + `)*)`)
1554 // Regexp to extract a single opcoded check
1555 rxAsmCheck = regexp.MustCompile(reMatchCheck)
1557 // List of all architecture variants. Key is the GOARCH architecture,
1558 // value[0] is the variant-changing environment variable, and values[1:]
1559 // are the supported variants.
1560 archVariants = map[string][]string{
1561 "386": {"GO386", "sse2", "softfloat"},
1563 "arm": {"GOARM", "5", "6", "7"},
1565 "mips": {"GOMIPS", "hardfloat", "softfloat"},
1566 "mips64": {"GOMIPS64", "hardfloat", "softfloat"},
1567 "ppc64": {"GOPPC64", "power8", "power9"},
1568 "ppc64le": {"GOPPC64", "power8", "power9"},
1574 // wantedAsmOpcode is a single asmcheck check
1575 type wantedAsmOpcode struct {
1576 fileline string // original source file/line (eg: "/path/foo.go:45")
1577 line int // original source line
1578 opcode *regexp.Regexp // opcode check to be performed on assembly output
1579 negative bool // true if the check is supposed to fail rather than pass
1580 found bool // true if the opcode check matched at least one in the output
1583 // A build environment triplet separated by slashes (eg: linux/386/sse2).
1584 // The third field can be empty if the arch does not support variants (eg: "plan9/amd64/")
1585 type buildEnv string
1587 // Environ returns the environment it represents in cmd.Environ() "key=val" format
1588 // For instance, "linux/386/sse2".Environ() returns {"GOOS=linux", "GOARCH=386", "GO386=sse2"}
1589 func (b buildEnv) Environ() []string {
1590 fields := strings.Split(string(b), "/")
1591 if len(fields) != 3 {
1592 panic("invalid buildEnv string: " + string(b))
1594 env := []string{"GOOS=" + fields[0], "GOARCH=" + fields[1]}
1595 if fields[2] != "" {
1596 env = append(env, archVariants[fields[1]][0]+"="+fields[2])
1601 // asmChecks represents all the asmcheck checks present in a test file
1602 // The outer map key is the build triplet in which the checks must be performed.
1603 // The inner map key represent the source file line ("filename.go:1234") at which the
1604 // checks must be performed.
1605 type asmChecks map[buildEnv]map[string][]wantedAsmOpcode
1607 // Envs returns all the buildEnv in which at least one check is present
1608 func (a asmChecks) Envs() []buildEnv {
1611 envs = append(envs, e)
1613 sort.Slice(envs, func(i, j int) bool {
1614 return string(envs[i]) < string(envs[j])
1619 func (t *test) wantedAsmOpcodes(fn string) asmChecks {
1620 ops := make(asmChecks)
1623 src, _ := ioutil.ReadFile(fn)
1624 for i, line := range strings.Split(string(src), "\n") {
1625 matches := rxAsmComment.FindStringSubmatch(line)
1626 code, cmt := matches[1], matches[2]
1628 // Keep comments pending in the comment variable until
1629 // we find a line that contains some code.
1630 comment += " " + cmt
1635 // Parse and extract any architecture check from comments,
1636 // made by one architecture name and multiple checks.
1637 lnum := fn + ":" + strconv.Itoa(i+1)
1638 for _, ac := range rxAsmPlatform.FindAllStringSubmatch(comment, -1) {
1639 archspec, allchecks := ac[1:4], ac[4]
1641 var arch, subarch, os string
1643 case archspec[2] != "": // 3 components: "linux/386/sse2"
1644 os, arch, subarch = archspec[0], archspec[1][1:], archspec[2][1:]
1645 case archspec[1] != "": // 2 components: "386/sse2"
1646 os, arch, subarch = "linux", archspec[0], archspec[1][1:]
1647 default: // 1 component: "386"
1648 os, arch, subarch = "linux", archspec[0], ""
1654 if _, ok := archVariants[arch]; !ok {
1655 log.Fatalf("%s:%d: unsupported architecture: %v", t.goFileName(), i+1, arch)
1658 // Create the build environments corresponding the above specifiers
1659 envs := make([]buildEnv, 0, 4)
1661 envs = append(envs, buildEnv(os+"/"+arch+"/"+subarch))
1663 subarchs := archVariants[arch]
1664 if len(subarchs) == 0 {
1665 envs = append(envs, buildEnv(os+"/"+arch+"/"))
1667 for _, sa := range archVariants[arch][1:] {
1668 envs = append(envs, buildEnv(os+"/"+arch+"/"+sa))
1673 for _, m := range rxAsmCheck.FindAllString(allchecks, -1) {
1680 rxsrc, err := strconv.Unquote(m)
1682 log.Fatalf("%s:%d: error unquoting string: %v", t.goFileName(), i+1, err)
1685 // Compile the checks as regular expressions. Notice that we
1686 // consider checks as matching from the beginning of the actual
1687 // assembler source (that is, what is left on each line of the
1688 // compile -S output after we strip file/line info) to avoid
1689 // trivial bugs such as "ADD" matching "FADD". This
1690 // doesn't remove genericity: it's still possible to write
1691 // something like "F?ADD", but we make common cases simpler
1693 oprx, err := regexp.Compile("^" + rxsrc)
1695 log.Fatalf("%s:%d: %v", t.goFileName(), i+1, err)
1698 for _, env := range envs {
1699 if ops[env] == nil {
1700 ops[env] = make(map[string][]wantedAsmOpcode)
1702 ops[env][lnum] = append(ops[env][lnum], wantedAsmOpcode{
1717 func (t *test) asmCheck(outStr string, fn string, env buildEnv, fullops map[string][]wantedAsmOpcode) (err error) {
1718 // The assembly output contains the concatenated dump of multiple functions.
1719 // the first line of each function begins at column 0, while the rest is
1720 // indented by a tabulation. These data structures help us index the
1721 // output by function.
1722 functionMarkers := make([]int, 1)
1723 lineFuncMap := make(map[string]int)
1725 lines := strings.Split(outStr, "\n")
1726 rxLine := regexp.MustCompile(fmt.Sprintf(`\((%s:\d+)\)\s+(.*)`, regexp.QuoteMeta(fn)))
1728 for nl, line := range lines {
1729 // Check if this line begins a function
1730 if len(line) > 0 && line[0] != '\t' {
1731 functionMarkers = append(functionMarkers, nl)
1734 // Search if this line contains a assembly opcode (which is prefixed by the
1735 // original source file/line in parenthesis)
1736 matches := rxLine.FindStringSubmatch(line)
1737 if len(matches) == 0 {
1740 srcFileLine, asm := matches[1], matches[2]
1742 // Associate the original file/line information to the current
1743 // function in the output; it will be useful to dump it in case
1745 lineFuncMap[srcFileLine] = len(functionMarkers) - 1
1747 // If there are opcode checks associated to this source file/line,
1749 if ops, found := fullops[srcFileLine]; found {
1750 for i := range ops {
1751 if !ops[i].found && ops[i].opcode.FindString(asm) != "" {
1757 functionMarkers = append(functionMarkers, len(lines))
1759 var failed []wantedAsmOpcode
1760 for _, ops := range fullops {
1761 for _, o := range ops {
1762 // There's a failure if a negative match was found,
1763 // or a positive match was not found.
1764 if o.negative == o.found {
1765 failed = append(failed, o)
1769 if len(failed) == 0 {
1773 // At least one asmcheck failed; report them
1774 sort.Slice(failed, func(i, j int) bool {
1775 return failed[i].line < failed[j].line
1779 var errbuf bytes.Buffer
1780 fmt.Fprintln(&errbuf)
1781 for _, o := range failed {
1782 // Dump the function in which this opcode check was supposed to
1784 funcIdx := lineFuncMap[o.fileline]
1785 if funcIdx != 0 && funcIdx != lastFunction {
1786 funcLines := lines[functionMarkers[funcIdx]:functionMarkers[funcIdx+1]]
1787 log.Println(strings.Join(funcLines, "\n"))
1788 lastFunction = funcIdx // avoid printing same function twice
1792 fmt.Fprintf(&errbuf, "%s:%d: %s: wrong opcode found: %q\n", t.goFileName(), o.line, env, o.opcode.String())
1794 fmt.Fprintf(&errbuf, "%s:%d: %s: opcode not found: %q\n", t.goFileName(), o.line, env, o.opcode.String())
1797 err = errors.New(errbuf.String())
1801 // defaultRunOutputLimit returns the number of runoutput tests that
1802 // can be executed in parallel.
1803 func defaultRunOutputLimit() int {
1806 cpu := runtime.NumCPU()
1807 if runtime.GOARCH == "arm" && cpu > maxArmCPU {
1813 // checkShouldTest runs sanity checks on the shouldTest function.
1814 func checkShouldTest() {
1815 assert := func(ok bool, _ string) {
1820 assertNot := func(ok bool, _ string) { assert(!ok, "") }
1823 assert(shouldTest("// +build linux", "linux", "arm"))
1824 assert(shouldTest("// +build !windows", "linux", "arm"))
1825 assertNot(shouldTest("// +build !windows", "windows", "amd64"))
1827 // A file with no build tags will always be tested.
1828 assert(shouldTest("// This is a test.", "os", "arch"))
1830 // Build tags separated by a space are OR-ed together.
1831 assertNot(shouldTest("// +build arm 386", "linux", "amd64"))
1833 // Build tags separated by a comma are AND-ed together.
1834 assertNot(shouldTest("// +build !windows,!plan9", "windows", "amd64"))
1835 assertNot(shouldTest("// +build !windows,!plan9", "plan9", "386"))
1837 // Build tags on multiple lines are AND-ed together.
1838 assert(shouldTest("// +build !windows\n// +build amd64", "linux", "amd64"))
1839 assertNot(shouldTest("// +build !windows\n// +build amd64", "windows", "amd64"))
1841 // Test that (!a OR !b) matches anything.
1842 assert(shouldTest("// +build !windows !plan9", "windows", "amd64"))
1845 func getenv(key, def string) string {
1846 value := os.Getenv(key)
1853 // overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
1854 func overlayDir(dstRoot, srcRoot string) error {
1855 dstRoot = filepath.Clean(dstRoot)
1856 if err := os.MkdirAll(dstRoot, 0777); err != nil {
1860 srcRoot, err := filepath.Abs(srcRoot)
1865 return filepath.WalkDir(srcRoot, func(srcPath string, d fs.DirEntry, err error) error {
1866 if err != nil || srcPath == srcRoot {
1870 suffix := strings.TrimPrefix(srcPath, srcRoot)
1871 for len(suffix) > 0 && suffix[0] == filepath.Separator {
1874 dstPath := filepath.Join(dstRoot, suffix)
1876 var info fs.FileInfo
1877 if d.Type()&os.ModeSymlink != 0 {
1878 info, err = os.Stat(srcPath)
1880 info, err = d.Info()
1885 perm := info.Mode() & os.ModePerm
1887 // Always copy directories (don't symlink them).
1888 // If we add a file in the overlay, we don't want to add it in the original.
1890 return os.MkdirAll(dstPath, perm|0200)
1893 // If the OS supports symlinks, use them instead of copying bytes.
1894 if err := os.Symlink(srcPath, dstPath); err == nil {
1898 // Otherwise, copy the bytes.
1899 src, err := os.Open(srcPath)
1905 dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
1910 _, err = io.Copy(dst, src)
1911 if closeErr := dst.Close(); err == nil {
1918 // List of files that the compiler cannot errorcheck with the new typechecker (compiler -G option).
1919 // Temporary scaffolding until we pass all the tests at which point this map can be removed.
1920 var excluded = map[string]bool{
1921 "complit1.go": true, // types2 reports extra errors
1922 "const2.go": true, // types2 not run after syntax errors
1923 "ddd1.go": true, // issue #42987
1924 "directive.go": true, // misplaced compiler directive checks
1925 "float_lit3.go": true, // types2 reports extra errors
1926 "import1.go": true, // types2 reports extra errors
1927 "import5.go": true, // issue #42988
1928 "import6.go": true, // issue #43109
1929 "initializerr.go": true, // types2 reports extra errors
1930 "linkname2.go": true, // error reported by noder (not running for types2 errorcheck test)
1931 "notinheap.go": true, // types2 doesn't report errors about conversions that are invalid due to //go:notinheap
1932 "shift1.go": true, // issue #42989
1933 "typecheck.go": true, // invalid function is not causing errors when called
1934 "writebarrier.go": true, // correct diagnostics, but different lines (probably irgen's fault)
1936 "fixedbugs/bug176.go": true, // types2 reports all errors (pref: types2)
1937 "fixedbugs/bug193.go": true, // types2 bug: shift error not reported (fixed in go/types)
1938 "fixedbugs/bug195.go": true, // types2 reports slightly different (but correct) bugs
1939 "fixedbugs/bug228.go": true, // types2 not run after syntax errors
1940 "fixedbugs/bug231.go": true, // types2 bug? (same error reported twice)
1941 "fixedbugs/bug255.go": true, // types2 reports extra errors
1942 "fixedbugs/bug351.go": true, // types2 reports extra errors
1943 "fixedbugs/bug374.go": true, // types2 reports extra errors
1944 "fixedbugs/bug385_32.go": true, // types2 doesn't produce missing error "type .* too large" (32-bit specific)
1945 "fixedbugs/bug388.go": true, // types2 not run due to syntax errors
1946 "fixedbugs/bug412.go": true, // types2 produces a follow-on error
1948 "fixedbugs/issue11590.go": true, // types2 doesn't report a follow-on error (pref: types2)
1949 "fixedbugs/issue11610.go": true, // types2 not run after syntax errors
1950 "fixedbugs/issue11614.go": true, // types2 reports an extra error
1951 "fixedbugs/issue13415.go": true, // declared but not used conflict
1952 "fixedbugs/issue14520.go": true, // missing import path error by types2
1953 "fixedbugs/issue16428.go": true, // types2 reports two instead of one error
1954 "fixedbugs/issue17038.go": true, // types2 doesn't report a follow-on error (pref: types2)
1955 "fixedbugs/issue17645.go": true, // multiple errors on same line
1956 "fixedbugs/issue18331.go": true, // missing error about misuse of //go:noescape (irgen needs code from noder)
1957 "fixedbugs/issue18393.go": true, // types2 not run after syntax errors
1958 "fixedbugs/issue19012.go": true, // multiple errors on same line
1959 "fixedbugs/issue20233.go": true, // types2 reports two instead of one error (pref: compiler)
1960 "fixedbugs/issue20245.go": true, // types2 reports two instead of one error (pref: compiler)
1961 "fixedbugs/issue20250.go": true, // correct diagnostics, but different lines (probably irgen's fault)
1962 "fixedbugs/issue21979.go": true, // types2 doesn't report a follow-on error (pref: types2)
1963 "fixedbugs/issue23732.go": true, // types2 reports different (but ok) line numbers
1964 "fixedbugs/issue25958.go": true, // types2 doesn't report a follow-on error (pref: types2)
1965 "fixedbugs/issue28079b.go": true, // types2 reports follow-on errors
1966 "fixedbugs/issue28268.go": true, // types2 reports follow-on errors
1967 "fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error
1968 "fixedbugs/issue41575.go": true, // types2 reports alternative positions in separate error
1969 "fixedbugs/issue42058a.go": true, // types2 doesn't report "channel element type too large"
1970 "fixedbugs/issue42058b.go": true, // types2 doesn't report "channel element type too large"
1971 "fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors
1972 "fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors
1973 "fixedbugs/issue5609.go": true, // types2 needs a better error message
1974 "fixedbugs/issue6889.go": true, // types2 can handle this without constant overflow
1975 "fixedbugs/issue7525.go": true, // types2 reports init cycle error on different line - ok otherwise
1976 "fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise
1977 "fixedbugs/issue7525c.go": true, // types2 reports init cycle error on different line - ok otherwise
1978 "fixedbugs/issue7525d.go": true, // types2 reports init cycle error on different line - ok otherwise
1979 "fixedbugs/issue7525e.go": true, // types2 reports init cycle error on different line - ok otherwise