]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: use testenv.Command instead of exec.Command in tests
authorBryan C. Mills <bcmills@google.com>
Tue, 15 Nov 2022 15:21:21 +0000 (10:21 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 15 Nov 2022 20:22:14 +0000 (20:22 +0000)
testenv.Command sets a default timeout based on the test's deadline
and sends SIGQUIT (where supported) in case of a hang.

Change-Id: I25a67aa5793c6fa977ff6d4dc59ca1533bf58d41
Reviewed-on: https://go-review.googlesource.com/c/go/+/450702
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

12 files changed:
src/cmd/link/cgo_test.go
src/cmd/link/dwarf_test.go
src/cmd/link/elf_test.go
src/cmd/link/internal/ld/deadcode_test.go
src/cmd/link/internal/ld/dwarf_test.go
src/cmd/link/internal/ld/elf_test.go
src/cmd/link/internal/ld/go_test.go
src/cmd/link/internal/ld/ld_test.go
src/cmd/link/internal/ld/nooptcgolink_test.go
src/cmd/link/internal/ld/stackcheck_test.go
src/cmd/link/link_test.go
src/cmd/link/linkbig_test.go

index 26ab8024541d6cfc66b1b6694e4725779bd0d81a..4393c3fa8019a60b75940cf71c857f571a98185a 100644 (file)
@@ -106,7 +106,7 @@ func testCGOLTO(t *testing.T, cc string, test int) {
                t.Fatalf("bad case %d", test)
        }
 
-       cmd := exec.Command(testenv.GoToolPath(t), "build")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build")
        cmd.Dir = dir
        cmd.Env = append(os.Environ(),
                "CC="+cc,
index 78ef3cfe9713691cbb053a8e180cff02dcd66820..53dc686a4b512a4478d1b9c9e1c52b4565f6e1f7 100644 (file)
@@ -85,7 +85,7 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
 
                        exe := filepath.Join(tmpDir, prog+".exe")
                        dir := "../../runtime/testdata/" + prog
-                       cmd := exec.Command(testenv.GoToolPath(t), "build", "-toolexec", os.Args[0], "-o", exe)
+                       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-toolexec", os.Args[0], "-o", exe)
                        if buildmode != "" {
                                cmd.Args = append(cmd.Args, "-buildmode", buildmode)
                        }
@@ -100,7 +100,7 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
 
                        if buildmode == "c-archive" {
                                // Extract the archive and use the go.o object within.
-                               cmd := exec.Command("ar", "-x", exe)
+                               cmd := testenv.Command(t, "ar", "-x", exe)
                                cmd.Dir = tmpDir
                                if out, err := cmd.CombinedOutput(); err != nil {
                                        t.Fatalf("ar -x %s: %v\n%s", exe, err, out)
@@ -112,7 +112,7 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
                        if runtime.GOOS == "darwin" && !darwinSymbolTestIsTooFlaky {
                                if _, err = exec.LookPath("symbols"); err == nil {
                                        // Ensure Apple's tooling can parse our object for symbols.
-                                       out, err = exec.Command("symbols", exe).CombinedOutput()
+                                       out, err = testenv.Command(t, "symbols", exe).CombinedOutput()
                                        if err != nil {
                                                t.Fatalf("symbols %v: %v: %s", filepath.Base(exe), err, out)
                                        } else {
@@ -208,12 +208,12 @@ func TestDWARFiOS(t *testing.T) {
        if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
                t.Skip("skipping on non-darwin/amd64 platform")
        }
-       if err := exec.Command("xcrun", "--help").Run(); err != nil {
+       if err := testenv.Command(t, "xcrun", "--help").Run(); err != nil {
                t.Skipf("error running xcrun, required for iOS cross build: %v", err)
        }
        // Check to see if the ios tools are installed. It's possible to have the command line tools
        // installed without the iOS sdk.
-       if output, err := exec.Command("xcodebuild", "-showsdks").CombinedOutput(); err != nil {
+       if output, err := testenv.Command(t, "xcodebuild", "-showsdks").CombinedOutput(); err != nil {
                t.Skipf("error running xcodebuild, required for iOS cross build: %v", err)
        } else if !strings.Contains(string(output), "iOS SDK") {
                t.Skipf("iOS SDK not detected.")
index 8f7af2598c9b092236fffcefccdb89dd7e34172f..27285ff566ead9023f825ec8a12ac7664f29b4d0 100644 (file)
@@ -23,7 +23,7 @@ import (
 
 func getCCAndCCFLAGS(t *testing.T, env []string) (string, []string) {
        goTool := testenv.GoToolPath(t)
-       cmd := exec.Command(goTool, "env", "CC")
+       cmd := testenv.Command(t, goTool, "env", "CC")
        cmd.Env = env
        ccb, err := cmd.Output()
        if err != nil {
@@ -31,7 +31,7 @@ func getCCAndCCFLAGS(t *testing.T, env []string) (string, []string) {
        }
        cc := strings.TrimSpace(string(ccb))
 
-       cmd = exec.Command(goTool, "env", "GOGCCFLAGS")
+       cmd = testenv.Command(t, goTool, "env", "GOGCCFLAGS")
        cmd.Env = env
        cflagsb, err := cmd.Output()
        if err != nil {
@@ -87,14 +87,14 @@ func TestSectionsWithSameName(t *testing.T) {
 
        asmObj := filepath.Join(dir, "x.o")
        t.Logf("%s %v -c -o %s %s", cc, cflags, asmObj, asmFile)
-       if out, err := exec.Command(cc, append(cflags, "-c", "-o", asmObj, asmFile)...).CombinedOutput(); err != nil {
+       if out, err := testenv.Command(t, cc, append(cflags, "-c", "-o", asmObj, asmFile)...).CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
        }
 
        asm2Obj := filepath.Join(dir, "x2.syso")
        t.Logf("%s --rename-section .text2=.text1 %s %s", objcopy, asmObj, asm2Obj)
-       if out, err := exec.Command(objcopy, "--rename-section", ".text2=.text1", asmObj, asm2Obj).CombinedOutput(); err != nil {
+       if out, err := testenv.Command(t, objcopy, "--rename-section", ".text2=.text1", asmObj, asm2Obj).CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
        }
@@ -110,7 +110,7 @@ func TestSectionsWithSameName(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command(goTool, "build")
+       cmd := testenv.Command(t, goTool, "build")
        cmd.Dir = dir
        cmd.Env = env
        t.Logf("%s build", goTool)
@@ -162,7 +162,7 @@ func TestMinusRSymsWithSameName(t *testing.T) {
                obj := filepath.Join(dir, fmt.Sprintf("x%d.o", i))
                objs = append(objs, obj)
                t.Logf("%s %v -c -o %s %s", cc, cflags, obj, csrcFile)
-               if out, err := exec.Command(cc, append(cflags, "-c", "-o", obj, csrcFile)...).CombinedOutput(); err != nil {
+               if out, err := testenv.Command(t, cc, append(cflags, "-c", "-o", obj, csrcFile)...).CombinedOutput(); err != nil {
                        t.Logf("%s", out)
                        t.Fatal(err)
                }
@@ -170,7 +170,7 @@ func TestMinusRSymsWithSameName(t *testing.T) {
 
        sysoObj := filepath.Join(dir, "ldr.syso")
        t.Logf("%s %v -nostdlib -r -o %s %v", cc, cflags, sysoObj, objs)
-       if out, err := exec.Command(cc, append(cflags, "-nostdlib", "-r", "-o", sysoObj, objs[0], objs[1])...).CombinedOutput(); err != nil {
+       if out, err := testenv.Command(t, cc, append(cflags, "-nostdlib", "-r", "-o", sysoObj, objs[0], objs[1])...).CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
        }
@@ -190,7 +190,7 @@ func TestMinusRSymsWithSameName(t *testing.T) {
        }
 
        t.Logf("%s build", goTool)
-       cmd := exec.Command(goTool, "build")
+       cmd := testenv.Command(t, goTool, "build")
        cmd.Dir = dir
        cmd.Env = env
        if out, err := cmd.CombinedOutput(); err != nil {
@@ -221,7 +221,7 @@ func TestMergeNoteSections(t *testing.T) {
        goTool := testenv.GoToolPath(t)
        // sha1sum of "gopher"
        id := "0xf4e8cd51ce8bae2996dc3b74639cdeaa1f7fee5f"
-       cmd := exec.Command(goTool, "build", "-o", outFile, "-ldflags",
+       cmd := testenv.Command(t, goTool, "build", "-o", outFile, "-ldflags",
                "-B "+id, goFile)
        cmd.Dir = t.TempDir()
        if out, err := cmd.CombinedOutput(); err != nil {
@@ -328,7 +328,7 @@ func TestPIESize(t *testing.T) {
                        }
 
                        build := func(bin, mode string) error {
-                               cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", bin, "-buildmode="+mode)
+                               cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", bin, "-buildmode="+mode)
                                if external {
                                        cmd.Args = append(cmd.Args, "-ldflags=-linkmode=external")
                                }
@@ -478,7 +478,7 @@ func TestIssue51939(t *testing.T) {
        }
        outFile := filepath.Join(td, "issue51939.exe")
        goTool := testenv.GoToolPath(t)
-       cmd := exec.Command(goTool, "build", "-o", outFile, goFile)
+       cmd := testenv.Command(t, goTool, "build", "-o", outFile, goFile)
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
index ed37a088128d40048304e5c36d57c0706c5088d8..573bff3c850d57b3f8349abbc941899bf5129747 100644 (file)
@@ -7,7 +7,6 @@ package ld
 import (
        "bytes"
        "internal/testenv"
-       "os/exec"
        "path/filepath"
        "testing"
 )
@@ -35,7 +34,7 @@ func TestDeadcode(t *testing.T) {
                        t.Parallel()
                        src := filepath.Join("testdata", "deadcode", test.src+".go")
                        exe := filepath.Join(tmpdir, test.src+".exe")
-                       cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-dumpdep", "-o", exe, src)
+                       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-dumpdep", "-o", exe, src)
                        out, err := cmd.CombinedOutput()
                        if err != nil {
                                t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
index 3132e1233cd751ec636a86a6ebeeea6032b9703a..a3db4a99ffbb10facce0d42a9367355a67c579f5 100644 (file)
@@ -11,7 +11,6 @@ import (
        "internal/testenv"
        "io"
        "os"
-       "os/exec"
        "path/filepath"
        "reflect"
        "runtime"
@@ -100,7 +99,7 @@ func gobuild(t *testing.T, dir string, testfile string, gcflags string) *builtFi
                t.Fatal(err)
        }
 
-       cmd := exec.Command(testenv.GoToolPath(t), "build", gcflags, "-o", dst, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", gcflags, "-o", dst, src)
        b, err := cmd.CombinedOutput()
        if len(b) != 0 {
                t.Logf("## build output:\n%s", b)
@@ -122,7 +121,7 @@ func gobuildTestdata(t *testing.T, tdir string, pkgDir string, gcflags string) *
        dst := filepath.Join(tdir, "out.exe")
 
        // Run a build with an updated GOPATH
-       cmd := exec.Command(testenv.GoToolPath(t), "build", gcflags, "-o", dst)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", gcflags, "-o", dst)
        cmd.Dir = pkgDir
        if b, err := cmd.CombinedOutput(); err != nil {
                t.Logf("build: %s\n", b)
@@ -768,7 +767,7 @@ func main() {
        f := gobuild(t, dir, prog, flags)
        defer f.Close()
 
-       out, err := exec.Command(f.path).CombinedOutput()
+       out, err := testenv.Command(t, f.path).CombinedOutput()
        if err != nil {
                t.Fatalf("could not run test program: %v", err)
        }
index 9f5a0ed9e2e82728d61e3165e0459681873b7ea3..8af0ca144eb1b32132cf891ce53bc33a89658243 100644 (file)
@@ -11,7 +11,6 @@ import (
        "debug/elf"
        "internal/testenv"
        "os"
-       "os/exec"
        "path/filepath"
        "runtime"
        "strings"
@@ -38,7 +37,7 @@ func main() {
        }
 
        binFile := filepath.Join(dir, "issue33358")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", binFile, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", binFile, src)
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
        }
@@ -101,7 +100,7 @@ func TestNoDuplicateNeededEntries(t *testing.T) {
 
        path := filepath.Join(dir, "x")
        argv := []string{"build", "-o", path, filepath.Join(wd, "testdata", "issue39256")}
-       out, err := exec.Command(testenv.GoToolPath(t), argv...).CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), argv...).CombinedOutput()
        if err != nil {
                t.Fatalf("Build failure: %s\n%s\n", err, string(out))
        }
index 7dc9b5711284c69fcd37dfda231492e4e5e323f1..836731a891e193dcd78389502fd799ce46e7fe52 100644 (file)
@@ -7,7 +7,6 @@ package ld
 import (
        "internal/testenv"
        "os"
-       "os/exec"
        "path/filepath"
        "reflect"
        "runtime"
@@ -105,13 +104,13 @@ func main() {}`
        }
 
        exe := filepath.Join(dir, "deduped.exe")
-       out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, srcFile).CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, srcFile).CombinedOutput()
        if err != nil {
                t.Fatalf("build failure: %s\n%s\n", err, string(out))
        }
 
        // Result should be runnable.
-       if _, err = exec.Command(exe).CombinedOutput(); err != nil {
+       if _, err = testenv.Command(t, exe).CombinedOutput(); err != nil {
                t.Fatal(err)
        }
 }
index e1149d3e563a549ab8917eb1820860b0aab2ed08..314dab7d7daeff1d95a35bacb9be7485a490bc83 100644 (file)
@@ -10,7 +10,6 @@ import (
        "fmt"
        "internal/testenv"
        "os"
-       "os/exec"
        "path/filepath"
        "runtime"
        "strings"
@@ -26,7 +25,7 @@ func TestUndefinedRelocErrors(t *testing.T) {
 
        t.Parallel()
 
-       out, err := exec.Command(testenv.GoToolPath(t), "build", "./testdata/issue10978").CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), "build", "./testdata/issue10978").CombinedOutput()
        if err == nil {
                t.Fatal("expected build to fail")
        }
@@ -113,7 +112,7 @@ func TestArchiveBuildInvokeWithExec(t *testing.T) {
 
        ldf := fmt.Sprintf("-ldflags=-v -tmpdir=%s", dir)
        argv := []string{"build", "-buildmode=c-archive", "-o", arfile, ldf, srcfile}
-       out, err := exec.Command(testenv.GoToolPath(t), argv...).CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), argv...).CombinedOutput()
        if err != nil {
                t.Fatalf("build failure: %s\n%s\n", err, string(out))
        }
@@ -155,13 +154,13 @@ func TestLargeTextSectionSplitting(t *testing.T) {
        // is arbitrary; we just need something sufficiently large that uses
        // external linking.
        exe := filepath.Join(dir, "go.exe")
-       out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "-ldflags=-linkmode=external -debugtextsize=1048576", "cmd/go").CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, "-ldflags=-linkmode=external -debugtextsize=1048576", "cmd/go").CombinedOutput()
        if err != nil {
                t.Fatalf("build failure: %s\n%s\n", err, string(out))
        }
 
        // Check that we did split text sections.
-       out, err = exec.Command(testenv.GoToolPath(t), "tool", "nm", exe).CombinedOutput()
+       out, err = testenv.Command(t, testenv.GoToolPath(t), "tool", "nm", exe).CombinedOutput()
        if err != nil {
                t.Fatalf("nm failure: %s\n%s\n", err, string(out))
        }
@@ -170,7 +169,7 @@ func TestLargeTextSectionSplitting(t *testing.T) {
        }
 
        // Result should be runnable.
-       _, err = exec.Command(exe, "version").CombinedOutput()
+       _, err = testenv.Command(t, exe, "version").CombinedOutput()
        if err != nil {
                t.Fatal(err)
        }
@@ -210,7 +209,7 @@ func testWindowsBuildmodeCSharedASLR(t *testing.T, useASLR bool) {
                argv = append(argv, "-ldflags", "-aslr=false")
        }
        argv = append(argv, "-o", objfile, srcfile)
-       out, err := exec.Command(testenv.GoToolPath(t), argv...).CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), argv...).CombinedOutput()
        if err != nil {
                t.Fatalf("build failure: %s\n%s\n", err, string(out))
        }
@@ -330,7 +329,7 @@ func main() {
                        if err := os.WriteFile(src, []byte(tt.prog), 0644); err != nil {
                                t.Fatal(err)
                        }
-                       cmd := exec.Command(testenv.GoToolPath(t), "run", src)
+                       cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
                        out, err := cmd.CombinedOutput()
                        if err != nil {
                                t.Fatal(err)
index 0b76ecaecb846d7543bf62e2b9d04c2b55091167..646583f13ac62b87dd8849183e06db6231f5c57e 100644 (file)
@@ -6,7 +6,6 @@ package ld
 
 import (
        "internal/testenv"
-       "os/exec"
        "path/filepath"
        "testing"
 )
@@ -20,7 +19,7 @@ func TestNooptCgoBuild(t *testing.T) {
        testenv.MustHaveGoBuild(t)
        testenv.MustHaveCGO(t)
        dir := t.TempDir()
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-N -l", "-o", filepath.Join(dir, "a.out"))
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-gcflags=-N -l", "-o", filepath.Join(dir, "a.out"))
        cmd.Dir = filepath.Join(testenv.GOROOT(t), "src", "runtime", "testdata", "testprogcgo")
        out, err := cmd.CombinedOutput()
        if err != nil {
index d93540174012336d75753c098a15c2912bd907d7..dd7e20528f095958b7e1d869641250378807f972 100644 (file)
@@ -8,7 +8,6 @@ import (
        "fmt"
        "internal/testenv"
        "os"
-       "os/exec"
        "regexp"
        "strconv"
        "testing"
@@ -20,7 +19,7 @@ func TestStackCheckOutput(t *testing.T) {
        testenv.MustHaveGoBuild(t)
        t.Parallel()
 
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", os.DevNull, "./testdata/stackcheck")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", os.DevNull, "./testdata/stackcheck")
        // The rules for computing frame sizes on all of the
        // architectures are complicated, so just do this on amd64.
        cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux")
index 406487c7eee4d7be7af61b6bbfeb3971f408f6af..a770c919365081a7d082b0b5819d330914814b78 100644 (file)
@@ -12,7 +12,6 @@ import (
        "internal/platform"
        "internal/testenv"
        "os"
-       "os/exec"
        "path/filepath"
        "regexp"
        "runtime"
@@ -58,14 +57,14 @@ func main() {}
                t.Fatalf("failed to write main.go: %v\n", err)
        }
 
-       cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "main.go")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "main.go")
        cmd.Dir = tmpdir
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("failed to compile main.go: %v, output: %s\n", err, out)
        }
 
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "main.o")
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "main.o")
        cmd.Dir = tmpdir
        out, err = cmd.CombinedOutput()
        if err != nil {
@@ -92,7 +91,7 @@ func TestIssue28429(t *testing.T) {
        }
 
        runGo := func(args ...string) {
-               cmd := exec.Command(testenv.GoToolPath(t), args...)
+               cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
                cmd.Dir = tmpdir
                out, err := cmd.CombinedOutput()
                if err != nil {
@@ -154,7 +153,7 @@ TEXT Â·x(SB),0,$0
         MOVD Â·zero(SB), AX
         RET
 `)
-       cmd := exec.Command(testenv.GoToolPath(t), "build")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build")
        cmd.Dir = tmpdir
        cmd.Env = append(os.Environ(),
                "GOARCH=amd64", "GOOS=linux", "GOPATH="+filepath.Join(tmpdir, "_gopath"))
@@ -202,7 +201,7 @@ func TestIssue33979(t *testing.T) {
        }
 
        run := func(name string, args ...string) string {
-               cmd := exec.Command(name, args...)
+               cmd := testenv.Command(t, name, args...)
                cmd.Dir = tmpdir
                out, err := cmd.CombinedOutput()
                if err != nil {
@@ -253,7 +252,7 @@ void foo() {
        runGo("tool", "pack", "c", "x.a", "x1.o", "x2.o", "x3.o")
 
        // Now attempt to link using the internal linker.
-       cmd := exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-linkmode=internal", "x.a")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-linkmode=internal", "x.a")
        cmd.Dir = tmpdir
        out, err := cmd.CombinedOutput()
        if err == nil {
@@ -276,13 +275,13 @@ func TestBuildForTvOS(t *testing.T) {
        if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
                t.Skip("skipping in -short mode with $GO_BUILDER_NAME empty")
        }
-       if err := exec.Command("xcrun", "--help").Run(); err != nil {
+       if err := testenv.Command(t, "xcrun", "--help").Run(); err != nil {
                t.Skipf("error running xcrun, required for iOS cross build: %v", err)
        }
 
        t.Parallel()
 
-       sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
+       sdkPath, err := testenv.Command(t, "xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
        if err != nil {
                t.Skip("failed to locate appletvos SDK, skipping")
        }
@@ -299,7 +298,7 @@ func TestBuildForTvOS(t *testing.T) {
        tmpDir := t.TempDir()
 
        ar := filepath.Join(tmpDir, "lib.a")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
        cmd.Env = append(os.Environ(),
                "CGO_ENABLED=1",
                "GOOS=ios",
@@ -312,7 +311,7 @@ func TestBuildForTvOS(t *testing.T) {
                t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
        }
 
-       link := exec.Command(CC[0], CC[1:]...)
+       link := testenv.Command(t, CC[0], CC[1:]...)
        link.Args = append(link.Args, CGO_LDFLAGS...)
        link.Args = append(link.Args, "-o", filepath.Join(tmpDir, "a.out")) // Avoid writing to package directory.
        link.Args = append(link.Args, ar, filepath.Join("testdata", "testBuildFortvOS", "main.m"))
@@ -341,7 +340,7 @@ func TestXFlag(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-X=main.X=meow", "-o", filepath.Join(tmpdir, "main"), src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-X=main.X=meow", "-o", filepath.Join(tmpdir, "main"), src)
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Errorf("%v: %v:\n%s", cmd.Args, err, out)
        }
@@ -366,7 +365,7 @@ func TestMachOBuildVersion(t *testing.T) {
        }
 
        exe := filepath.Join(tmpdir, "main")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-linkmode=internal", "-o", exe, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-linkmode=internal", "-o", exe, src)
        cmd.Env = append(os.Environ(),
                "CGO_ENABLED=0",
                "GOOS=darwin",
@@ -442,14 +441,14 @@ func TestIssue34788Android386TLSSequence(t *testing.T) {
        }
 
        obj := filepath.Join(tmpdir, "blah.o")
-       cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=blah", "-o", obj, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=blah", "-o", obj, src)
        cmd.Env = append(os.Environ(), "GOARCH=386", "GOOS=android")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Fatalf("failed to compile blah.go: %v, output: %s\n", err, out)
        }
 
        // Run objdump on the resulting object.
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "objdump", obj)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "objdump", obj)
        out, oerr := cmd.CombinedOutput()
        if oerr != nil {
                t.Fatalf("failed to objdump blah.o: %v, output: %s\n", oerr, out)
@@ -529,7 +528,7 @@ func TestStrictDup(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-strictdups=1")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-strictdups=1")
        cmd.Dir = tmpdir
        out, err := cmd.CombinedOutput()
        if err != nil {
@@ -539,7 +538,7 @@ func TestStrictDup(t *testing.T) {
                t.Errorf("unexpected output:\n%s", out)
        }
 
-       cmd = exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-strictdups=2")
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-strictdups=2")
        cmd.Dir = tmpdir
        out, err = cmd.CombinedOutput()
        if err == nil {
@@ -613,13 +612,13 @@ func TestFuncAlign(t *testing.T) {
        }
 
        // Build and run with old object file format.
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "falign")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "falign")
        cmd.Dir = tmpdir
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Errorf("build failed: %v", err)
        }
-       cmd = exec.Command(tmpdir + "/falign")
+       cmd = testenv.Command(t, tmpdir+"/falign")
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Errorf("failed to run with err %v, output: %s", err, out)
@@ -677,12 +676,12 @@ func TestTrampoline(t *testing.T) {
        exe := filepath.Join(tmpdir, "hello.exe")
 
        for _, mode := range buildmodes {
-               cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
+               cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
                out, err := cmd.CombinedOutput()
                if err != nil {
                        t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
                }
-               cmd = exec.Command(exe)
+               cmd = testenv.Command(t, exe)
                out, err = cmd.CombinedOutput()
                if err != nil {
                        t.Errorf("executable failed to run (%s): %v\n%s", mode, err, out)
@@ -735,12 +734,12 @@ func TestTrampolineCgo(t *testing.T) {
        exe := filepath.Join(tmpdir, "hello.exe")
 
        for _, mode := range buildmodes {
-               cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
+               cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
                out, err := cmd.CombinedOutput()
                if err != nil {
                        t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
                }
-               cmd = exec.Command(exe)
+               cmd = testenv.Command(t, exe)
                out, err = cmd.CombinedOutput()
                if err != nil {
                        t.Errorf("executable failed to run (%s): %v\n%s", mode, err, out)
@@ -754,12 +753,12 @@ func TestTrampolineCgo(t *testing.T) {
                if runtime.GOARCH == "ppc64" || (runtime.GOARCH == "arm64" && runtime.GOOS == "windows") || !testenv.CanInternalLink() {
                        return // internal linking cgo is not supported
                }
-               cmd = exec.Command(testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2 -linkmode=internal", "-o", exe, src)
+               cmd = testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2 -linkmode=internal", "-o", exe, src)
                out, err = cmd.CombinedOutput()
                if err != nil {
                        t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
                }
-               cmd = exec.Command(exe)
+               cmd = testenv.Command(t, exe)
                out, err = cmd.CombinedOutput()
                if err != nil {
                        t.Errorf("executable failed to run (%s): %v\n%s", mode, err, out)
@@ -793,19 +792,19 @@ func TestIndexMismatch(t *testing.T) {
        testenv.WriteImportcfg(t, importcfgWithAFile, map[string]string{"a": aObj})
 
        // Build a program with main package importing package a.
-       cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgFile, "-p=a", "-o", aObj, aSrc)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgFile, "-p=a", "-o", aObj, aSrc)
        t.Log(cmd)
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compiling a.go failed: %v\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgWithAFile, "-p=main", "-I", tmpdir, "-o", mObj, mSrc)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgWithAFile, "-p=main", "-I", tmpdir, "-o", mObj, mSrc)
        t.Log(cmd)
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compiling main.go failed: %v\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
        t.Log(cmd)
        out, err = cmd.CombinedOutput()
        if err != nil {
@@ -814,13 +813,13 @@ func TestIndexMismatch(t *testing.T) {
 
        // Now, overwrite a.o with the object of b.go. This should
        // result in an index mismatch.
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgFile, "-p=a", "-o", aObj, bSrc)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgFile, "-p=a", "-o", aObj, bSrc)
        t.Log(cmd)
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compiling a.go failed: %v\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
        t.Log(cmd)
        out, err = cmd.CombinedOutput()
        if err == nil {
@@ -846,7 +845,7 @@ func TestPErsrcBinutils(t *testing.T) {
 
        pkgdir := filepath.Join("testdata", "pe-binutils")
        exe := filepath.Join(tmpdir, "a.exe")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe)
        cmd.Dir = pkgdir
        // cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
        out, err := cmd.CombinedOutput()
@@ -878,7 +877,7 @@ func TestPErsrcLLVM(t *testing.T) {
 
        pkgdir := filepath.Join("testdata", "pe-llvm")
        exe := filepath.Join(tmpdir, "a.exe")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe)
        cmd.Dir = pkgdir
        // cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
        out, err := cmd.CombinedOutput()
@@ -903,7 +902,7 @@ func TestContentAddressableSymbols(t *testing.T) {
        t.Parallel()
 
        src := filepath.Join("testdata", "testHashedSyms", "p.go")
-       cmd := exec.Command(testenv.GoToolPath(t), "run", src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Errorf("command %s failed: %v\n%s", cmd, err, out)
@@ -917,7 +916,7 @@ func TestReadOnly(t *testing.T) {
        t.Parallel()
 
        src := filepath.Join("testdata", "testRO", "x.go")
-       cmd := exec.Command(testenv.GoToolPath(t), "run", src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
        out, err := cmd.CombinedOutput()
        if err == nil {
                t.Errorf("running test program did not fail. output:\n%s", out)
@@ -953,7 +952,7 @@ func TestIssue38554(t *testing.T) {
                t.Fatalf("failed to write source file: %v", err)
        }
        exe := filepath.Join(tmpdir, "x.exe")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("build failed: %v\n%s", err, out)
@@ -1003,7 +1002,7 @@ func TestIssue42396(t *testing.T) {
                t.Fatalf("failed to write source file: %v", err)
        }
        exe := filepath.Join(tmpdir, "main.exe")
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-race", "-o", exe, src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-gcflags=-race", "-o", exe, src)
        out, err := cmd.CombinedOutput()
        if err == nil {
                t.Fatalf("build unexpectedly succeeded")
@@ -1073,14 +1072,14 @@ func TestLargeReloc(t *testing.T) {
        if err != nil {
                t.Fatalf("failed to write source file: %v", err)
        }
-       cmd := exec.Command(testenv.GoToolPath(t), "run", src)
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Errorf("build failed: %v. output:\n%s", err, out)
        }
 
        if testenv.HasCGO() { // currently all targets that support cgo can external link
-               cmd = exec.Command(testenv.GoToolPath(t), "run", "-ldflags=-linkmode=external", src)
+               cmd = testenv.Command(t, testenv.GoToolPath(t), "run", "-ldflags=-linkmode=external", src)
                out, err = cmd.CombinedOutput()
                if err != nil {
                        t.Fatalf("build failed: %v. output:\n%s", err, out)
@@ -1114,17 +1113,17 @@ func TestUnlinkableObj(t *testing.T) {
        if err != nil {
                t.Fatalf("failed to write source file: %v", err)
        }
-       cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-o", pObj, pSrc) // without -p
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-o", pObj, pSrc) // without -p
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compile p.go failed: %v. output:\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "-o", xObj, xSrc)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "-o", xObj, xSrc)
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compile x.go failed: %v. output:\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
        out, err = cmd.CombinedOutput()
        if err == nil {
                t.Fatalf("link did not fail")
@@ -1134,18 +1133,18 @@ func TestUnlinkableObj(t *testing.T) {
        }
 
        // It is okay to omit -p for (only) main package.
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=p", "-o", pObj, pSrc)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=p", "-o", pObj, pSrc)
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compile p.go failed: %v. output:\n%s", err, out)
        }
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-o", xObj, xSrc) // without -p
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-o", xObj, xSrc) // without -p
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("compile failed: %v. output:\n%s", err, out)
        }
 
-       cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Errorf("link failed: %v. output:\n%s", err, out)
index 796adfd422ddef25adec59d3fab7bef6bdaecbb5..45cb1b3ab6784fdcb27c7128be2a28bb342389b3 100644 (file)
@@ -14,7 +14,6 @@ import (
        "internal/buildcfg"
        "internal/testenv"
        "os"
-       "os/exec"
        "testing"
 )
 
@@ -83,13 +82,13 @@ func TestLargeText(t *testing.T) {
        }
 
        // Build and run with internal linking.
-       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "bigtext")
+       cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "bigtext")
        cmd.Dir = tmpdir
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("Build failed for big text program with internal linking: %v, output: %s", err, out)
        }
-       cmd = exec.Command("./bigtext")
+       cmd = testenv.Command(t, "./bigtext")
        cmd.Dir = tmpdir
        out, err = cmd.CombinedOutput()
        if err != nil {
@@ -97,13 +96,13 @@ func TestLargeText(t *testing.T) {
        }
 
        // Build and run with external linking
-       cmd = exec.Command(testenv.GoToolPath(t), "build", "-o", "bigtext", "-ldflags", "-linkmode=external")
+       cmd = testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "bigtext", "-ldflags", "-linkmode=external")
        cmd.Dir = tmpdir
        out, err = cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("Build failed for big text program with external linking: %v, output: %s", err, out)
        }
-       cmd = exec.Command("./bigtext")
+       cmd = testenv.Command(t, "./bigtext")
        cmd.Dir = tmpdir
        out, err = cmd.CombinedOutput()
        if err != nil {