aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/exec_linux_test.go
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2024-08-29 22:24:30 -0700
committerGopher Robot <gobot@golang.org>2024-09-03 20:11:34 +0000
commit763781c6ec92fceeb530167bc41985b865516f3a (patch)
treef7364313ab75d8c9b2f3a7fd5472080a99d6df32 /src/syscall/exec_linux_test.go
parentc3f346a485f2fa97a7bdee82d587419b3823a1ba (diff)
downloadgo-763781c6ec92fceeb530167bc41985b865516f3a.tar.xz
syscall: use testenv.Executable
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>
Diffstat (limited to 'src/syscall/exec_linux_test.go')
-rw-r--r--src/syscall/exec_linux_test.go47
1 files changed, 7 insertions, 40 deletions
diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go
index 079220eab1..1c2024af45 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -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)