aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/lp_linux_test.go
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2023-04-04 14:57:14 +0200
committerTobias Klauser <tobias.klauser@gmail.com>2023-04-04 21:20:20 +0000
commit2f2b874b0aab741a8628fd971f4b3aa41e2fdffb (patch)
tree2d91604f3e045b385beaeecabbaa457c185ba4e3 /src/os/exec/lp_linux_test.go
parent6991f63d9e97b2a76f29170450f40b5ac6bb87f3 (diff)
downloadgo-2f2b874b0aab741a8628fd971f4b3aa41e2fdffb.tar.xz
os/exec: skip remount in TestFindExecutableVsNoexec on EROFS
To allow using testenv.SyscallIsNotSupported, rewrite the test to use the exported API only. Given that path is an absolute path, exec.LookPath is equivalent to exec.findExecutable on linux. Fixes #59087 Change-Id: Ia01b84d4e9d5a65a88dd995f9e3c8a81c4ccd19f Reviewed-on: https://go-review.googlesource.com/c/go/+/481620 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Bypass: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/os/exec/lp_linux_test.go')
-rw-r--r--src/os/exec/lp_linux_test.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/os/exec/lp_linux_test.go b/src/os/exec/lp_linux_test.go
index 845573fb14..60cb13e9b7 100644
--- a/src/os/exec/lp_linux_test.go
+++ b/src/os/exec/lp_linux_test.go
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package exec
+package exec_test
import (
"errors"
"internal/syscall/unix"
+ "internal/testenv"
"os"
+ "os/exec"
"path/filepath"
"syscall"
"testing"
@@ -25,10 +27,12 @@ func TestFindExecutableVsNoexec(t *testing.T) {
// Create a tmpfs mount.
err := syscall.Mount("tmpfs", tmp, "tmpfs", 0, "")
- if err != nil {
+ if testenv.SyscallIsNotSupported(err) {
// Usually this means lack of CAP_SYS_ADMIN, but there might be
// other reasons, especially in restricted test environments.
t.Skipf("requires ability to mount tmpfs (%v)", err)
+ } else if err != nil {
+ t.Fatalf("mount %s failed: %v", tmp, err)
}
t.Cleanup(func() {
if err := syscall.Unmount(tmp, 0); err != nil {
@@ -44,13 +48,13 @@ func TestFindExecutableVsNoexec(t *testing.T) {
}
// Check that it works as expected.
- err = findExecutable(path)
+ _, err = exec.LookPath(path)
if err != nil {
t.Fatalf("findExecutable: got %v, want nil", err)
}
for {
- err = Command(path).Run()
+ err = exec.Command(path).Run()
if err == nil {
break
}
@@ -67,16 +71,18 @@ func TestFindExecutableVsNoexec(t *testing.T) {
// Remount with noexec flag.
err = syscall.Mount("", tmp, "", syscall.MS_REMOUNT|syscall.MS_NOEXEC, "")
- if err != nil {
+ if testenv.SyscallIsNotSupported(err) {
+ t.Skipf("requires ability to re-mount tmpfs (%v)", err)
+ } else if err != nil {
t.Fatalf("remount %s with noexec failed: %v", tmp, err)
}
- if err := Command(path).Run(); err == nil {
+ if err := exec.Command(path).Run(); err == nil {
t.Fatal("exec on noexec filesystem: got nil, want error")
}
- err = findExecutable(path)
+ _, err = exec.LookPath(path)
if err == nil {
- t.Fatalf("findExecutable: got nil, want error")
+ t.Fatalf("LookPath: got nil, want error")
}
}