mirror of
https://github.com/golang/go.git
synced 2025-05-31 23:25:39 +00:00
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>
This commit is contained in:
parent
c3f346a485
commit
763781c6ec
@ -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)
|
||||
|
@ -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")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user