• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git test/fixedbugs/bug302.go test/fixedbugs/bug302.go
2index e4de25d5d0..ea566e6e44 100644
3--- test/fixedbugs/bug302.go
4+++ test/fixedbugs/bug302.go
5@@ -1,5 +1,5 @@
6 // +build !nacl
7-// run
8+// runtarget
9
10 // Copyright 2010 The Go Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style
12@@ -8,16 +8,27 @@
13 package main
14
15 import (
16+	"flag"
17 	"fmt"
18 	"os"
19 	"os/exec"
20 	"path/filepath"
21 )
22
23+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
24+
25+func goCmd() string {
26+        if *target != "" {
27+                return "go_" + *target
28+        }
29+        return "go"
30+}
31+
32 func main() {
33-	run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
34-	run("go", "tool", "pack", "grc", "pp.a", "p.o")
35-	run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
36+	flag.Parse()
37+	run(goCmd(), "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
38+	run(goCmd(), "tool", "pack", "grc", "pp.a", "p.o")
39+	run(goCmd(), "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
40 	os.Remove("p.o")
41 	os.Remove("pp.a")
42 	os.Remove("main.o")
43diff --git test/fixedbugs/bug369.go test/fixedbugs/bug369.go
44index 60162ab1cb..4470d5a076 100644
45--- test/fixedbugs/bug369.go
46+++ test/fixedbugs/bug369.go
47@@ -1,5 +1,5 @@
48 // +build !nacl,!windows
49-// run
50+// runtarget
51
52 // Copyright 2011 The Go Authors. All rights reserved.
53 // Use of this source code is governed by a BSD-style
54@@ -10,21 +10,40 @@
55 package main
56
57 import (
58+	"flag"
59 	"fmt"
60 	"os"
61 	"os/exec"
62 	"path/filepath"
63 )
64
65+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
66+
67+func goCmd() string {
68+       if *target != "" {
69+               return "go_" + *target
70+       }
71+       return "go"
72+}
73+
74+func goRun(cmd ...string) {
75+       if *target == "" {
76+               run(cmd[0], cmd[1:]...)
77+       } else {
78+               run("go_"+*target+"_exec", cmd...)
79+       }
80+}
81+
82 func main() {
83+	flag.Parse()
84 	err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
85 	check(err)
86
87-	run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
88-	run("go", "tool", "compile", "-o", "fast.o", "pkg.go")
89-	run("go", "tool", "compile", "-o", "main.o", "main.go")
90-	run("go", "tool", "link", "-o", "a.exe", "main.o")
91-	run("." + string(filepath.Separator) + "a.exe")
92+	run(goCmd(), "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
93+	run(goCmd(), "tool", "compile", "-o", "fast.o", "pkg.go")
94+	run(goCmd(), "tool", "compile", "-o", "main.o", "main.go")
95+	run(goCmd(), "tool", "link", "-o", "a.exe", "main.o")
96+	goRun("." + string(filepath.Separator) + "a.exe")
97
98 	os.Remove("slow.o")
99 	os.Remove("fast.o")
100diff --git test/fixedbugs/bug429_run.go test/fixedbugs/bug429_run.go
101index 284033d1f7..e8d18b13e8 100644
102--- test/fixedbugs/bug429_run.go
103+++ test/fixedbugs/bug429_run.go
104@@ -1,5 +1,5 @@
105 // +build !nacl
106-// run
107+// runtarget
108
109 // Copyright 2014 The Go Authors. All rights reserved.
110 // Use of this source code is governed by a BSD-style
111@@ -10,6 +10,7 @@
112 package main
113
114 import (
115+	"flag"
116 	"fmt"
117 	"os"
118 	"os/exec"
119@@ -17,8 +18,27 @@ import (
120 	"strings"
121 )
122
123+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
124+
125+func goCmd() string {
126+       if *target != "" {
127+               return "go_" + *target
128+       }
129+       return "go"
130+}
131+
132+func goRun(args ...string) *exec.Cmd {
133+       cmd := []string{"run"}
134+       if *target != "" {
135+               cmd = append(cmd, "-exec", "go_"+*target+"_exec")
136+       }
137+       cmd = append(cmd, args...)
138+       return exec.Command(goCmd(), cmd...)
139+}
140+
141 func main() {
142-	cmd := exec.Command("go", "run", filepath.Join("fixedbugs", "bug429.go"))
143+	flag.Parse()
144+	cmd := goRun(filepath.Join("fixedbugs", "bug429.go"))
145 	out, err := cmd.CombinedOutput()
146 	if err == nil {
147 		fmt.Println("expected deadlock")
148diff --git test/fixedbugs/issue10607.go test/fixedbugs/issue10607.go
149index 9ee6c72bc6..e819a3085a 100644
150--- test/fixedbugs/issue10607.go
151+++ test/fixedbugs/issue10607.go
152@@ -1,5 +1,5 @@
153 // +build linux,!ppc64 android
154-// run
155+// runtarget
156
157 // Copyright 2015 The Go Authors. All rights reserved.
158 // Use of this source code is governed by a BSD-style
159@@ -11,19 +11,39 @@
160 package main
161
162 import (
163+	"flag"
164 	"fmt"
165 	"os"
166 	"os/exec"
167 	"path/filepath"
168 )
169
170+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
171+
172+func goCmd() string {
173+       if *target != "" {
174+               return "go_" + *target
175+       }
176+       return "go"
177+}
178+
179+func goRun(args ...string) *exec.Cmd {
180+       cmd := []string{"run"}
181+       if *target != "" {
182+               cmd = append(cmd, "-exec", "go_"+*target+"_exec")
183+       }
184+       cmd = append(cmd, args...)
185+       return exec.Command(goCmd(), cmd...)
186+}
187+
188 func main() {
189-	test("internal")
190+	flag.Parse()
191+	//test("internal")
192 	test("external")
193 }
194
195 func test(linkmode string) {
196-	out, err := exec.Command("go", "run", "-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
197+	out, err := goRun("-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
198 	if err != nil {
199 		fmt.Printf("BUG: linkmode=%s %v\n%s\n", linkmode, err, out)
200 		os.Exit(1)
201diff --git test/fixedbugs/issue11771.go test/fixedbugs/issue11771.go
202index d91fc5d966..4f55ce6982 100644
203--- test/fixedbugs/issue11771.go
204+++ test/fixedbugs/issue11771.go
205@@ -1,5 +1,5 @@
206 // +build !nacl
207-// run
208+// runtarget
209
210 // Copyright 2015 The Go Authors. All rights reserved.
211 // Use of this source code is governed by a BSD-style
212@@ -11,6 +11,7 @@ package main
213
214 import (
215 	"bytes"
216+	"flag"
217 	"fmt"
218 	"io/ioutil"
219 	"log"
220@@ -20,7 +21,17 @@ import (
221 	"runtime"
222 )
223
224+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
225+
226+func goCmd() string {
227+       if *target != "" {
228+               return "go_" + *target
229+       }
230+       return "go"
231+}
232+
233 func main() {
234+	flag.Parse()
235 	if runtime.Compiler != "gc" {
236 		return
237 	}
238@@ -52,7 +63,7 @@ func x() {
239 		log.Fatal(err)
240 	}
241
242-	cmd := exec.Command("go", "tool", "compile", "x.go")
243+	cmd := exec.Command(goCmd(), "tool", "compile", "x.go")
244 	cmd.Dir = dir
245 	output, err := cmd.CombinedOutput()
246 	if err == nil {
247diff --git test/fixedbugs/issue9355.go test/fixedbugs/issue9355.go
248index 10f8c73069..87356c7402 100644
249--- test/fixedbugs/issue9355.go
250+++ test/fixedbugs/issue9355.go
251@@ -1,4 +1,4 @@
252-// run
253+// runtarget
254
255 // Copyright 2014 The Go Authors. All rights reserved.
256 // Use of this source code is governed by a BSD-style
257@@ -7,6 +7,7 @@
258 package main
259
260 import (
261+	"flag"
262 	"fmt"
263 	"os"
264 	"os/exec"
265@@ -15,7 +16,17 @@ import (
266 	"runtime"
267 )
268
269+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
270+
271+func goCmd() string {
272+        if *target != "" {
273+                return "go_" + *target
274+        }
275+        return "go"
276+}
277+
278 func main() {
279+	flag.Parse()
280 	if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
281 		return
282 	}
283@@ -23,7 +34,7 @@ func main() {
284 	err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
285 	check(err)
286
287-	out := run("go", "tool", "compile", "-S", "a.go")
288+	out := run(goCmd(), "tool", "compile", "-S", "a.go")
289 	os.Remove("a.o")
290
291 	// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
292diff --git test/fixedbugs/issue9862_run.go test/fixedbugs/issue9862_run.go
293index be22f40580..a72a59fda2 100644
294--- test/fixedbugs/issue9862_run.go
295+++ test/fixedbugs/issue9862_run.go
296@@ -1,5 +1,5 @@
297 // +build !nacl
298-// run
299+// runtarget
300
301 // Copyright 2015 The Go Authors. All rights reserved.
302 // Use of this source code is governed by a BSD-style
303@@ -10,12 +10,32 @@
304 package main
305
306 import (
307+	"flag"
308 	"os/exec"
309 	"strings"
310 )
311
312+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
313+
314+func goCmd() string {
315+        if *target != "" {
316+                return "go_" + *target
317+        }
318+        return "go"
319+}
320+
321+func goRun(args ...string) *exec.Cmd {
322+        cmd := []string{"run"}
323+        if *target != "" {
324+                cmd = append(cmd, "-exec", "go_"+*target+"_exec")
325+        }
326+        cmd = append(cmd, args...)
327+        return exec.Command(goCmd(), cmd...)
328+}
329+
330 func main() {
331-	out, err := exec.Command("go", "run", "fixedbugs/issue9862.go").CombinedOutput()
332+	flag.Parse()
333+	out, err := goRun("fixedbugs/issue9862.go").CombinedOutput()
334 	outstr := string(out)
335 	if err == nil {
336 		println("go run issue9862.go succeeded, should have failed\n", outstr)
337diff --git test/linkmain_run.go test/linkmain_run.go
338index 55de481a81..03666e6b29 100644
339--- test/linkmain_run.go
340+++ test/linkmain_run.go
341@@ -1,5 +1,5 @@
342 // +build !nacl
343-// run
344+// runtarget
345
346 // Copyright 2014 The Go Authors. All rights reserved.
347 // Use of this source code is governed by a BSD-style
348@@ -10,12 +10,22 @@
349 package main
350
351 import (
352+	"flag"
353 	"fmt"
354 	"os"
355 	"os/exec"
356 	"strings"
357 )
358
359+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
360+
361+func goCmd() string {
362+        if *target != "" {
363+                return "go_" + *target
364+        }
365+        return "go"
366+}
367+
368 func cleanup() {
369 	os.Remove("linkmain.o")
370 	os.Remove("linkmain.a")
371@@ -51,16 +61,17 @@ func runFail(cmdline string) {
372 }
373
374 func main() {
375+	flag.Parse()
376 	// helloworld.go is package main
377-	run("go tool compile -o linkmain.o helloworld.go")
378-	run("go tool compile -pack -o linkmain.a helloworld.go")
379-	run("go tool link -o linkmain.exe linkmain.o")
380-	run("go tool link -o linkmain.exe linkmain.a")
381+	run(goCmd() + " tool compile -o linkmain.o helloworld.go")
382+	run(goCmd() + " tool compile -pack -o linkmain.a helloworld.go")
383+	run(goCmd() + " tool link -o linkmain.exe linkmain.o")
384+	run(goCmd() + " tool link -o linkmain.exe linkmain.a")
385
386 	// linkmain.go is not
387-	run("go tool compile -o linkmain1.o linkmain.go")
388-	run("go tool compile -pack -o linkmain1.a linkmain.go")
389-	runFail("go tool link -o linkmain.exe linkmain1.o")
390-	runFail("go tool link -o linkmain.exe linkmain1.a")
391+	run(goCmd() + " tool compile -o linkmain1.o linkmain.go")
392+	run(goCmd() + " tool compile -pack -o linkmain1.a linkmain.go")
393+	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.o")
394+	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.a")
395 	cleanup()
396 }
397diff --git test/linkobj.go test/linkobj.go
398index 8a86aa872f..0d1964e7fb 100644
399--- test/linkobj.go
400+++ test/linkobj.go
401@@ -1,5 +1,5 @@
402 // +build !nacl
403-// run
404+// runtarget
405
406 // Copyright 2016 The Go Authors. All rights reserved.
407 // Use of this source code is governed by a BSD-style
408@@ -10,6 +10,7 @@
409 package main
410
411 import (
412+	"flag"
413 	"fmt"
414 	"io/ioutil"
415 	"log"
416@@ -18,9 +19,27 @@ import (
417 	"strings"
418 )
419
420+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
421+
422+func goCmd() string {
423+        if *target != "" {
424+                return "go_" + *target
425+        }
426+        return "go"
427+}
428+
429+func goRun(cmd ...string) string {
430+        if *target == "" {
431+                return run(cmd...)
432+        } else {
433+                return run(append([]string{"go_"+*target+"_exec"}, cmd...)...)
434+        }
435+}
436+
437 var pwd, tmpdir string
438
439 func main() {
440+	flag.Parse()
441 	dir, err := ioutil.TempDir("", "go-test-linkobj-")
442 	if err != nil {
443 		log.Fatal(err)
444@@ -37,28 +56,28 @@ func main() {
445
446 	writeFile("p1.go", `
447 		package p1
448-
449+
450 		func F() {
451 			println("hello from p1")
452 		}
453 	`)
454 	writeFile("p2.go", `
455 		package p2
456-
457+
458 		import "./p1"
459
460 		func F() {
461 			p1.F()
462 			println("hello from p2")
463 		}
464-
465+
466 		func main() {}
467 	`)
468 	writeFile("p3.go", `
469 		package main
470
471 		import "./p2"
472-
473+
474 		func main() {
475 			p2.F()
476 			println("hello from main")
477@@ -76,9 +95,9 @@ func main() {
478 		}
479
480 		// inlining is disabled to make sure that the link objects contain needed code.
481-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
482-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
483-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
484+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
485+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
486+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
487
488 		cp("p1."+o, "p1.oo")
489 		cp("p2."+o, "p2.oo")
490@@ -86,13 +105,13 @@ func main() {
491 		cp("p1.lo", "p1."+o)
492 		cp("p2.lo", "p2."+o)
493 		cp("p3.lo", "p3."+o)
494-		out := runFail("go", "tool", "link", "p2."+o)
495+		out := runFail(goCmd(), "tool", "link", "p2."+o)
496 		if !strings.Contains(out, "not package main") {
497 			fatalf("link p2.o failed but not for package main:\n%s", out)
498 		}
499
500-		run("go", "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
501-		out = run("./a.out.exe")
502+		run(goCmd(), "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
503+		out = goRun("./a.out.exe")
504 		if !strings.Contains(out, "hello from p1\nhello from p2\nhello from main\n") {
505 			fatalf("running main, incorrect output:\n%s", out)
506 		}
507diff --git test/linkx_run.go test/linkx_run.go
508index cc249c9cfc..530159ab9d 100644
509--- test/linkx_run.go
510+++ test/linkx_run.go
511@@ -1,5 +1,5 @@
512 // +build !nacl
513-// run
514+// runtarget
515
516 // Copyright 2014 The Go Authors. All rights reserved.
517 // Use of this source code is governed by a BSD-style
518@@ -11,20 +11,40 @@ package main
519
520 import (
521 	"bytes"
522+	"flag"
523 	"fmt"
524 	"os"
525 	"os/exec"
526 	"strings"
527 )
528
529+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
530+
531+func goCmd() string {
532+        if *target != "" {
533+                return "go_" + *target
534+        }
535+        return "go"
536+}
537+
538+func goRun(args ...string) *exec.Cmd {
539+        cmd := []string{"run"}
540+        if *target != "" {
541+                cmd = append(cmd, "-exec", "go_"+*target+"_exec")
542+        }
543+        cmd = append(cmd, args...)
544+        return exec.Command(goCmd(), cmd...)
545+}
546+
547 func main() {
548+	flag.Parse()
549 	// test(" ") // old deprecated & removed syntax
550 	test("=") // new syntax
551 }
552
553 func test(sep string) {
554 	// Successful run
555-	cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
556+	cmd := goRun("-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
557 	var out, errbuf bytes.Buffer
558 	cmd.Stdout = &out
559 	cmd.Stderr = &errbuf
560@@ -44,7 +64,7 @@ func test(sep string) {
561 	}
562
563 	// Issue 8810
564-	cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
565+	cmd = goRun("-ldflags=-X main.tbd", "linkx.go")
566 	_, err = cmd.CombinedOutput()
567 	if err == nil {
568 		fmt.Println("-X linker flag should not accept keys without values")
569@@ -52,7 +72,7 @@ func test(sep string) {
570 	}
571
572 	// Issue 9621
573-	cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
574+	cmd = goRun("-ldflags=-X main.b=false -X main.x=42", "linkx.go")
575 	outx, err := cmd.CombinedOutput()
576 	if err == nil {
577 		fmt.Println("-X linker flag should not overwrite non-strings")
578diff --git test/nosplit.go test/nosplit.go
579index e6cecebde3..fed1c0e510 100644
580--- test/nosplit.go
581+++ test/nosplit.go
582@@ -1,5 +1,5 @@
583 // +build !nacl
584-// run
585+// runtarget
586
587 // Copyright 2014 The Go Authors. All rights reserved.
588 // Use of this source code is governed by a BSD-style
589@@ -9,6 +9,7 @@ package main
590
591 import (
592 	"bytes"
593+	"flag"
594 	"fmt"
595 	"io/ioutil"
596 	"log"
597@@ -21,6 +22,24 @@ import (
598 	"strings"
599 )
600
601+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
602+
603+func goCmd() string {
604+        if *target != "" {
605+                return "go_" + *target
606+        }
607+        return "go"
608+}
609+
610+func goArch() string {
611+        goarch, err := exec.Command(goCmd(), "env", "GOARCH").Output()
612+        if err != nil {
613+                bug()
614+                fmt.Printf("running go env GOARCH: %v\n", err)
615+        }
616+        return strings.TrimSpace(string(goarch))
617+}
618+
619 var tests = `
620 # These are test cases for the linker analysis that detects chains of
621 # nosplit functions that would cause a stack overflow.
622@@ -194,12 +213,13 @@ var (
623 )
624
625 func main() {
626-	goarch := os.Getenv("GOARCH")
627+	flag.Parse()
628+	goarch := goArch()
629 	if goarch == "" {
630-		goarch = runtime.GOARCH
631+		return
632 	}
633
634-	version, err := exec.Command("go", "tool", "compile", "-V").Output()
635+	version, err := exec.Command(goCmd(), "tool", "compile", "-V").Output()
636 	if err != nil {
637 		bug()
638 		fmt.Printf("running go tool compile -V: %v\n", err)
639@@ -345,7 +365,7 @@ TestCases:
640 			log.Fatal(err)
641 		}
642
643-		cmd := exec.Command("go", "build")
644+		cmd := exec.Command(goCmd(), "build")
645 		cmd.Dir = dir
646 		output, err := cmd.CombinedOutput()
647 		if err == nil {
648diff --git test/run.go test/run.go
649index ac5d3c3e8d..62041226b0 100644
650--- test/run.go
651+++ test/run.go
652@@ -229,6 +229,16 @@ func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out []
653         return runcmd(cmd...)
654 }
655
656+func goRunTarget(runcmd runCmd, goname string, args ...string) (out []byte, err error) {
657+        cmd := []string{"go_local", "run"}
658+        cmd = append(cmd, goname)
659+        if *target != "" {
660+                cmd = append(cmd, "-target", *target)
661+        }
662+        cmd = append(cmd, args...)
663+        return runcmd(cmd...)
664+}
665+
666 // skipError describes why a test was skipped.
667 type skipError string
668
669@@ -491,7 +501,7 @@ func (t *test) run() {
670 		action = "rundir"
671 	case "cmpout":
672 		action = "run" // the run case already looks for <dir>/<test>.out files
673-	case "compile", "compiledir", "build", "builddir", "run", "buildrun", "runoutput", "rundir":
674+	case "compile", "compiledir", "build", "builddir", "run", "runtarget", "buildrun", "runoutput", "rundir":
675 		// nothing to do
676 	case "errorcheckandrundir":
677 		wantError = false // should be no error if also will run
678@@ -816,6 +826,17 @@ func (t *test) run() {
679 			t.err = fmt.Errorf("incorrect output\n%s", out)
680 		}
681
682+       case "runtarget":
683+                useTmp = false
684+                out, err := goRunTarget(runcmd, t.goFileName(), args...)
685+                if err != nil {
686+                        t.err = err
687+                        return
688+                }
689+                if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
690+                        t.err = fmt.Errorf("incorrect output\n%s", out)
691+                }
692+
693 	case "runoutput":
694 		rungatec <- true
695 		defer func() {
696diff --git test/sinit_run.go test/sinit_run.go
697index c9afd3b777..dc885ecffd 100644
698--- test/sinit_run.go
699+++ test/sinit_run.go
700@@ -1,5 +1,5 @@
701 // +build !nacl
702-// run
703+// runtarget
704
705 // Copyright 2014 The Go Authors. All rights reserved.
706 // Use of this source code is governed by a BSD-style
707@@ -11,13 +11,24 @@ package main
708
709 import (
710 	"bytes"
711+	"flag"
712 	"fmt"
713 	"os"
714 	"os/exec"
715 )
716
717+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
718+
719+func goCmd() string {
720+       if *target != "" {
721+               return "go_" + *target
722+       }
723+       return "go"
724+}
725+
726 func main() {
727-	cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
728+	flag.Parse()
729+	cmd := exec.Command(goCmd(), "tool", "compile", "-S", "sinit.go")
730 	out, err := cmd.CombinedOutput()
731 	if err != nil {
732 		fmt.Println(string(out))
733