"path/filepath"
"runtime"
"strings"
- "sync"
"testing"
)
os.Exit(m.Run())
}
-// addr2linePath returns the path to the "addr2line" binary to run.
-func addr2linePath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- addr2linePathOnce.Do(func() {
- addr2lineExePath, addr2linePathErr = os.Executable()
- })
- if addr2linePathErr != nil {
- t.Fatal(addr2linePathErr)
- }
- return addr2lineExePath
-}
-
-var (
- addr2linePathOnce sync.Once
- addr2lineExePath string
- addr2linePathErr error
-)
-
func loadSyms(t *testing.T, dbgExePath string) map[string]string {
cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "nm", dbgExePath)
out, err := cmd.CombinedOutput()
}
func runAddr2Line(t *testing.T, dbgExePath, addr string) (funcname, path, lineno string) {
- cmd := testenv.Command(t, addr2linePath(t), dbgExePath)
+ cmd := testenv.Command(t, testenv.Executable(t), dbgExePath)
cmd.Stdin = strings.NewReader(addr)
out, err := cmd.CombinedOutput()
if err != nil {
// Debug paths are stored slash-separated, so convert to system-native.
srcPath = filepath.FromSlash(srcPath)
fi2, err := os.Stat(srcPath)
-
if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if !os.SameFile(fi1, fi2) {
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
}
- if want := "124"; srcLineNo != want {
+ if want := "102"; srcLineNo != want {
t.Fatalf("line number = %v; want %s", srcLineNo, want)
}
}
-// This is line 123. The test depends on that.
+// This is line 101. The test depends on that.
func TestAddr2Line(t *testing.T) {
testenv.MustHaveGoBuild(t)
"testing"
)
-// testcovdata returns the path to the unit test executable to be used as
-// standin for 'go tool covdata'.
-func testcovdata(t testing.TB) string {
- exe, err := os.Executable()
- if err != nil {
- t.Helper()
- t.Fatal(err)
- }
- return exe
-}
-
// Top level tempdir for test.
var testTempDir string
s.exepath3, s.exedir3 = buildProg(t, "prog1", dir, "atomic", flags)
// Reuse unit test executable as tool to be tested.
- s.tool = testcovdata(t)
+ s.tool = testenv.Executable(t)
// Create a few coverage output dirs.
for i := 0; i < 4; i++ {
// test. At one point this was created via "go build"; we now reuse the unit
// test executable itself.
func testcover(t testing.TB) string {
- exe, err := os.Executable()
- if err != nil {
- t.Helper()
- t.Fatal(err)
- }
- return exe
+ return testenv.Executable(t)
}
// testTempDir is a temporary directory created in TestMain.
// "-toolexec" wrapper program to invoke the cover test executable
// itself via "go test -cover".
func TestCoverWithToolExec(t *testing.T) {
- testenv.MustHaveExec(t)
-
toolexecArg := "-toolexec=" + testcover(t)
t.Run("CoverHTML", func(t *testing.T) {
// Makes sure that `cover -func=profile.cov` reports accurate coverage.
// Issue #20515.
func TestCoverFunc(t *testing.T) {
- testenv.MustHaveExec(t)
-
// testcover -func ./testdata/profile.cov
coverProfile := filepath.Join(testdata, "profile.cov")
cmd := testenv.Command(t, testcover(t), "-func", coverProfile)
"path/filepath"
"runtime"
"strings"
- "sync"
"testing"
"text/template"
)
os.Exit(m.Run())
}
-// nmPath returns the path to the "nm" binary to run.
-func nmPath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- nmPathOnce.Do(func() {
- nmExePath, nmPathErr = os.Executable()
- })
- if nmPathErr != nil {
- t.Fatal(nmPathErr)
- }
- return nmExePath
-}
-
-var (
- nmPathOnce sync.Once
- nmExePath string
- nmPathErr error
-)
-
func TestNonGoExecs(t *testing.T) {
t.Parallel()
testfiles := []string{
exepath = tf
}
- cmd := testenv.Command(t, nmPath(t), exepath)
+ cmd := testenv.Command(t, testenv.Executable(t), exepath)
out, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("go tool nm %v: %v\n%s", exepath, err, string(out))
runtimeSyms["runtime.epclntab"] = "D"
}
- out, err = testenv.Command(t, nmPath(t), exe).CombinedOutput()
+ out, err = testenv.Command(t, testenv.Executable(t), exe).CombinedOutput()
if err != nil {
t.Fatalf("go tool nm: %v\n%s", err, string(out))
}
}
mylib := filepath.Join(libpath, "mylib.a")
- out, err = testenv.Command(t, nmPath(t), mylib).CombinedOutput()
+ out, err = testenv.Command(t, testenv.Executable(t), mylib).CombinedOutput()
if err != nil {
t.Fatalf("go tool nm: %v\n%s", err, string(out))
}
"path/filepath"
"runtime"
"strings"
- "sync"
"testing"
)
os.Exit(m.Run())
}
-// objdumpPath returns the path to the "objdump" binary to run.
-func objdumpPath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- objdumpPathOnce.Do(func() {
- objdumpExePath, objdumpPathErr = os.Executable()
- })
- if objdumpPathErr != nil {
- t.Fatal(objdumpPathErr)
- }
- return objdumpExePath
-}
-
-var (
- objdumpPathOnce sync.Once
- objdumpExePath string
- objdumpPathErr error
-)
-
var x86Need = []string{ // for both 386 and AMD64
"JMP main.main(SB)",
"CALL main.Println(SB)",
if printGnuAsm {
args = append([]string{"-gnu"}, args...)
}
- cmd = testenv.Command(t, objdumpPath(t), args...)
+ cmd = testenv.Command(t, testenv.Executable(t), args...)
cmd.Dir = "testdata" // "Bad line" bug #36683 is sensitive to being run in the source directory
out, err = cmd.CombinedOutput()
t.Logf("Running %v", cmd.Args)
hello,
}
- out, err = testenv.Command(t, objdumpPath(t), args...).CombinedOutput()
+ out, err = testenv.Command(t, testenv.Executable(t), args...).CombinedOutput()
if err != nil {
t.Fatalf("objdump fmthello.o: %v\n%s", err, out)
}
t.Fatalf("build failed: %v\n%s", err, out)
}
- cmd = testenv.Command(t, objdumpPath(t), obj)
+ cmd = testenv.Command(t, testenv.Executable(t), obj)
out, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("objdump failed: %v\n%s", err, out)
}
func TestGoObjOtherVersion(t *testing.T) {
- testenv.MustHaveExec(t)
t.Parallel()
obj := filepath.Join("testdata", "go116.o")
- cmd := testenv.Command(t, objdumpPath(t), obj)
+ cmd := testenv.Command(t, testenv.Executable(t), obj)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("objdump go116.o succeeded unexpectedly")
"path/filepath"
"runtime"
"strings"
- "sync"
"testing"
"time"
)
// packPath returns the path to the "pack" binary to run.
func packPath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- packPathOnce.Do(func() {
- packExePath, packPathErr = os.Executable()
- })
- if packPathErr != nil {
- t.Fatal(packPathErr)
- }
- return packExePath
+ return testenv.Executable(t)
}
-var (
- packPathOnce sync.Once
- packExePath string
- packPathErr error
-)
-
// testCreate creates an archive in the specified directory.
func testCreate(t *testing.T, dir string) {
name := filepath.Join(dir, "pack.a")
"path/filepath"
"runtime"
"strings"
- "sync"
"testing"
)
// pprofPath returns the path to the "pprof" binary to run.
func pprofPath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- pprofPathOnce.Do(func() {
- pprofExePath, pprofPathErr = os.Executable()
- })
- if pprofPathErr != nil {
- t.Fatal(pprofPathErr)
- }
- return pprofExePath
+ return testenv.Executable(t)
}
-var (
- pprofPathOnce sync.Once
- pprofExePath string
- pprofPathErr error
-)
-
// See also runtime/pprof.cpuProfilingBroken.
func mustHaveCPUProfiling(t *testing.T) {
switch runtime.GOOS {
"regexp"
"strconv"
"strings"
- "sync"
"testing"
)
// vetPath returns the path to the "vet" binary to run.
func vetPath(t testing.TB) string {
- t.Helper()
- testenv.MustHaveExec(t)
-
- vetPathOnce.Do(func() {
- vetExePath, vetPathErr = os.Executable()
- })
- if vetPathErr != nil {
- t.Fatal(vetPathErr)
- }
- return vetExePath
+ return testenv.Executable(t)
}
-var (
- vetPathOnce sync.Once
- vetExePath string
- vetPathErr error
-)
-
func vetCmd(t *testing.T, arg, pkg string) *exec.Cmd {
cmd := testenv.Command(t, testenv.GoToolPath(t), "vet", "-vettool="+vetPath(t), arg, path.Join("cmd/vet/testdata", pkg))
cmd.Env = os.Environ()