}
// Run the resulting binary.
- cmd := exec.Command(dst.Name())
+ cmd := testenv.Command(t, dst.Name())
testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "TESTGOAMD64V1=yes")
cmd.Env = append(cmd.Env, fmt.Sprintf("GODEBUG=%s", strings.Join(features, ",")))
if false {
// TODO: go tool objdump doesn't disassemble the bmi1 instructions
// in question correctly. See issue 48584.
- cmd := exec.Command("go", "tool", "objdump", src)
+ cmd := testenv.Command(t, "go", "tool", "objdump", src)
var err error
disasm, err = cmd.StdoutPipe()
if err != nil {
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
+ t.Cleanup(func() {
+ if err := cmd.Wait(); err != nil {
+ t.Error(err)
+ }
+ })
re = regexp.MustCompile(`^[^:]*:[-\d]+\s+0x([\da-f]+)\s+([\da-f]+)\s+([A-Z]+)`)
} else {
// TODO: we're depending on platform-native objdump here. Hence the Skipf
// below if it doesn't run for some reason.
- cmd := exec.Command("objdump", "-d", src)
+ cmd := testenv.Command(t, "objdump", "-d", src)
var err error
disasm, err = cmd.StdoutPipe()
if err != nil {
}
t.Fatal(err)
}
+ t.Cleanup(func() {
+ if err := cmd.Wait(); err != nil {
+ t.Error(err)
+ }
+ })
re = regexp.MustCompile(`^\s*([\da-f]+):\s*((?:[\da-f][\da-f] )+)\s*([a-z\d]+)`)
}
"fmt"
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"runtime"
"sort"
}
args = append(args, "-o", dst, src)
- cmd := exec.Command(testenv.GoToolPath(t), args...)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
if b, err := cmd.CombinedOutput(); err != nil {
t.Logf("build: %s\n", string(b))
t.Fatal(err)
"internal/goexperiment"
"internal/testenv"
"os"
- "os/exec"
"path"
"path/filepath"
"runtime"
importcfgfile := filepath.Join(outdirname, basename) + ".importcfg"
testenv.WriteImportcfg(t, importcfgfile, packagefiles)
pkgpath := path.Join("testdata", basename)
- cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename)
cmd.Dir = dirname
out, err := cmd.CombinedOutput()
if err != nil {
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"runtime"
"strings"
func testLogOpt(t *testing.T, flag, src, outfile string) (string, error) {
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", flag, "-o", outfile, src}
t.Log(run)
- cmd := exec.Command(run[0], run[1:]...)
+ cmd := testenv.Command(t, run[0], run[1:]...)
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
return string(out), err
// Notice the specified import path "x"
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", flag, "-o", outfile, src}
t.Log(run)
- cmd := exec.Command(run[0], run[1:]...)
+ cmd := testenv.Command(t, run[0], run[1:]...)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
// Notice the specified import path "x"
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", "-json=0,file://log/opt", "-o", outfile, src}
t.Log(run)
- cmd := exec.Command(run[0], run[1:]...)
+ cmd := testenv.Command(t, run[0], run[1:]...)
cmd.Dir = dir
cmd.Env = append(os.Environ(), "GOARCH="+goarch, "GOOS="+goos)
out, err := cmd.CombinedOutput()
"internal/buildcfg"
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"reflect"
"regexp"
panic(fmt.Sprintf("Could not get abspath of testdata directory and file, %v", err))
}
- cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "foo.o", "-gcflags=-d=ssa/genssa/dump="+function+" "+moreGCFlags, source)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "foo.o", "-gcflags=-d=ssa/genssa/dump="+function+" "+moreGCFlags, source)
cmd.Dir = tmpdir
cmd.Env = replaceEnv(cmd.Env, "GOSSADIR", tmpdir)
testGoos := "linux" // default to linux
tmplog := tmpbase + ".nexts"
var dbg dbgr
if *useGdb {
- dbg = newGdb(tag, exe)
+ dbg = newGdb(t, tag, exe)
} else {
- dbg = newDelve(tag, exe)
+ dbg = newDelve(t, tag, exe)
}
h1 := runDbgr(dbg, count)
if *dryrun {
if !h0.equals(h1) {
// Be very noisy about exactly what's wrong to simplify debugging.
h1.write(tmplog)
- cmd := exec.Command("diff", "-u", nextlog, tmplog)
+ cmd := testenv.Command(t, "diff", "-u", nextlog, tmplog)
line := asCommandLine("", cmd)
bytes, err := cmd.CombinedOutput()
if err != nil && len(bytes) == 0 {
func runGo(t *testing.T, dir string, args ...string) string {
var stdout, stderr strings.Builder
- cmd := exec.Command(testenv.GoToolPath(t), args...)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
cmd.Dir = dir
if *dryrun {
fmt.Printf("%s\n", asCommandLine("", cmd))
function string
}
-func newDelve(tag, executable string, args ...string) dbgr {
- cmd := exec.Command("dlv", "exec", executable)
+func newDelve(t testing.TB, tag, executable string, args ...string) dbgr {
+ cmd := testenv.Command(t, "dlv", "exec", executable)
cmd.Env = replaceEnv(cmd.Env, "TERM", "dumb")
if len(args) > 0 {
cmd.Args = append(cmd.Args, "--")
function string
}
-func newGdb(tag, executable string, args ...string) dbgr {
+func newGdb(t testing.TB, tag, executable string, args ...string) dbgr {
// Turn off shell, necessary for Darwin apparently
- cmd := exec.Command(gdb, "-nx",
+ cmd := testenv.Command(t, gdb, "-nx",
"-iex", fmt.Sprintf("add-auto-load-safe-path %s/src/runtime", runtime.GOROOT()),
"-ex", "set startup-with-shell off", executable)
cmd.Env = replaceEnv(cmd.Env, "TERM", "dumb")
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"regexp"
"runtime"
defer os.RemoveAll(tmpdir)
source := filepath.Join("testdata", "fma.go")
output := filepath.Join(tmpdir, "fma.exe")
- cmd := exec.Command(gocmd, "build", "-o", output, source)
+ cmd := testenv.Command(t, gocmd, "build", "-o", output, source)
// The hash-dependence on file path name is dodged by specifying "all hashes ending in 1" plus "all hashes ending in 0"
// i.e., all hashes. This will print all the FMAs; this test is only interested in one of them (that should appear near the end).
cmd.Env = append(cmd.Env, "GOCOMPILEDEBUG=fmahash=1/0", "GOOS=linux", "GOARCH=arm64", "HOME="+tmpdir)
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"testing"
)
t.Fatalf("write file failed: %v", err)
}
- cmd := exec.Command(testenv.GoToolPath(t), "run", "-gcflags=all="+flag, src)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "run", "-gcflags=all="+flag, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go run failed: %v\n%s", err, out)
import (
"internal/testenv"
- "os/exec"
"strings"
"testing"
)
func TestDeps(t *testing.T) {
- out, err := exec.Command(testenv.GoToolPath(t), "list", "-f", "{{.Deps}}", "cmd/compile/internal/gc").Output()
+ out, err := testenv.Command(t, testenv.GoToolPath(t), "list", "-f", "{{.Deps}}", "cmd/compile/internal/gc").Output()
if err != nil {
t.Fatal(err)
}
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"strings"
"testing"
t.Fatalf("could not write file: %v", err)
}
- cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go tool compile: %v\n%s", err, out)
"bytes"
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"strings"
"testing"
dst := filepath.Join(dir, "test")
// Compile source.
- cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", dst, src)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", dst, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("could not build target: %v\n%s", err, out)
}
// Check destination to see if scanf code was included.
- cmd = exec.Command(testenv.GoToolPath(t), "tool", "nm", dst)
+ cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "nm", dst)
out, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("could not read target: %v", err)
f.Close()
// Compile source.
- cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags", "-S", "-o", filepath.Join(dir, "test"), src)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-gcflags", "-S", "-o", filepath.Join(dir, "test"), src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("could not build target: %v\n%s", err, out)
"internal/testenv"
"io"
"math/bits"
- "os/exec"
"regexp"
"runtime"
"strings"
}
args := append([]string{"build", "-gcflags=-m -m", "-tags=math_big_pure_go"}, pkgs...)
- cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), args...))
+ cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), args...))
pr, pw := io.Pipe()
cmd.Stdout = pw
cmd.Stderr = pw
for _, mode := range modes {
// Build the Go runtime with "-m", capturing output.
args := []string{"build", "-gcflags=runtime=-m", "runtime"}
- cmd := exec.Command(testenv.GoToolPath(t), args...)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
b, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed (%v): %s", err, b)
// Redo the build with -cover, also with "-m".
args = []string{"build", "-gcflags=runtime=-m", mode, "runtime"}
- cmd = exec.Command(testenv.GoToolPath(t), args...)
+ cmd = testenv.Command(t, testenv.GoToolPath(t), args...)
b, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed (%v): %s", err, b)
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"regexp"
"testing"
outname := "ptrsort.out"
gotool := testenv.GoToolPath(t)
dest := filepath.Join(tmpdir, exename)
- cmd := exec.Command(gotool, "build", "-o", dest, filepath.Join("testdata", filename))
+ cmd := testenv.Command(t, gotool, "build", "-o", dest, filepath.Join("testdata", filename))
if output, err = cmd.CombinedOutput(); err != nil {
t.Fatalf("Failed: %v:\nOutput: %s\n", err, output)
}
// Test that there is exactly one shape-based instantiation of Sort in
// the executable.
- cmd = exec.Command(gotool, "tool", "nm", dest)
+ cmd = testenv.Command(t, gotool, "tool", "nm", dest)
if output, err = cmd.CombinedOutput(); err != nil {
t.Fatalf("Failed: %v:\nOut: %s\n", err, output)
}
}
// Actually run the test and make sure output is correct.
- cmd = exec.Command(gotool, "run", filepath.Join("testdata", filename))
+ cmd = testenv.Command(t, gotool, "run", filepath.Join("testdata", filename))
if output, err = cmd.CombinedOutput(); err != nil {
t.Fatalf("Failed: %v:\nOut: %s\n", err, output)
}
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"testing"
)
func testLang(t *testing.T, lang, src, outfile string) error {
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", "-lang", lang, "-o", outfile, src}
t.Log(run)
- out, err := exec.Command(run[0], run[1:]...).CombinedOutput()
+ out, err := testenv.Command(t, run[0], run[1:]...).CombinedOutput()
t.Logf("%s", out)
return err
}
"internal/testenv"
"io"
"os"
- "os/exec"
"path/filepath"
"regexp"
"strings"
pprof := filepath.Join(dir, "inline_hot.pprof")
gcflag := fmt.Sprintf("-gcflags=-m -m -pgoprofile=%s -d=pgoinlinebudget=160,pgoinlinecdfthreshold=90", pprof)
out := filepath.Join(dir, "test.exe")
- cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "test", "-c", "-o", out, gcflag, "."))
+ cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "test", "-c", "-o", out, gcflag, "."))
cmd.Dir = dir
pr, pw, err := os.Pipe()
"bytes"
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"testing"
)
for i := 0; i < iters; i++ {
// Note: use -c 2 to expose any nondeterminism which is the result
// of the runtime scheduler.
- out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput()
+ out, err := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=p", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput()
if err != nil {
t.Fatalf("failed to compile: %v\n%s", err, out)
}
s := &scenarios[i]
s.libpath = filepath.Join(tmpdir, s.tag+".a")
// Note: use of "-p" required in order for DWARF to be generated.
- cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
"go/token"
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"runtime"
"strings"
testenv.MustHaveGoRun(t)
gotool := testenv.GoToolPath(t)
var stdout, stderr bytes.Buffer
- cmd := exec.Command(gotool, "run", filepath.Join("testdata", filename))
+ cmd := testenv.Command(t, gotool, "run", filepath.Join("testdata", filename))
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
stdout.Reset()
stderr.Reset()
- cmd = exec.Command(gotool, "run", "-gcflags=-d=ssa/check/on", rungo)
+ cmd = testenv.Command(t, gotool, "run", "-gcflags=-d=ssa/check/on", rungo)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = append(cmd.Env, ev...)
for _, flag := range flags {
args := []string{"test", "-c", "-gcflags=-d=ssa/check/on" + flag, "-o", filepath.Join(tmpdir, "code.test")}
args = append(args, srcs...)
- out, err := exec.Command(gotool, args...).CombinedOutput()
+ out, err := testenv.Command(t, gotool, args...).CombinedOutput()
if err != nil || len(out) != 0 {
t.Fatalf("Build failed: %v\n%s\n", err, out)
}
continue
}
t.Run(fmt.Sprintf("%s%s", test.name[4:], flag), func(t *testing.T) {
- out, err := exec.Command(filepath.Join(tmpdir, "code.test"), "-test.run="+test.name).CombinedOutput()
+ out, err := testenv.Command(t, filepath.Join(tmpdir, "code.test"), "-test.run="+test.name).CombinedOutput()
if err != nil || string(out) != "PASS\n" {
t.Errorf("Failed:\n%s\n", out)
}
"bytes"
"internal/testenv"
"os"
- "os/exec"
"testing"
)
t.Fatal(err)
}
- new, err := exec.Command(testenv.GoToolPath(t), "run", "mkbuiltin.go", "-stdout").Output()
+ new, err := testenv.Command(t, testenv.GoToolPath(t), "run", "mkbuiltin.go", "-stdout").Output()
if err != nil {
t.Fatal(err)
}