]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: use testenv.Executable
authorKir Kolyshkin <kolyshkin@gmail.com>
Fri, 30 Aug 2024 05:24:30 +0000 (22:24 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 3 Sep 2024 20:11:34 +0000 (20:11 +0000)
Change-Id: I4390d4bfb7deb974df6546e30ebbb4b6fff74730
Reviewed-on: https://go-review.googlesource.com/c/go/+/609836
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/syscall/exec_linux_test.go
src/syscall/exec_unix_test.go

index 079220eab16ce7c361fb94e6ddf45d99fd86109f..1c2024af4550bfe7034fc3d5477eb2266ad16b19 100644 (file)
@@ -232,12 +232,7 @@ func TestUnshareMountNameSpace(t *testing.T) {
                os.Exit(0)
        }
 
-       testenv.MustHaveExec(t)
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        d := t.TempDir()
        t.Cleanup(func() {
                // If the subprocess fails to unshare the parent directory, force-unmount it
@@ -351,12 +346,7 @@ func TestUnshareUidGidMapping(t *testing.T) {
                t.Skip("test exercises unprivileged user namespace, fails with privileges")
        }
 
-       testenv.MustHaveExec(t)
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        cmd := testenv.Command(t, exe, "-test.run=^TestUnshareUidGidMapping$")
        cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
        cmd.SysProcAttr = &syscall.SysProcAttr{
@@ -434,8 +424,6 @@ func prepareCgroupFD(t *testing.T) (int, string) {
 }
 
 func TestUseCgroupFD(t *testing.T) {
-       testenv.MustHaveExec(t)
-
        if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                // Read and print own cgroup path.
                selfCg, err := os.ReadFile("/proc/self/cgroup")
@@ -447,11 +435,7 @@ func TestUseCgroupFD(t *testing.T) {
                os.Exit(0)
        }
 
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        fd, suffix := prepareCgroupFD(t)
 
        cmd := testenv.Command(t, exe, "-test.run=^TestUseCgroupFD$")
@@ -478,8 +462,6 @@ func TestUseCgroupFD(t *testing.T) {
 }
 
 func TestCloneTimeNamespace(t *testing.T) {
-       testenv.MustHaveExec(t)
-
        if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                timens, err := os.Readlink("/proc/self/ns/time")
                if err != nil {
@@ -490,11 +472,7 @@ func TestCloneTimeNamespace(t *testing.T) {
                os.Exit(0)
        }
 
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        cmd := testenv.Command(t, exe, "-test.run=^TestCloneTimeNamespace$")
        cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
        cmd.SysProcAttr = &syscall.SysProcAttr{
@@ -524,18 +502,12 @@ func TestCloneTimeNamespace(t *testing.T) {
 }
 
 func testPidFD(t *testing.T, userns bool) error {
-       testenv.MustHaveExec(t)
-
        if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                // Child: wait for a signal.
                time.Sleep(time.Hour)
        }
 
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        var pidfd int
        cmd := testenv.Command(t, exe, "-test.run=^TestPidFD$")
        cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
@@ -568,7 +540,7 @@ func testPidFD(t *testing.T, userns bool) error {
                t.Fatal("pidfd_send_signal syscall failed:", err)
        }
        // Check if the child received our signal.
-       err = cmd.Wait()
+       err := cmd.Wait()
        if cmd.ProcessState == nil || cmd.ProcessState.Sys().(syscall.WaitStatus).Signal() != sig {
                t.Fatal("unexpected child error:", err)
        }
@@ -695,12 +667,7 @@ func testAmbientCaps(t *testing.T, userns bool) {
                os.Remove(f.Name())
        })
 
-       testenv.MustHaveExec(t)
-       exe, err := os.Executable()
-       if err != nil {
-               t.Fatal(err)
-       }
-
+       exe := testenv.Executable(t)
        e, err := os.Open(exe)
        if err != nil {
                t.Fatal(err)
index bb0b3e703714a687e158fa8c3f5f54cc1cdc1ba9..fda9019e3940b2e26863ef9719fe5851d7e2ac51 100644 (file)
@@ -354,12 +354,8 @@ func TestRlimitRestored(t *testing.T) {
                t.Skip("skipping test because rlimit not adjusted at startup")
        }
 
-       executable, err := os.Executable()
-       if err != nil {
-               executable = os.Args[0]
-       }
-
-       cmd := testenv.Command(t, executable, "-test.run=^TestRlimitRestored$")
+       exe := testenv.Executable(t)
+       cmd := testenv.Command(t, exe, "-test.run=^TestRlimitRestored$")
        cmd = testenv.CleanCmdEnv(cmd)
        cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")