Commit 842b0583 authored by Keith Randall's avatar Keith Randall

all: use testing.GoToolPath instead of "go"

This change makes sure that tests are run with the correct
version of the go tool.  The correct version is the one that
we invoked with "go test", not the one that is first in our path.

Fixes #16577

Change-Id: If22c8f8c3ec9e7c35d094362873819f2fbb8559b
Reviewed-on: https://go-review.googlesource.com/28089Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent be23e98e
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
) )
func loadSyms(t *testing.T) map[string]string { func loadSyms(t *testing.T) map[string]string {
cmd := exec.Command("go", "tool", "nm", os.Args[0]) cmd := exec.Command(testenv.GoToolPath(t), "tool", "nm", os.Args[0])
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("go tool nm %v: %v\n%s", os.Args[0], err, string(out)) t.Fatalf("go tool nm %v: %v\n%s", os.Args[0], err, string(out))
...@@ -98,7 +98,7 @@ func TestAddr2Line(t *testing.T) { ...@@ -98,7 +98,7 @@ func TestAddr2Line(t *testing.T) {
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
exepath := filepath.Join(tmpDir, "testaddr2line.exe") exepath := filepath.Join(tmpDir, "testaddr2line.exe")
out, err := exec.Command("go", "build", "-o", exepath, "cmd/addr2line").CombinedOutput() out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("go build -o %v cmd/addr2line: %v\n%s", exepath, err, string(out)) t.Fatalf("go build -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
} }
......
...@@ -34,7 +34,7 @@ func TestAssembly(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestAssembly(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
for _, test := range asmTests { for _, test := range asmTests {
asm := compileToAsm(dir, test.arch, fmt.Sprintf(template, test.function)) asm := compileToAsm(t, dir, test.arch, fmt.Sprintf(template, test.function))
// Get rid of code for "".init. Also gets rid of type algorithms & other junk. // Get rid of code for "".init. Also gets rid of type algorithms & other junk.
if i := strings.Index(asm, "\n\"\".init "); i >= 0 { if i := strings.Index(asm, "\n\"\".init "); i >= 0 {
asm = asm[:i+1] asm = asm[:i+1]
...@@ -49,7 +49,7 @@ func TestAssembly(t *testing.T) { ...@@ -49,7 +49,7 @@ func TestAssembly(t *testing.T) {
// compile compiles the package pkg for architecture arch and // compile compiles the package pkg for architecture arch and
// returns the generated assembly. dir is a scratch directory. // returns the generated assembly. dir is a scratch directory.
func compileToAsm(dir, arch, pkg string) string { func compileToAsm(t *testing.T, dir, arch, pkg string) string {
// Create source. // Create source.
src := filepath.Join(dir, "test.go") src := filepath.Join(dir, "test.go")
f, err := os.Create(src) f, err := os.Create(src)
...@@ -60,7 +60,7 @@ func compileToAsm(dir, arch, pkg string) string { ...@@ -60,7 +60,7 @@ func compileToAsm(dir, arch, pkg string) string {
f.Close() f.Close()
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cmd := exec.Command("go", "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src) cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src)
cmd.Env = mergeEnvLists([]string{"GOARCH=" + arch}, os.Environ()) cmd.Env = mergeEnvLists([]string{"GOARCH=" + arch}, os.Environ())
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
...@@ -139,7 +139,7 @@ func TestLineNumber(t *testing.T) { ...@@ -139,7 +139,7 @@ func TestLineNumber(t *testing.T) {
t.Fatalf("could not write file: %v", err) t.Fatalf("could not write file: %v", err)
} }
cmd := exec.Command("go", "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src) cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("fail to run go tool compile: %v", err) t.Fatalf("fail to run go tool compile: %v", err)
......
...@@ -20,7 +20,7 @@ func TestBuiltin(t *testing.T) { ...@@ -20,7 +20,7 @@ func TestBuiltin(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
new, err := exec.Command("go", "run", "mkbuiltin.go", "-stdout").Output() new, err := exec.Command(testenv.GoToolPath(t), "run", "mkbuiltin.go", "-stdout").Output()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -47,14 +47,14 @@ func main() { ...@@ -47,14 +47,14 @@ func main() {
dst := filepath.Join(dir, "test") dst := filepath.Join(dir, "test")
// Compile source. // Compile source.
cmd := exec.Command("go", "build", "-o", dst, src) cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", dst, src)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
log.Fatalf("could not build target: %v", err) log.Fatalf("could not build target: %v", err)
} }
// Check destination to see if scanf code was included. // Check destination to see if scanf code was included.
cmd = exec.Command("go", "tool", "nm", dst) cmd = exec.Command(testenv.GoToolPath(t), "tool", "nm", dst)
out, err = cmd.CombinedOutput() out, err = cmd.CombinedOutput()
if err != nil { if err != nil {
log.Fatalf("could not read target: %v", err) log.Fatalf("could not read target: %v", err)
...@@ -91,7 +91,7 @@ func main() { ...@@ -91,7 +91,7 @@ func main() {
f.Close() f.Close()
// Compile source. // Compile source.
cmd := exec.Command("go", "build", "-gcflags", "-S", "-o", filepath.Join(dir, "test"), src) cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags", "-S", "-o", filepath.Join(dir, "test"), src)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
log.Fatalf("could not build target: %v", err) log.Fatalf("could not build target: %v", err)
......
...@@ -25,7 +25,7 @@ func buildTest(t *testing.T, filename string) { ...@@ -25,7 +25,7 @@ func buildTest(t *testing.T, filename string) {
func doTest(t *testing.T, filename string, kind string) { func doTest(t *testing.T, filename string, kind string) {
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cmd := exec.Command("go", kind, filepath.Join("testdata", filename)) cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename))
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
......
...@@ -62,7 +62,7 @@ func TestCover(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestCover(t *testing.T) {
} }
// go build -o testcover // go build -o testcover
cmd := exec.Command("go", "build", "-o", testcover) cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", testcover)
run(cmd, t) run(cmd, t)
// defer removal of testcover // defer removal of testcover
...@@ -78,7 +78,7 @@ func TestCover(t *testing.T) { ...@@ -78,7 +78,7 @@ func TestCover(t *testing.T) {
} }
// go run ./testdata/main.go ./testdata/test.go // go run ./testdata/main.go ./testdata/test.go
cmd = exec.Command("go", "run", testMain, coverOutput) cmd = exec.Command(testenv.GoToolPath(t), "run", testMain, coverOutput)
run(cmd, t) run(cmd, t)
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package main package main
import ( import (
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -45,7 +46,7 @@ func TestAbsolutePath(t *testing.T) { ...@@ -45,7 +46,7 @@ func TestAbsolutePath(t *testing.T) {
noVolume := file[len(filepath.VolumeName(file)):] noVolume := file[len(filepath.VolumeName(file)):]
wrongPath := filepath.Join(dir, noVolume) wrongPath := filepath.Join(dir, noVolume)
output, err := exec.Command("go", "build", noVolume).CombinedOutput() output, err := exec.Command(testenv.GoToolPath(t), "build", noVolume).CombinedOutput()
if err == nil { if err == nil {
t.Fatal("build should fail") t.Fatal("build should fail")
} }
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"go/build"
"internal/testenv" "internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -96,13 +95,8 @@ func asmOutput(t *testing.T, s string) []byte { ...@@ -96,13 +95,8 @@ func asmOutput(t *testing.T, s string) []byte {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
gofolder := filepath.Join(build.Default.GOROOT, "bin")
if gobin := os.Getenv("GOBIN"); len(gobin) != 0 {
gofolder = gobin
}
cmd := exec.Command( cmd := exec.Command(
filepath.Join(gofolder, "go"), "tool", "asm", "-S", "-dynlink", testenv.GoToolPath(t), "tool", "asm", "-S", "-dynlink",
"-o", filepath.Join(tmpdir, "output.6"), tmpfile.Name()) "-o", filepath.Join(tmpdir, "output.6"), tmpfile.Name())
var env []string var env []string
......
...@@ -65,7 +65,7 @@ func TestNM(t *testing.T) { ...@@ -65,7 +65,7 @@ func TestNM(t *testing.T) {
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
testnmpath := filepath.Join(tmpDir, "testnm.exe") testnmpath := filepath.Join(tmpDir, "testnm.exe")
out, err := exec.Command("go", "build", "-o", testnmpath, "cmd/nm").CombinedOutput() out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", testnmpath, "cmd/nm").CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("go build -o %v cmd/nm: %v\n%s", testnmpath, err, string(out)) t.Fatalf("go build -o %v cmd/nm: %v\n%s", testnmpath, err, string(out))
} }
......
...@@ -25,7 +25,7 @@ func buildObjdump(t *testing.T) (tmp, exe string) { ...@@ -25,7 +25,7 @@ func buildObjdump(t *testing.T) (tmp, exe string) {
} }
exe = filepath.Join(tmp, "testobjdump.exe") exe = filepath.Join(tmp, "testobjdump.exe")
out, err := exec.Command("go", "build", "-o", exe, "cmd/objdump").CombinedOutput() out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "cmd/objdump").CombinedOutput()
if err != nil { if err != nil {
os.RemoveAll(tmp) os.RemoveAll(tmp)
t.Fatalf("go build -o %v cmd/objdump: %v\n%s", exe, err, string(out)) t.Fatalf("go build -o %v cmd/objdump: %v\n%s", exe, err, string(out))
...@@ -66,7 +66,7 @@ func testDisasm(t *testing.T, flags ...string) { ...@@ -66,7 +66,7 @@ func testDisasm(t *testing.T, flags ...string) {
args := []string{"build", "-o", hello} args := []string{"build", "-o", hello}
args = append(args, flags...) args = append(args, flags...)
args = append(args, "testdata/fmthello.go") args = append(args, "testdata/fmthello.go")
out, err := exec.Command("go", args...).CombinedOutput() out, err := exec.Command(testenv.GoToolPath(t), args...).CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("go build fmthello.go: %v\n%s", err, out) t.Fatalf("go build fmthello.go: %v\n%s", err, out)
} }
......
...@@ -218,10 +218,11 @@ func TestHello(t *testing.T) { ...@@ -218,10 +218,11 @@ func TestHello(t *testing.T) {
return doRun(t, dir, args...) return doRun(t, dir, args...)
} }
run("go", "build", "cmd/pack") // writes pack binary to dir goBin := testenv.GoToolPath(t)
run("go", "tool", "compile", "hello.go") run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "hello.go")
run("./pack", "grc", "hello.a", "hello.o") run("./pack", "grc", "hello.a", "hello.o")
run("go", "tool", "link", "-o", "a.out", "hello.a") run(goBin, "tool", "link", "-o", "a.out", "hello.a")
out := run("./a.out") out := run("./a.out")
if out != "hello world\n" { if out != "hello world\n" {
t.Fatalf("incorrect output: %q, want %q", out, "hello world\n") t.Fatalf("incorrect output: %q, want %q", out, "hello world\n")
...@@ -282,11 +283,12 @@ func TestLargeDefs(t *testing.T) { ...@@ -282,11 +283,12 @@ func TestLargeDefs(t *testing.T) {
return doRun(t, dir, args...) return doRun(t, dir, args...)
} }
run("go", "build", "cmd/pack") // writes pack binary to dir goBin := testenv.GoToolPath(t)
run("go", "tool", "compile", "large.go") run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "large.go")
run("./pack", "grc", "large.a", "large.o") run("./pack", "grc", "large.a", "large.o")
run("go", "tool", "compile", "-I", ".", "main.go") run(goBin, "tool", "compile", "-I", ".", "main.go")
run("go", "tool", "link", "-L", ".", "-o", "a.out", "main.o") run(goBin, "tool", "link", "-L", ".", "-o", "a.out", "main.o")
out := run("./a.out") out := run("./a.out")
if out != "ok\n" { if out != "ok\n" {
t.Fatalf("incorrect output: %q, want %q", out, "ok\n") t.Fatalf("incorrect output: %q, want %q", out, "ok\n")
......
...@@ -53,7 +53,7 @@ func Build(t *testing.T) { ...@@ -53,7 +53,7 @@ func Build(t *testing.T) {
if failed { if failed {
t.Skip("cannot run on this environment") t.Skip("cannot run on this environment")
} }
cmd := exec.Command("go", "build", "-o", binary) cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", binary)
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if err != nil { if err != nil {
failed = true failed = true
......
...@@ -938,7 +938,7 @@ func TestParsePEMCRL(t *testing.T) { ...@@ -938,7 +938,7 @@ func TestParsePEMCRL(t *testing.T) {
func TestImports(t *testing.T) { func TestImports(t *testing.T) {
testenv.MustHaveGoRun(t) testenv.MustHaveGoRun(t)
if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil { if err := exec.Command(testenv.GoToolPath(t), "run", "x509_test_import.go").Run(); err != nil {
t.Errorf("failed to run x509_test_import.go: %s", err) t.Errorf("failed to run x509_test_import.go: %s", err)
} }
} }
......
...@@ -37,7 +37,7 @@ func dotest(t *testing.T) { ...@@ -37,7 +37,7 @@ func dotest(t *testing.T) {
// the resulting binary looks like it was built from pclinetest.s, // the resulting binary looks like it was built from pclinetest.s,
// but we have renamed it to keep it away from the go tool. // but we have renamed it to keep it away from the go tool.
pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest") pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest")
cmd := exec.Command("go", "tool", "asm", "-o", pclinetestBinary+".o", "pclinetest.asm") cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-o", pclinetestBinary+".o", "pclinetest.asm")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
...@@ -58,7 +58,7 @@ func dotest(t *testing.T) { ...@@ -58,7 +58,7 @@ func dotest(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
cmd = exec.Command("go", "tool", "link", "-H", "linux", cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-H", "linux",
"-o", pclinetestBinary, pclinetestBinary+".o") "-o", pclinetestBinary, pclinetestBinary+".o")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
......
...@@ -307,7 +307,7 @@ func main() { ...@@ -307,7 +307,7 @@ func main() {
src := filepath.Join(tmpdir, "a.go") src := filepath.Join(tmpdir, "a.go")
exe := filepath.Join(tmpdir, "a.exe") exe := filepath.Join(tmpdir, "a.exe")
err = ioutil.WriteFile(src, []byte(prog), 0644) err = ioutil.WriteFile(src, []byte(prog), 0644)
output, err := exec.Command("go", "build", "-o", exe, src).CombinedOutput() output, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("building test executable failed: %s %s", err, output) t.Fatalf("building test executable failed: %s %s", err, output)
} }
......
...@@ -35,8 +35,7 @@ func skipSpecialPlatforms(t *testing.T) { ...@@ -35,8 +35,7 @@ func skipSpecialPlatforms(t *testing.T) {
} }
func compile(t *testing.T, dirname, filename string) string { func compile(t *testing.T, dirname, filename string) string {
testenv.MustHaveGoBuild(t) cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", filename)
cmd := exec.Command("go", "tool", "compile", filename)
cmd.Dir = dirname cmd.Dir = dirname
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
......
...@@ -66,7 +66,7 @@ func TestCleanHost(t *testing.T) { ...@@ -66,7 +66,7 @@ func TestCleanHost(t *testing.T) {
// server code. // server code.
func TestCmdGoNoHTTPServer(t *testing.T) { func TestCmdGoNoHTTPServer(t *testing.T) {
goBin := testenv.GoToolPath(t) goBin := testenv.GoToolPath(t)
out, err := exec.Command("go", "tool", "nm", goBin).CombinedOutput() out, err := exec.Command(goBin, "tool", "nm", goBin).CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("go tool nm: %v: %s", err, out) t.Fatalf("go tool nm: %v: %s", err, out)
} }
......
...@@ -6,6 +6,7 @@ package signal ...@@ -6,6 +6,7 @@ package signal
import ( import (
"bytes" "bytes"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -75,7 +76,7 @@ func main() { ...@@ -75,7 +76,7 @@ func main() {
// compile it // compile it
exe := name + ".exe" exe := name + ".exe"
defer os.Remove(exe) defer os.Remove(exe)
o, err := exec.Command("go", "build", "-o", exe, src).CombinedOutput() o, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("Failed to compile: %v\n%v", err, string(o)) t.Fatalf("Failed to compile: %v\n%v", err, string(o))
} }
......
...@@ -255,7 +255,7 @@ func testCgoPprof(t *testing.T, buildArg, runArg string) { ...@@ -255,7 +255,7 @@ func testCgoPprof(t *testing.T, buildArg, runArg string) {
fn := strings.TrimSpace(string(got)) fn := strings.TrimSpace(string(got))
defer os.Remove(fn) defer os.Remove(fn)
cmd := testEnv(exec.Command("go", "tool", "pprof", "-top", "-nodecount=1", exe, fn)) cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-top", "-nodecount=1", exe, fn))
found := false found := false
for i, e := range cmd.Env { for i, e := range cmd.Env {
......
...@@ -137,7 +137,7 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error) ...@@ -137,7 +137,7 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error)
} }
exe := filepath.Join(testprog.dir, name+".exe") exe := filepath.Join(testprog.dir, name+".exe")
cmd := exec.Command("go", append([]string{"build", "-o", exe}, flags...)...) cmd := exec.Command(testenv.GoToolPath(t), append([]string{"build", "-o", exe}, flags...)...)
cmd.Dir = "testdata/" + binary cmd.Dir = "testdata/" + binary
out, err := testEnv(cmd).CombinedOutput() out, err := testEnv(cmd).CombinedOutput()
if err != nil { if err != nil {
...@@ -159,7 +159,7 @@ var ( ...@@ -159,7 +159,7 @@ var (
func checkStaleRuntime(t *testing.T) { func checkStaleRuntime(t *testing.T) {
staleRuntimeOnce.Do(func() { staleRuntimeOnce.Do(func() {
// 'go run' uses the installed copy of runtime.a, which may be out of date. // 'go run' uses the installed copy of runtime.a, which may be out of date.
out, err := testEnv(exec.Command("go", "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput() out, err := testEnv(exec.Command(testenv.GoToolPath(t), "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput()
if err != nil { if err != nil {
staleRuntimeErr = fmt.Errorf("failed to execute 'go list': %v\n%v", err, string(out)) staleRuntimeErr = fmt.Errorf("failed to execute 'go list': %v\n%v", err, string(out))
return return
...@@ -459,7 +459,7 @@ func TestMemPprof(t *testing.T) { ...@@ -459,7 +459,7 @@ func TestMemPprof(t *testing.T) {
fn := strings.TrimSpace(string(got)) fn := strings.TrimSpace(string(got))
defer os.Remove(fn) defer os.Remove(fn)
cmd := testEnv(exec.Command("go", "tool", "pprof", "-alloc_space", "-top", exe, fn)) cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-alloc_space", "-top", exe, fn))
found := false found := false
for i, e := range cmd.Env { for i, e := range cmd.Env {
......
...@@ -47,7 +47,7 @@ func TestCrashDumpsAllThreads(t *testing.T) { ...@@ -47,7 +47,7 @@ func TestCrashDumpsAllThreads(t *testing.T) {
t.Fatalf("failed to create Go file: %v", err) t.Fatalf("failed to create Go file: %v", err)
} }
cmd := exec.Command("go", "build", "-o", "a.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir cmd.Dir = dir
out, err := testEnv(cmd).CombinedOutput() out, err := testEnv(cmd).CombinedOutput()
if err != nil { if err != nil {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package race_test package race_test
import ( import (
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -41,7 +42,7 @@ func TestOutput(t *testing.T) { ...@@ -41,7 +42,7 @@ func TestOutput(t *testing.T) {
t.Fatalf("failed to close file: %v", err) t.Fatalf("failed to close file: %v", err)
} }
// Pass -l to the compiler to test stack traces. // Pass -l to the compiler to test stack traces.
cmd := exec.Command("go", test.run, "-race", "-gcflags=-l", src) cmd := exec.Command(testenv.GoToolPath(t), test.run, "-race", "-gcflags=-l", src)
// GODEBUG spoils program output, GOMAXPROCS makes it flaky. // GODEBUG spoils program output, GOMAXPROCS makes it flaky.
for _, env := range os.Environ() { for _, env := range os.Environ() {
if strings.HasPrefix(env, "GODEBUG=") || if strings.HasPrefix(env, "GODEBUG=") ||
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"log" "log"
"math/rand" "math/rand"
...@@ -43,7 +44,7 @@ const ( ...@@ -43,7 +44,7 @@ const (
) )
func TestRace(t *testing.T) { func TestRace(t *testing.T) {
testOutput, err := runTests() testOutput, err := runTests(t)
if err != nil { if err != nil {
t.Fatalf("Failed to run tests: %v\n%v", err, string(testOutput)) t.Fatalf("Failed to run tests: %v\n%v", err, string(testOutput))
} }
...@@ -141,14 +142,14 @@ func processLog(testName string, tsanLog []string) string { ...@@ -141,14 +142,14 @@ func processLog(testName string, tsanLog []string) string {
// runTests assures that the package and its dependencies is // runTests assures that the package and its dependencies is
// built with instrumentation enabled and returns the output of 'go test' // built with instrumentation enabled and returns the output of 'go test'
// which includes possible data race reports from ThreadSanitizer. // which includes possible data race reports from ThreadSanitizer.
func runTests() ([]byte, error) { func runTests(t *testing.T) ([]byte, error) {
tests, err := filepath.Glob("./testdata/*_test.go") tests, err := filepath.Glob("./testdata/*_test.go")
if err != nil { if err != nil {
return nil, err return nil, err
} }
args := []string{"test", "-race", "-v"} args := []string{"test", "-race", "-v"}
args = append(args, tests...) args = append(args, tests...)
cmd := exec.Command("go", args...) cmd := exec.Command(testenv.GoToolPath(t), args...)
// The following flags turn off heuristics that suppress seemingly identical reports. // The following flags turn off heuristics that suppress seemingly identical reports.
// It is required because the tests contain a lot of data races on the same addresses // It is required because the tests contain a lot of data races on the same addresses
// (the tests are simple and the memory is constantly reused). // (the tests are simple and the memory is constantly reused).
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
package race_test package race_test
import ( import (
"internal/testenv"
"os" "os"
"os/exec" "os/exec"
"testing" "testing"
) )
func TestNoRaceCgoSync(t *testing.T) { func TestNoRaceCgoSync(t *testing.T) {
cmd := exec.Command("go", "run", "-race", "cgo_test_main.go") cmd := exec.Command(testenv.GoToolPath(t), "run", "-race", "cgo_test_main.go")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
......
...@@ -93,7 +93,7 @@ func TestGdbPython(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestGdbPython(t *testing.T) {
t.Fatalf("failed to create file: %v", err) t.Fatalf("failed to create file: %v", err)
} }
cmd := exec.Command("go", "build", "-o", "a.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir cmd.Dir = dir
out, err := testEnv(cmd).CombinedOutput() out, err := testEnv(cmd).CombinedOutput()
if err != nil { if err != nil {
...@@ -137,7 +137,7 @@ func TestGdbPython(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestGdbPython(t *testing.T) {
// This can happen when using all.bash with // This can happen when using all.bash with
// GOROOT_FINAL set, because the tests are run before // GOROOT_FINAL set, because the tests are run before
// the final installation of the files. // the final installation of the files.
cmd := exec.Command("go", "env", "GOROOT") cmd := exec.Command(testenv.GoToolPath(t), "env", "GOROOT")
cmd.Env = []string{} cmd.Env = []string{}
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil && bytes.Contains(out, []byte("cannot find GOROOT")) { if err != nil && bytes.Contains(out, []byte("cannot find GOROOT")) {
...@@ -227,7 +227,7 @@ func TestGdbBacktrace(t *testing.T) { ...@@ -227,7 +227,7 @@ func TestGdbBacktrace(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to create file: %v", err) t.Fatalf("failed to create file: %v", err)
} }
cmd := exec.Command("go", "build", "-o", "a.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir cmd.Dir = dir
out, err := testEnv(cmd).CombinedOutput() out, err := testEnv(cmd).CombinedOutput()
if err != nil { if err != nil {
......
...@@ -158,7 +158,7 @@ func TestLldbPython(t *testing.T) { ...@@ -158,7 +158,7 @@ func TestLldbPython(t *testing.T) {
t.Fatalf("failed to create file: %v", err) t.Fatalf("failed to create file: %v", err)
} }
cmd := exec.Command("go", "build", "-gcflags", "-N -l", "-o", "a.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags", "-N -l", "-o", "a.exe")
cmd.Dir = dir cmd.Dir = dir
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
...@@ -198,7 +198,7 @@ func TestDwarfAranges(t *testing.T) { ...@@ -198,7 +198,7 @@ func TestDwarfAranges(t *testing.T) {
t.Fatalf("failed to create file: %v", err) t.Fatalf("failed to create file: %v", err)
} }
cmd := exec.Command("go", "build", "-o", "a.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe")
cmd.Dir = dir cmd.Dir = dir
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment