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