]> Cypherpunks repositories - gostls13.git/commitdiff
all: use testenv.Executable instead of os.Executable and os.Args[0]
authorqmuntal <quimmuntal@gmail.com>
Mon, 24 Feb 2025 08:43:41 +0000 (09:43 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 24 Feb 2025 19:03:10 +0000 (11:03 -0800)
In test files, using testenv.Executable is more reliable than
os.Executable or os.Args[0].

Change-Id: I88e577efeabc20d02ada27bf706ae4523129128e
Reviewed-on: https://go-review.googlesource.com/c/go/+/651955
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
29 files changed:
src/cmd/cgo/internal/test/issue18146.go
src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
src/cmd/go/internal/lockedfile/lockedfile_test.go
src/crypto/internal/fips140test/check_test.go
src/crypto/internal/sysrand/rand_linux_test.go
src/crypto/internal/sysrand/rand_test.go
src/crypto/rand/rand_test.go
src/flag/flag_test.go
src/internal/cpu/cpu_test.go
src/internal/godebug/godebug_test.go
src/internal/syscall/windows/exec_windows_test.go
src/net/mockserver_test.go
src/net/net_windows_test.go
src/os/pipe_test.go
src/os/signal/signal_test.go
src/runtime/abi_test.go
src/runtime/crash_test.go
src/runtime/crash_unix_test.go
src/runtime/debug/stack_test.go
src/runtime/hash_test.go
src/runtime/malloc_test.go
src/runtime/map_test.go
src/runtime/syscall_windows_test.go
src/sync/mutex_test.go
src/syscall/exec_unix_test.go
src/syscall/exec_windows_test.go
src/syscall/syscall_unix_test.go
src/testing/panic_test.go
src/testing/testing_test.go

index 112b7ee2e7373212c0113e2510933db4dd160724..04e5b5ffb8a033e05039ebdc79b6334e27aff49c 100644 (file)
@@ -11,6 +11,7 @@ package cgotest
 import (
        "bytes"
        "crypto/md5"
+       "internal/testenv"
        "os"
        "os/exec"
        "runtime"
@@ -73,7 +74,7 @@ func test18146(t *testing.T) {
                }
                runtime.GOMAXPROCS(threads)
                argv := append(os.Args, "-test.run=^$")
-               if err := syscall.Exec(os.Args[0], argv, os.Environ()); err != nil {
+               if err := syscall.Exec(testenv.Executable(t), argv, os.Environ()); err != nil {
                        t.Fatal(err)
                }
        }
@@ -87,7 +88,7 @@ func test18146(t *testing.T) {
 
        args := append(append([]string(nil), os.Args[1:]...), "-test.run=^Test18146$")
        for n := attempts; n > 0; n-- {
-               cmd := exec.Command(os.Args[0], args...)
+               cmd := exec.Command(testenv.Executable(t), args...)
                cmd.Env = append(os.Environ(), "test18146=exec")
                buf := bytes.NewBuffer(nil)
                cmd.Stdout = buf
index 035840db7e11ed211bc29e9b292cb2ec24f8be61..c1423e60875ca57476b22a3637a53bef7325a12a 100644 (file)
@@ -198,7 +198,7 @@ func TestLockNotDroppedByExecCommand(t *testing.T) {
        // Some kinds of file locks are dropped when a duplicated or forked file
        // descriptor is unlocked. Double-check that the approach used by os/exec does
        // not accidentally drop locks.
-       cmd := testenv.Command(t, os.Args[0], "-test.run=^$")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^$")
        if err := cmd.Run(); err != nil {
                t.Fatalf("exec failed: %v", err)
        }
index 8cea197abcdfa5ff45f4e509ed7ff031c0b76595..514d0a316c165ca2776977b67dc52aefaf6b9576 100644 (file)
@@ -180,8 +180,6 @@ func TestSpuriousEDEADLK(t *testing.T) {
        //      P.2 unblocks and locks file B.
        //      P.2 unlocks file B.
 
-       testenv.MustHaveExec(t)
-
        dirVar := t.Name() + "DIR"
 
        if dir := os.Getenv(dirVar); dir != "" {
@@ -216,7 +214,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+t.Name()+"$")
        cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", dirVar, dir))
 
        qDone := make(chan struct{})
index c014fff2a6d80d8ccc1a0cc5b9a9e952fbf861d8..f516455fb4636aef3257bd001ad5a587058ce349 100644 (file)
@@ -35,7 +35,7 @@ func TestIntegrityCheck(t *testing.T) {
                t.Skipf("skipping: %v", err)
        }
 
-       cmd := testenv.Command(t, os.Args[0], "-test.v", "-test.run=TestIntegrityCheck")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.v", "-test.run=TestIntegrityCheck")
        cmd.Env = append(cmd.Environ(), "GODEBUG=fips140=on")
        out, err := cmd.CombinedOutput()
        if err != nil {
index ab43904f91296f4609024f55f5636a253c6d039e..ee28ebe1350349cc699b122a18b2f620ab200d2b 100644 (file)
@@ -49,7 +49,7 @@ func TestNoGetrandom(t *testing.T) {
                        return
                }
 
-               cmd := testenv.Command(t, os.Args[0], "-test.v")
+               cmd := testenv.Command(t, testenv.Executable(t), "-test.v")
                cmd.Env = append(os.Environ(), "GO_GETRANDOM_DISABLED=1")
                out, err := cmd.CombinedOutput()
                if err != nil {
index 2b9620c2fbaac4c2c92e3b3ed2dbe1f6f525170c..55b11a929bd4d33061520a84a8773650bf36e4bb 100644 (file)
@@ -105,7 +105,7 @@ func TestReadError(t *testing.T) {
                return
        }
 
-       cmd := testenv.Command(t, os.Args[0], "-test.run=TestReadError")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestReadError")
        cmd.Env = append(os.Environ(), "GO_TEST_READ_ERROR=1")
        out, err := cmd.CombinedOutput()
        if err == nil {
index 2590dc3e3748ad70e6193217b33f90f490046836..9047ac193bd009c6e2a41e67606b8219362643d4 100644 (file)
@@ -168,7 +168,6 @@ func TestReadError(t *testing.T) {
        if testing.Short() {
                t.Skip("skipping test in short mode")
        }
-       testenv.MustHaveExec(t)
 
        // We run this test in a subprocess because it's expected to crash.
        if os.Getenv("GO_TEST_READ_ERROR") == "1" {
@@ -181,7 +180,7 @@ func TestReadError(t *testing.T) {
                return
        }
 
-       cmd := testenv.Command(t, os.Args[0], "-test.run=TestReadError")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestReadError")
        cmd.Env = append(os.Environ(), "GO_TEST_READ_ERROR=1")
        out, err := cmd.CombinedOutput()
        if err == nil {
index 14a5038917f21b24e320d4eff91c64342d89df2c..278ae7e4e02aac1abf279e6764af7a20390051af 100644 (file)
@@ -701,7 +701,7 @@ func TestExitCode(t *testing.T) {
        }
 
        for _, test := range tests {
-               cmd := exec.Command(os.Args[0], "-test.run=^TestExitCode$")
+               cmd := exec.Command(testenv.Executable(t), "-test.run=^TestExitCode$")
                cmd.Env = append(
                        os.Environ(),
                        "GO_CHILD_FLAG="+test.flag,
index a6fe7f77f34585f344ae4879ecdda51467f35dbb..3bff9bed4ea4c2f995b85cefcc72864898ba56b8 100644 (file)
@@ -8,7 +8,6 @@ import (
        . "internal/cpu"
        "internal/godebug"
        "internal/testenv"
-       "os"
        "os/exec"
        "testing"
 )
@@ -26,11 +25,9 @@ func MustSupportFeatureDetection(t *testing.T) {
 func runDebugOptionsTest(t *testing.T, test string, options string) {
        MustHaveDebugOptionsSupport(t)
 
-       testenv.MustHaveExec(t)
-
        env := "GODEBUG=" + options
 
-       cmd := exec.Command(os.Args[0], "-test.run=^"+test+"$")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^"+test+"$")
        cmd.Env = append(cmd.Env, env)
 
        output, err := cmd.CombinedOutput()
index fe1e67225c9928bd66f0aa2b467ca8ef77cb5679..fbabc657fe847eaa6f7addf45365fc6efe81bbb8 100644 (file)
@@ -78,7 +78,7 @@ func TestPanicNilRace(t *testing.T) {
                t.Skip("Skipping test intended for use with -race.")
        }
        if os.Getenv("GODEBUG") != "panicnil=1" {
-               cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0], "-test.run=^TestPanicNilRace$", "-test.v", "-test.parallel=2", "-test.count=1"))
+               cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t), "-test.run=^TestPanicNilRace$", "-test.v", "-test.parallel=2", "-test.count=1"))
                cmd.Env = append(cmd.Env, "GODEBUG=panicnil=1")
                out, err := cmd.CombinedOutput()
                t.Logf("output:\n%s", out)
index 72550b5a84eac8eb49842be70702ba0c9f8ca458..fc694199f744722e11f670489de3a6f0981454cf 100644 (file)
@@ -9,6 +9,7 @@ package windows_test
 import (
        "fmt"
        "internal/syscall/windows"
+       "internal/testenv"
        "os"
        "os/exec"
        "syscall"
@@ -29,7 +30,7 @@ func TestRunAtLowIntegrity(t *testing.T) {
                return
        }
 
-       cmd := exec.Command(os.Args[0], "-test.run=^TestRunAtLowIntegrity$", "--")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestRunAtLowIntegrity$", "--")
        cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
 
        token, err := getIntegrityLevelToken(sidWilLow)
index 4d5e79a592652960be481121b4651e0144d3ff9c..63802c575e2a72889ceb367eb95fbf0d3bea3d65 100644 (file)
@@ -548,7 +548,7 @@ func startTestSocketPeer(t testing.TB, conn Conn, op string, chunkSize, totalSiz
                return nil, err
        }
 
-       cmd := testenv.Command(t, os.Args[0])
+       cmd := testenv.Command(t, testenv.Executable(t))
        cmd.Env = []string{
                "GO_NET_TEST_TRANSFER=1",
                "GO_NET_TEST_TRANSFER_OP=" + op,
index 480e89dfd74945b5246d2a092af0c361e722ead4..bc3171b4ea60c16ad56b414b8be8f7bca09df0d5 100644 (file)
@@ -100,7 +100,7 @@ func TestAcceptIgnoreSomeErrors(t *testing.T) {
        defer ln.Close()
 
        // Start child process that connects to our listener.
-       cmd := exec.Command(os.Args[0], "-test.run=TestAcceptIgnoreSomeErrors")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=TestAcceptIgnoreSomeErrors")
        cmd.Env = append(os.Environ(), "GOTEST_DIAL_ADDR="+ln.Addr().String())
        stdout, err := cmd.StdoutPipe()
        if err != nil {
index a9e0c8bc8a9d2c71693681d1858f5facb56e5d6b..ccae6f61bf4c93893832d28637f5d588a6a2a62d 100644 (file)
@@ -118,7 +118,7 @@ func TestStdPipe(t *testing.T) {
        // all writes should fail with EPIPE and then exit 0.
        for _, sig := range []bool{false, true} {
                for dest := 1; dest < 4; dest++ {
-                       cmd := testenv.Command(t, os.Args[0], "-test.run", "TestStdPipe")
+                       cmd := testenv.Command(t, testenv.Executable(t), "-test.run", "TestStdPipe")
                        cmd.Stdout = w
                        cmd.Stderr = w
                        cmd.ExtraFiles = []*os.File{w}
@@ -145,7 +145,7 @@ func TestStdPipe(t *testing.T) {
        }
 
        // Test redirecting stdout but not stderr.  Issue 40076.
-       cmd := testenv.Command(t, os.Args[0], "-test.run", "TestStdPipe")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run", "TestStdPipe")
        cmd.Stdout = w
        var stderr bytes.Buffer
        cmd.Stderr = &stderr
@@ -263,7 +263,7 @@ func TestReadNonblockingFd(t *testing.T) {
        }
        defer r.Close()
        defer w.Close()
-       cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+t.Name()+"$")
        cmd.Env = append(cmd.Environ(), "GO_WANT_READ_NONBLOCKING_FD=1")
        cmd.Stdin = r
        output, err := cmd.CombinedOutput()
index d54787bc199a3b362202330d6947973ef0dbe9c4..0aa0439b90c390376ddd77b9fd5e02df448f16cb 100644 (file)
@@ -304,7 +304,7 @@ func TestDetectNohup(t *testing.T) {
                // We have no intention of reading from c.
                c := make(chan os.Signal, 1)
                Notify(c, syscall.SIGHUP)
-               if out, err := testenv.Command(t, os.Args[0], "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput(); err == nil {
+               if out, err := testenv.Command(t, testenv.Executable(t), "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput(); err == nil {
                        t.Errorf("ran test with -check_sighup_ignored and it succeeded: expected failure.\nOutput:\n%s", out)
                }
                Stop(c)
@@ -316,7 +316,7 @@ func TestDetectNohup(t *testing.T) {
                }
                Ignore(syscall.SIGHUP)
                os.Remove("nohup.out")
-               out, err := testenv.Command(t, "/usr/bin/nohup", os.Args[0], "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput()
+               out, err := testenv.Command(t, "/usr/bin/nohup", testenv.Executable(t), "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput()
 
                data, _ := os.ReadFile("nohup.out")
                os.Remove("nohup.out")
@@ -454,7 +454,7 @@ func TestNohup(t *testing.T) {
                                if subTimeout != 0 {
                                        args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
                                }
-                               out, err := testenv.Command(t, os.Args[0], args...).CombinedOutput()
+                               out, err := testenv.Command(t, testenv.Executable(t), args...).CombinedOutput()
 
                                if err == nil {
                                        t.Errorf("ran test with -send_uncaught_sighup=%d and it succeeded: expected failure.\nOutput:\n%s", i, out)
@@ -562,7 +562,7 @@ func TestAtomicStop(t *testing.T) {
                if deadline, ok := t.Deadline(); ok {
                        timeout = time.Until(deadline).String()
                }
-               cmd := testenv.Command(t, os.Args[0], "-test.run=^TestAtomicStop$", "-test.timeout="+timeout)
+               cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestAtomicStop$", "-test.timeout="+timeout)
                cmd.Env = append(os.Environ(), "GO_TEST_ATOMIC_STOP=1")
                out, err := cmd.CombinedOutput()
                if err == nil {
@@ -765,7 +765,7 @@ func TestNotifyContextNotifications(t *testing.T) {
                        if subTimeout != 0 {
                                args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
                        }
-                       out, err := testenv.Command(t, os.Args[0], args...).CombinedOutput()
+                       out, err := testenv.Command(t, testenv.Executable(t), args...).CombinedOutput()
                        if err != nil {
                                t.Errorf("ran test with -check_notify_ctx_notification and it failed with %v.\nOutput:\n%s", err, out)
                        }
index d2e79c6dc4072b41fad5bf7f9534181fb9643f3b..af187fc7a8df30cc80501e0424d347065cb4f96d 100644 (file)
@@ -44,12 +44,10 @@ type TintPointer struct {
 func (*TintPointer) m() {}
 
 func TestFinalizerRegisterABI(t *testing.T) {
-       testenv.MustHaveExec(t)
-
        // Actually run the test in a subprocess because we don't want
        // finalizers from other tests interfering.
        if os.Getenv("TEST_FINALIZER_REGABI") != "1" {
-               cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestFinalizerRegisterABI$", "-test.v"))
+               cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=^TestFinalizerRegisterABI$", "-test.v"))
                cmd.Env = append(cmd.Env, "TEST_FINALIZER_REGABI=1")
                out, err := cmd.CombinedOutput()
                if !strings.Contains(string(out), "PASS\n") || err != nil {
index fcf5ef85ce7dbd13e3992822993907e59cafc17b..00e84a38797a7c5eea9b9b08a914180476b8541c 100644 (file)
@@ -889,8 +889,7 @@ func init() {
 }
 
 func TestRuntimePanic(t *testing.T) {
-       testenv.MustHaveExec(t)
-       cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestRuntimePanic$"))
+       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=^TestRuntimePanic$"))
        cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_PANIC=1")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
@@ -902,8 +901,7 @@ func TestRuntimePanic(t *testing.T) {
 }
 
 func TestTracebackRuntimeFunction(t *testing.T) {
-       testenv.MustHaveExec(t)
-       cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestTracebackRuntimeFunction"))
+       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=TestTracebackRuntimeFunction"))
        cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_READMEMSTATS=1")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
@@ -915,8 +913,7 @@ func TestTracebackRuntimeFunction(t *testing.T) {
 }
 
 func TestTracebackRuntimeMethod(t *testing.T) {
-       testenv.MustHaveExec(t)
-       cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestTracebackRuntimeMethod"))
+       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=TestTracebackRuntimeMethod"))
        cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_FUNCMETHOD=1")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
@@ -929,14 +926,12 @@ func TestTracebackRuntimeMethod(t *testing.T) {
 
 // Test that g0 stack overflows are handled gracefully.
 func TestG0StackOverflow(t *testing.T) {
-       testenv.MustHaveExec(t)
-
        if runtime.GOOS == "ios" {
                testenv.SkipFlaky(t, 62671)
        }
 
        if os.Getenv("TEST_G0_STACK_OVERFLOW") != "1" {
-               cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0], "-test.run=^TestG0StackOverflow$", "-test.v"))
+               cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t), "-test.run=^TestG0StackOverflow$", "-test.v"))
                cmd.Env = append(cmd.Env, "TEST_G0_STACK_OVERFLOW=1")
                out, err := cmd.CombinedOutput()
                t.Logf("output:\n%s", out)
@@ -977,7 +972,7 @@ func init() {
 func TestCrashWhileTracing(t *testing.T) {
        testenv.MustHaveExec(t)
 
-       cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0]))
+       cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t)))
        cmd.Env = append(cmd.Env, "TEST_CRASH_WHILE_TRACING=1")
        stdOut, err := cmd.StdoutPipe()
        var errOut bytes.Buffer
index 123a462423db4ad59b168bb9ebc01349c4c2687f..101107d2f7acc31e563c20663eb4bc2b99e53c9d 100644 (file)
@@ -163,7 +163,7 @@ func TestPanicSystemstack(t *testing.T) {
        }
 
        t.Parallel()
-       cmd := exec.Command(os.Args[0], "testPanicSystemstackInternal")
+       cmd := exec.Command(testenv.Executable(t), "testPanicSystemstackInternal")
        cmd = testenv.CleanCmdEnv(cmd)
        cmd.Dir = t.TempDir() // put any core file in tempdir
        cmd.Env = append(cmd.Env, "GOTRACEBACK=crash")
index e1559303f05fe08f7219ed39c482169d22f9f391..88d4ad0c0fe7574b216ddab38d6f3d352a84299d 100644 (file)
@@ -87,12 +87,7 @@ func TestStack(t *testing.T) {
                // initial (not current) environment. Spawn a subprocess to determine the
                // real baked-in GOROOT.
                t.Logf("found GOROOT %q from environment; checking embedded GOROOT value", envGoroot)
-               testenv.MustHaveExec(t)
-               exe, err := os.Executable()
-               if err != nil {
-                       t.Fatal(err)
-               }
-               cmd := exec.Command(exe)
+               cmd := exec.Command(testenv.Executable(t))
                cmd.Env = append(os.Environ(), "GOROOT=", "GO_RUNTIME_DEBUG_TEST_ENTRYPOINT=dumpgoroot")
                out, err := cmd.Output()
                if err != nil {
@@ -137,18 +132,12 @@ func TestStack(t *testing.T) {
 }
 
 func TestSetCrashOutput(t *testing.T) {
-       testenv.MustHaveExec(t)
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
        crashOutput := filepath.Join(t.TempDir(), "crash.out")
 
-       cmd := exec.Command(exe)
+       cmd := exec.Command(testenv.Executable(t))
        cmd.Stderr = new(strings.Builder)
        cmd.Env = append(os.Environ(), "GO_RUNTIME_DEBUG_TEST_ENTRYPOINT=setcrashoutput", "CRASHOUTPUT="+crashOutput)
-       err = cmd.Run()
+       err := cmd.Run()
        stderr := fmt.Sprint(cmd.Stderr)
        if err == nil {
                t.Fatalf("child process succeeded unexpectedly (stderr: %s)", stderr)
index 24c04b260e3841fbf192cec410a6b80c4fcc4b22..3ef9f9addb3eb48c1798e56f8dc40dc5fd284085 100644 (file)
@@ -638,11 +638,10 @@ func TestSmhasherSeed(t *testing.T) {
 }
 
 func TestIssue66841(t *testing.T) {
-       testenv.MustHaveExec(t)
        if *UseAeshash && os.Getenv("TEST_ISSUE_66841") == "" {
                // We want to test the backup hash, so if we're running on a machine
                // that uses aeshash, exec ourselves while turning aes off.
-               cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0], "-test.run=^TestIssue66841$"))
+               cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t), "-test.run=^TestIssue66841$"))
                cmd.Env = append(cmd.Env, "GODEBUG=cpu.aes=off", "TEST_ISSUE_66841=1")
                out, err := cmd.CombinedOutput()
                if err != nil {
index 67bceef2e30db89e8d02ac9c63db6548c4f26651..6cd525d5e945b12787fd58802ab7d8497dd7d9b6 100644 (file)
@@ -270,12 +270,10 @@ type acLink struct {
 var arenaCollisionSink []*acLink
 
 func TestArenaCollision(t *testing.T) {
-       testenv.MustHaveExec(t)
-
        // Test that mheap.sysAlloc handles collisions with other
        // memory mappings.
        if os.Getenv("TEST_ARENA_COLLISION") != "1" {
-               cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestArenaCollision$", "-test.v"))
+               cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=^TestArenaCollision$", "-test.v"))
                cmd.Env = append(cmd.Env, "TEST_ARENA_COLLISION=1")
                out, err := cmd.CombinedOutput()
                if race.Enabled {
index c522c44a4ef4767139784b212f3792aae85e451f..b1ff02d851e916b72d35593549c7c80d505806ac 100644 (file)
@@ -1106,7 +1106,7 @@ func computeHash() uintptr {
 func subprocessHash(t *testing.T, env string) uintptr {
        t.Helper()
 
-       cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0], "-test.run=^TestMemHashGlobalSeed$"))
+       cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t), "-test.run=^TestMemHashGlobalSeed$"))
        cmd.Env = append(cmd.Env, "GO_TEST_SUBPROCESS_HASH=1")
        if env != "" {
                cmd.Env = append(cmd.Env, env)
index 01a9ca3b8cfba8a20f0039500c66b63142b4bb8c..7a7269d125e396c0e8351a64d7c954595ec253fe 100644 (file)
@@ -1043,7 +1043,7 @@ func TestNumCPU(t *testing.T) {
        _GetProcessAffinityMask := kernel32.MustFindProc("GetProcessAffinityMask")
        _SetProcessAffinityMask := kernel32.MustFindProc("SetProcessAffinityMask")
 
-       cmd := exec.Command(os.Args[0], "-test.run=TestNumCPU")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=TestNumCPU")
        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
        var buf strings.Builder
        cmd.Stdout = &buf
index cca0986a30975ebd9c51cf37d97037b43b666dae..c9e5ec22c2b22e3e068716aa04790025ddd809be 100644 (file)
@@ -187,9 +187,8 @@ func init() {
 }
 
 func TestMutexMisuse(t *testing.T) {
-       testenv.MustHaveExec(t)
        for _, test := range misuseTests {
-               out, err := exec.Command(os.Args[0], "TESTMISUSE", test.name).CombinedOutput()
+               out, err := exec.Command(testenv.Executable(t), "TESTMISUSE", test.name).CombinedOutput()
                if err == nil || !strings.Contains(string(out), "unlocked") {
                        t.Errorf("%s: did not find failure with message about unlocked lock: %s\n%s\n", test.name, err, out)
                }
index fda9019e3940b2e26863ef9719fe5851d7e2ac51..3a95356c1e5ecee9e005bae0467d89c4d76e6f1e 100644 (file)
@@ -302,8 +302,7 @@ func TestInvalidExec(t *testing.T) {
 
 // TestExec is for issue #41702.
 func TestExec(t *testing.T) {
-       testenv.MustHaveExec(t)
-       cmd := exec.Command(os.Args[0], "-test.run=^TestExecHelper$")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestExecHelper$")
        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=2")
        o, err := cmd.CombinedOutput()
        if err != nil {
index 5cacf42b6b92d016ab79d3e4850ba0a14fc9ec38..90a13af8d1bdbbef2c75d7f1bbf9c563ebd096ff 100644 (file)
@@ -6,6 +6,7 @@ package syscall_test
 
 import (
        "fmt"
+       "internal/testenv"
        "os"
        "os/exec"
        "path/filepath"
@@ -73,7 +74,7 @@ func TestChangingProcessParent(t *testing.T) {
 
        // run parent process
 
-       parent := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$")
+       parent := exec.Command(testenv.Executable(t), "-test.run=^TestChangingProcessParent$")
        parent.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=parent")
        err := parent.Start()
        if err != nil {
@@ -96,7 +97,7 @@ func TestChangingProcessParent(t *testing.T) {
        }
        defer syscall.CloseHandle(ph)
 
-       child := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$")
+       child := exec.Command(testenv.Executable(t), "-test.run=^TestChangingProcessParent$")
        child.Env = append(os.Environ(),
                "GO_WANT_HELPER_PROCESS=child",
                "GO_WANT_HELPER_PROCESS_FILE="+childDumpPath)
index 56e771e08603d08c6cb852b1d01d3e20e253afd7..8c6de43231e032cc27203e7602eb07d24a72ee36 100644 (file)
@@ -99,7 +99,7 @@ func TestFcntlFlock(t *testing.T) {
                        t.Fatalf("FcntlFlock(F_SETLK) failed: %v", err)
                }
 
-               cmd := exec.Command(os.Args[0], "-test.run=^TestFcntlFlock$")
+               cmd := exec.Command(testenv.Executable(t), "-test.run=^TestFcntlFlock$")
                cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
                cmd.ExtraFiles = []*os.File{f}
                out, err := cmd.CombinedOutput()
@@ -171,7 +171,7 @@ func TestPassFD(t *testing.T) {
        defer writeFile.Close()
        defer readFile.Close()
 
-       cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", tempDir)
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestPassFD$", "--", tempDir)
        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
        cmd.ExtraFiles = []*os.File{writeFile}
 
index 6307b84a7a534b5c1d2a8f4d74626d7fcaf6efe0..1c42f9f8dd8b87bbfc8b92e8c9998a48e0ef2193 100644 (file)
@@ -139,7 +139,7 @@ ran outer cleanup
        }}
        for _, tc := range testCases {
                t.Run(tc.desc, func(t *testing.T) {
-                       cmd := exec.Command(os.Args[0], "-test.run=^TestPanicHelper$")
+                       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestPanicHelper$")
                        cmd.Args = append(cmd.Args, tc.flags...)
                        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
                        b, _ := cmd.CombinedOutput()
@@ -232,7 +232,7 @@ func TestMorePanic(t *testing.T) {
        }
 
        for _, tc := range testCases {
-               cmd := exec.Command(os.Args[0], tc.flags...)
+               cmd := exec.Command(testenv.Executable(t), tc.flags...)
                cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
                b, _ := cmd.CombinedOutput()
                got := string(b)
index addf6cad91d66707e60b096caa3d58ff097419de..907d0701f033d4b1a173aeabfef34cb87f1da06c 100644 (file)
@@ -801,7 +801,7 @@ func TestRunningTests(t *testing.T) {
 
        timeout := 10 * time.Millisecond
        for {
-               cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$", "-test.timeout="+timeout.String(), "-test.parallel=4")
+               cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+t.Name()+"$", "-test.timeout="+timeout.String(), "-test.parallel=4")
                cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
                out, err := cmd.CombinedOutput()
                t.Logf("%v:\n%s", cmd, out)
@@ -860,7 +860,7 @@ func TestRunningTestsInCleanup(t *testing.T) {
 
        timeout := 10 * time.Millisecond
        for {
-               cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$", "-test.timeout="+timeout.String())
+               cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+t.Name()+"$", "-test.timeout="+timeout.String())
                cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
                out, err := cmd.CombinedOutput()
                t.Logf("%v:\n%s", cmd, out)