1diff --git test/run.go test/run.go 2index ad38d420c9..e2b93d35da 100644 3--- test/run.go 4+++ test/run.go 5@@ -36,13 +36,13 @@ var ( 6 summary = flag.Bool("summary", false, "show summary of results") 7 showSkips = flag.Bool("show_skips", false, "show skipped tests") 8 runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)") 9- linkshared = flag.Bool("linkshared", false, "") 10 updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output") 11 runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run") 12 13 shard = flag.Int("shard", 0, "shard index to run. Only applicable if -shards is non-zero.") 14 shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.") 15 ) 16+ target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 17 18 var ( 19 goos, goarch string 20@@ -207,25 +207,19 @@ func goFiles(dir string) []string { 21 type runCmd func(...string) ([]byte, error) 22 23 func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) { 24- cmd := []string{goTool(), "tool", "compile", "-e"} 25+ cmd := []string{findGoCmd, "tool", "compile", "-e"} 26 cmd = append(cmd, flags...) 27- if *linkshared { 28- cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") 29- } 30 cmd = append(cmd, longname) 31 return runcmd(cmd...) 32 } 33 34 func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) { 35- cmd := []string{goTool(), "tool", "compile", "-e"} 36+ cmd := []string{findGoCmd(), "tool", "compile", "-e"} 37 if localImports { 38 // Set relative path for local imports and import search path to current dir. 39 cmd = append(cmd, "-D", ".", "-I", ".") 40 } 41 cmd = append(cmd, flags...) 42- if *linkshared { 43- cmd = append(cmd, "-dynlink", "-installsuffix=dynlink") 44- } 45 for _, name := range names { 46 cmd = append(cmd, filepath.Join(dir, name)) 47 } 48@@ -234,15 +228,28 @@ func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, 49 50 func linkFile(runcmd runCmd, goname string) (err error) { 51 pfile := strings.Replace(goname, ".go", ".o", -1) 52- cmd := []string{goTool(), "tool", "link", "-w", "-o", "a.exe", "-L", "."} 53+ cmd := []string{findGoCmd(), "tool", "link", "-w", "-o", "a.exe", "-L", "."} 54 if *linkshared { 55 cmd = append(cmd, "-linkshared", "-installsuffix=dynlink") 56 } 57 cmd = append(cmd, pfile) 58- _, err = runcmd(cmd...) 59+ _, err = runcmd(findGoCmd(), "tool", "link", "-w", "-o", "a.exe", "-L", ".", pfile) 60 return 61 } 62 63+ 64+func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out []byte, err error) { 65+ cmd := []string{findGoCmd(), "run", goGcflags()} 66+ if len(findExecCmd()) > 0 { 67+ cmd = append(cmd, "-exec") 68+ cmd = append(cmd, findExecCmd()...) 69+ } 70+ cmd = append(cmd, flags...) 71+ cmd = append(cmd, goname) 72+ cmd = append(cmd, args...) 73+ return runcmd(cmd...) 74+} 75+ 76 // skipError describes why a test was skipped. 77 type skipError string 78 79@@ -646,7 +653,7 @@ func (t *test) run() { 80 // Fail if wantError is true and compilation was successful and vice versa. 81 // Match errors produced by gc against errors in comments. 82 // TODO(gri) remove need for -C (disable printing of columns in error messages) 83- cmdline := []string{goTool(), "tool", "compile", "-C", "-e", "-o", "a.o"} 84+ cmdline := []string{findGoCmd(), "tool", "compile", "-C", "-e", "-o", "a.o"} 85 // No need to add -dynlink even if linkshared if we're just checking for errors... 86 cmdline = append(cmdline, flags...) 87 cmdline = append(cmdline, long) 88@@ -773,7 +780,7 @@ func (t *test) run() { 89 90 case "build": 91 // Build Go file. 92- _, err := runcmd(goTool(), "build", goGcflags(), "-o", "a.exe", long) 93+ _, err := runcmd(findGoCmd(), "build", goGcflags(), "-o", "a.exe", long) 94 if err != nil { 95 t.err = err 96 } 97@@ -799,7 +806,7 @@ func (t *test) run() { 98 99 } 100 var objs []string 101- cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"} 102+ cmd := []string{findGoCmd(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"} 103 if len(asms) > 0 { 104 cmd = append(cmd, "-asmhdr", "go_asm.h") 105 } 106@@ -813,7 +820,7 @@ func (t *test) run() { 107 } 108 objs = append(objs, "go.o") 109 if len(asms) > 0 { 110- cmd = []string{goTool(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"} 111+ cmd = []string{findGoCmd(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"} 112 for _, file := range asms { 113 cmd = append(cmd, filepath.Join(longdir, file.Name())) 114 } 115@@ -857,14 +864,14 @@ func (t *test) run() { 116 } 117 objs = append(objs, "asm.o") 118 } 119- cmd = []string{goTool(), "tool", "pack", "c", "all.a"} 120+ cmd = []string{findGoCmd(), "tool", "pack", "c", "all.a"} 121 cmd = append(cmd, objs...) 122 _, err = runcmd(cmd...) 123 if err != nil { 124 t.err = err 125 break 126 } 127- cmd = []string{goTool(), "tool", "link", "-o", "a.exe", "all.a"} 128+ cmd = []string{findGoCmd(), "tool", "link", "-o", "a.exe", "all.a"} 129 _, err = runcmd(cmd...) 130 if err != nil { 131 t.err = err 132@@ -886,10 +893,7 @@ func (t *test) run() { 133 // Build an executable from Go file, then run it, verify its output. 134 // Useful for timeout tests where failure mode is infinite loop. 135 // TODO: not supported on NaCl 136- cmd := []string{goTool(), "build", goGcflags(), "-o", "a.exe"} 137- if *linkshared { 138- cmd = append(cmd, "-linkshared") 139- } 140+ cmd := []string{findGoCmd(), "build", goGcflags(), "-o", "a.exe"} 141 longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile) 142 cmd = append(cmd, flags...) 143 cmd = append(cmd, longdirgofile) 144@@ -898,8 +902,13 @@ func (t *test) run() { 145 t.err = err 146 return 147 } 148- cmd = []string{"./a.exe"} 149- out, err = runcmd(append(cmd, args...)...) 150+ cmd = []string{} 151+ if len(findExecCmd()) > 0 { 152+ cmd = append(cmd, findExecCmd()...) 153+ } 154+ cmd = append(cmd, "./a.exe") 155+ 156+ out, err = runcmd(append(cmd, args...)...) 157 if err != nil { 158 t.err = err 159 return 160@@ -914,38 +923,7 @@ func (t *test) run() { 161 // otherwise build an executable and run it. 162 // Verify the output. 163 useTmp = false 164- var out []byte 165- var err error 166- if len(flags)+len(args) == 0 && goGcflags() == "" && !*linkshared { 167- // If we're not using special go command flags, 168- // skip all the go command machinery. 169- // This avoids any time the go command would 170- // spend checking whether, for example, the installed 171- // package runtime is up to date. 172- // Because we run lots of trivial test programs, 173- // the time adds up. 174- pkg := filepath.Join(t.tempDir, "pkg.a") 175- if _, err := runcmd(goTool(), "tool", "compile", "-o", pkg, t.goFileName()); err != nil { 176- t.err = err 177- return 178- } 179- exe := filepath.Join(t.tempDir, "test.exe") 180- cmd := []string{goTool(), "tool", "link", "-s", "-w"} 181- cmd = append(cmd, "-o", exe, pkg) 182- if _, err := runcmd(cmd...); err != nil { 183- t.err = err 184- return 185- } 186- out, err = runcmd(append([]string{exe}, args...)...) 187- } else { 188- cmd := []string{goTool(), "run", goGcflags()} 189- if *linkshared { 190- cmd = append(cmd, "-linkshared") 191- } 192- cmd = append(cmd, flags...) 193- cmd = append(cmd, t.goFileName()) 194- out, err = runcmd(append(cmd, args...)...) 195- } 196+ out, err := goRun(runcmd, flags, t.goFileName(), args...) 197 if err != nil { 198 t.err = err 199 return 200@@ -962,12 +940,7 @@ func (t *test) run() { 201 <-rungatec 202 }() 203 useTmp = false 204- cmd := []string{goTool(), "run", goGcflags()} 205- if *linkshared { 206- cmd = append(cmd, "-linkshared") 207- } 208- cmd = append(cmd, t.goFileName()) 209- out, err := runcmd(append(cmd, args...)...) 210+ out, err := goRun(runcmd, nil, t.goFileName(), args...) 211 if err != nil { 212 t.err = err 213 return 214@@ -977,12 +950,7 @@ func (t *test) run() { 215 t.err = fmt.Errorf("write tempfile:%s", err) 216 return 217 } 218- cmd = []string{goTool(), "run", goGcflags()} 219- if *linkshared { 220- cmd = append(cmd, "-linkshared") 221- } 222- cmd = append(cmd, tfile) 223- out, err = runcmd(cmd...) 224+ out, err = goRun(runcmd, nil, tfile) 225 if err != nil { 226 t.err = err 227 return 228@@ -995,12 +963,7 @@ func (t *test) run() { 229 // Run Go file and write its output into temporary Go file. 230 // Compile and errorCheck generated Go file. 231 useTmp = false 232- cmd := []string{goTool(), "run", goGcflags()} 233- if *linkshared { 234- cmd = append(cmd, "-linkshared") 235- } 236- cmd = append(cmd, t.goFileName()) 237- out, err := runcmd(append(cmd, args...)...) 238+ out, err := goRun(runcmd, nil, t.goFileName(), args...) 239 if err != nil { 240 t.err = err 241 return 242@@ -1011,7 +974,7 @@ func (t *test) run() { 243 t.err = fmt.Errorf("write tempfile:%s", err) 244 return 245 } 246- cmdline := []string{goTool(), "tool", "compile", "-e", "-o", "a.o"} 247+ cmdline := []string{findGoCmd(), "tool", "compile", "-e", "-o", "a.o"} 248 cmdline = append(cmdline, flags...) 249 cmdline = append(cmdline, tfile) 250 out, err = runcmd(cmdline...) 251@@ -1038,6 +1001,11 @@ func findExecCmd() []string { 252 return execCmd 253 } 254 execCmd = []string{} // avoid work the second time 255+ if *target != "" { 256+ execCmd = []string{"go_" + *target + "_exec"} 257+ return execCmd 258+ } 259+ 260 if goos == runtime.GOOS && goarch == runtime.GOARCH { 261 return execCmd 262 } 263@@ -1048,6 +1016,14 @@ func findExecCmd() []string { 264 return execCmd 265 } 266 267+func findGoCmd() string { 268+ if *target != "" { 269+ return "go_" + *target 270+ } 271+ return "go" 272+} 273+ 274+ 275 func (t *test) String() string { 276 return filepath.Join(t.dir, t.gofile) 277 } 278