diff options
Diffstat (limited to 'go/patch/go2.patch')
-rw-r--r-- | go/patch/go2.patch | 256 |
1 files changed, 221 insertions, 35 deletions
diff --git a/go/patch/go2.patch b/go/patch/go2.patch index dfc236a4..20f04791 100644 --- a/go/patch/go2.patch +++ b/go/patch/go2.patch @@ -2,10 +2,15 @@ test: add -target flag. --- test/run.go +++ test/run.go -@@ -37,9 +37,9 @@ var ( +@@ -34,19 +34,19 @@ import ( + + var ( + verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.") + keep = flag.Bool("k", false, "keep. keep temporary directory.") numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run") summary = flag.Bool("summary", false, "show summary of results") showSkips = flag.Bool("show_skips", false, "show skipped tests") + runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)") - linkshared = flag.Bool("linkshared", false, "") updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output") runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run") @@ -13,29 +18,42 @@ test: add -target flag. shard = flag.Int("shard", 0, "shard index to run. Only applicable if -shards is non-zero.") shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.") -@@ -192,19 +192,11 @@ func goFiles(dir string) []string { + ) + + var ( + goos, goarch string + +@@ -189,48 +189,49 @@ func goFiles(dir string) []string { + } + sort.Strings(names) + return names + } + type runCmd func(...string) ([]byte, error) - func compileFile(runcmd runCmd, longname string) (out []byte, err error) { + func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) { - cmd := []string{"go", "tool", "compile", "-e"} ++ cmd := []string{findGoCmd(), "tool", "compile", "-e"} + cmd = append(cmd, flags...) - if *linkshared { - cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") - } -- cmd = append(cmd, longname) -- return runcmd(cmd...) -+ return runcmd(findGoCmd(), "tool", "compile", "-e", longname) + cmd = append(cmd, longname) + return runcmd(cmd...) } - func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) { + func compileInDir(runcmd runCmd, dir string, flags []string, names ...string) (out []byte, err error) { - cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."} ++ cmd := []string{findGoCmd(), "tool", "compile", "-e", "-D", ".", "-I", "."} + cmd = append(cmd, flags...) - if *linkshared { - cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") - } -+ cmd := []string{findGoCmd(), "tool", "compile", "-e", "-D", ".", "-I", "."} for _, name := range names { cmd = append(cmd, filepath.Join(dir, name)) } -@@ -213,15 +205,21 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e + return runcmd(cmd...) + } func linkFile(runcmd runCmd, goname string) (err error) { pfile := strings.Replace(goname, ".go", ".o", -1) @@ -49,12 +67,13 @@ test: add -target flag. return } -+func goRun(runcmd runCmd, goname string, args ...string) (out []byte, err error) { -+ cmd := []string{findGoCmd(), "run"} ++func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out []byte, err error) { ++ cmd := []string{findGoCmd(), "run", goGcflags()} + if len(findExecCmd()) > 0 { + cmd = append(cmd, "-exec") + cmd = append(cmd, findExecCmd()...) + } ++ cmd = append(cmd, flags...) + cmd = append(cmd, goname) + cmd = append(cmd, args...) + return runcmd(cmd...) @@ -63,81 +82,230 @@ test: add -target flag. // skipError describes why a test was skipped. type skipError string -@@ -530,8 +528,7 @@ func (t *test) run() { + func (s skipError) Error() string { return string(s) } + + func check(err error) { + if err != nil { + log.Fatal(err) +@@ -590,18 +591,17 @@ func (t *test) run() { + + long := filepath.Join(cwd, t.goFileName()) + switch action { + default: t.err = fmt.Errorf("unimplemented action %q", action) case "errorcheck": -- cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"} + // TODO(gri) remove need for -C (disable printing of columns in error messages) +- cmdline := []string{"go", "tool", "compile", "-C", "-e", "-o", "a.o"} - // No need to add -dynlink even if linkshared if we're just checking for errors... -+ cmdline := []string{findGoCmd(), "tool", "compile", "-e", "-o", "a.o"} ++ cmdline := []string{findGoCmd(), "tool", "compile", "-C", "-e", "-o", "a.o"} cmdline = append(cmdline, flags...) cmdline = append(cmdline, long) out, err := runcmd(cmdline...) -@@ -640,19 +637,14 @@ func (t *test) run() { + if wantError { + if err == nil { + t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) + return + } +@@ -704,17 +704,17 @@ func (t *test) run() { + } + if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { + t.err = fmt.Errorf("incorrect output\n%s", out) + } + } } case "build": -- _, err := runcmd("go", "build", "-o", "a.exe", long) -+ _, err := runcmd(findGoCmd(), "build", "-o", "a.exe", long) +- _, err := runcmd("go", "build", goGcflags(), "-o", "a.exe", long) ++ _, err := runcmd(findGoCmd(), "build", goGcflags(), "-o", "a.exe", long) if err != nil { t.err = err } - case "run": - useTmp = false -- cmd := []string{"go", "run"} + case "builddir": + // Build an executable from all the .go and .s files in a subdirectory. + useTmp = true + longdir := filepath.Join(cwd, t.goDirName()) +@@ -730,177 +730,132 @@ func (t *test) run() { + case ".go": + gos = append(gos, file) + case ".s": + asms = append(asms, file) + } + + } + var objs []string +- cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"} ++ cmd := []string{findGoCmd(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"} + if len(asms) > 0 { + cmd = append(cmd, "-asmhdr", "go_asm.h") + } + for _, file := range gos { + cmd = append(cmd, filepath.Join(longdir, file.Name())) + } + _, err := runcmd(cmd...) + if err != nil { + t.err = err + break + } + objs = append(objs, "go.o") + if len(asms) > 0 { +- cmd = []string{"go", "tool", "asm", "-e", "-I", ".", "-o", "asm.o"} ++ cmd = []string{findGoCmd(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"} + for _, file := range asms { + cmd = append(cmd, filepath.Join(longdir, file.Name())) + } + _, err = runcmd(cmd...) + if err != nil { + t.err = err + break + } + objs = append(objs, "asm.o") + } +- cmd = []string{"go", "tool", "pack", "c", "all.a"} ++ cmd = []string{findGoCmd(), "tool", "pack", "c", "all.a"} + cmd = append(cmd, objs...) + _, err = runcmd(cmd...) + if err != nil { + t.err = err + break + } +- cmd = []string{"go", "tool", "link", "all.a"} ++ cmd = []string{findGoCmd(), "tool", "link", "all.a"} + _, err = runcmd(cmd...) + if err != nil { + t.err = err + break + } + + case "buildrun": // build binary, then run binary, instead of go run. Useful for timeout tests where failure mode is infinite loop. + // TODO: not supported on NaCl + useTmp = true +- cmd := []string{"go", "build", goGcflags(), "-o", "a.exe"} - if *linkshared { - cmd = append(cmd, "-linkshared") - } -- cmd = append(cmd, t.goFileName()) -- out, err := runcmd(append(cmd, args...)...) -+ out, err := goRun(runcmd, t.goFileName(), args...) ++ cmd := []string{findGoCmd(), "build", goGcflags(), "-o", "a.exe"} + longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile) + cmd = append(cmd, flags...) + cmd = append(cmd, longdirgofile) + out, err := runcmd(cmd...) + if err != nil { + t.err = err + return + } +- cmd = []string{"./a.exe"} ++ cmd = []string{} ++ if len(findExecCmd()) > 0 { ++ cmd = append(cmd, findExecCmd()...) ++ } ++ cmd = append(cmd, "./a.exe") + out, err = runcmd(append(cmd, args...)...) if err != nil { t.err = err return -@@ -667,12 +659,7 @@ func (t *test) run() { + } + + if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { + t.err = fmt.Errorf("incorrect output\n%s", out) + } + + case "run": + useTmp = false +- var out []byte +- var err error +- if len(flags)+len(args) == 0 && goGcflags() == "" && !*linkshared { +- // If we're not using special go command flags, +- // skip all the go command machinery. +- // This avoids any time the go command would +- // spend checking whether, for example, the installed +- // package runtime is up to date. +- // Because we run lots of trivial test programs, +- // the time adds up. +- pkg := filepath.Join(t.tempDir, "pkg.a") +- if _, err := runcmd("go", "tool", "compile", "-o", pkg, t.goFileName()); err != nil { +- t.err = err +- return +- } +- exe := filepath.Join(t.tempDir, "test.exe") +- cmd := []string{"go", "tool", "link", "-s", "-w"} +- cmd = append(cmd, "-o", exe, pkg) +- if _, err := runcmd(cmd...); err != nil { +- t.err = err +- return +- } +- out, err = runcmd(append([]string{exe}, args...)...) +- } else { +- cmd := []string{"go", "run", goGcflags()} +- if *linkshared { +- cmd = append(cmd, "-linkshared") +- } +- cmd = append(cmd, flags...) +- cmd = append(cmd, t.goFileName()) +- out, err = runcmd(append(cmd, args...)...) +- } ++ out, err := goRun(runcmd, flags, t.goFileName(), args...) + 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) + } + + case "runoutput": + rungatec <- true + defer func() { <-rungatec }() useTmp = false -- cmd := []string{"go", "run"} +- cmd := []string{"go", "run", goGcflags()} - if *linkshared { - cmd = append(cmd, "-linkshared") - } - cmd = append(cmd, t.goFileName()) - out, err := runcmd(append(cmd, args...)...) -+ out, err := goRun(runcmd, t.goFileName(), args...) ++ out, err := goRun(runcmd, nil, t.goFileName(), args...) if err != nil { t.err = err return -@@ -682,12 +669,7 @@ func (t *test) run() { + } + tfile := filepath.Join(t.tempDir, "tmp__.go") + if err := ioutil.WriteFile(tfile, out, 0666); err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return } -- cmd = []string{"go", "run"} +- cmd = []string{"go", "run", goGcflags()} - if *linkshared { - cmd = append(cmd, "-linkshared") - } - cmd = append(cmd, tfile) - out, err = runcmd(cmd...) -+ out, err = goRun(runcmd, tfile) ++ out, err = goRun(runcmd, nil, tfile) if err != nil { t.err = err return -@@ -698,12 +680,7 @@ func (t *test) run() { + } + if string(out) != t.expectedOutput() { + t.err = fmt.Errorf("incorrect output\n%s", out) + } case "errorcheckoutput": useTmp = false -- cmd := []string{"go", "run"} +- cmd := []string{"go", "run", goGcflags()} - if *linkshared { - cmd = append(cmd, "-linkshared") - } - cmd = append(cmd, t.goFileName()) - out, err := runcmd(append(cmd, args...)...) -+ out, err := goRun(runcmd, t.goFileName(), args...) ++ out, err := goRun(runcmd, nil, t.goFileName(), args...) if err != nil { t.err = err return -@@ -714,7 +691,7 @@ func (t *test) run() { + } + tfile := filepath.Join(t.tempDir, "tmp__.go") + err = ioutil.WriteFile(tfile, out, 0666) + if err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return } @@ -146,7 +314,17 @@ test: add -target flag. cmdline = append(cmdline, flags...) cmdline = append(cmdline, tfile) out, err = runcmd(cmdline...) -@@ -741,6 +718,10 @@ func findExecCmd() []string { + if wantError { + if err == nil { + t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) + return + } +@@ -917,26 +872,37 @@ func (t *test) run() { + + var execCmd []string + + func findExecCmd() []string { + if execCmd != nil { return execCmd } execCmd = []string{} // avoid work the second time @@ -157,7 +335,10 @@ test: add -target flag. if goos == runtime.GOOS && goarch == runtime.GOARCH { return execCmd } -@@ -751,6 +732,13 @@ func findExecCmd() []string { + path, err := exec.LookPath(fmt.Sprintf("go_%s_%s_exec", goos, goarch)) + if err == nil { + execCmd = []string{path} + } return execCmd } @@ -171,3 +352,8 @@ test: add -target flag. func (t *test) String() string { return filepath.Join(t.dir, t.gofile) } + + func (t *test) makeTempDir() { + var err error + t.tempDir, err = ioutil.TempDir("", "") + check(err) |