Skip to content

Commit 2ad666d

Browse files
dmitshurgopherbot
authored andcommitted
syscall, cmd/cgo: skip tests that shouldn't run under 'unshare -n -r'
A small number of tests in the main tree are currently skipped in LUCI because our builders there run tests without root. Unfortunately, these tests begin to run when run under 'unshare -n -r' as implemented in the current iteration of a no-network check. Add targeted builder-only skips so that they don't begin to run and fail with a false positive. Updates #10719. For #30612. Change-Id: I6dd320714a279c395882c1b2ebfbb2fce58f913b Reviewed-on: https://go-review.googlesource.com/c/go/+/513779 Run-TryBot: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent f322d67 commit 2ad666d

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/cmd/cgo/internal/test/issue1435.go

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package cgotest
88

99
import (
1010
"fmt"
11+
"internal/testenv"
1112
"os"
1213
"runtime"
1314
"sort"
@@ -145,6 +146,13 @@ func test1435(t *testing.T) {
145146
if syscall.Getuid() != 0 {
146147
t.Skip("skipping root only test")
147148
}
149+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
150+
// The Go build system's swarming user is known not to be root.
151+
// Unfortunately, it sometimes appears as root due the current
152+
// implementation of a no-network check using 'unshare -n -r'.
153+
// Since this test does need root to work, we need to skip it.
154+
t.Skip("skipping root only test on a non-root builder")
155+
}
148156
if runtime.GOOS == "linux" {
149157
if _, err := os.Stat("/etc/alpine-release"); err == nil {
150158
t.Skip("skipping failing test on alpine - go.dev/issue/19938")

src/syscall/exec_linux_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ func TestUnshareMountNameSpace(t *testing.T) {
249249
if testenv.SyscallIsNotSupported(err) {
250250
t.Skipf("skipping: could not start process with CLONE_NEWNS: %v", err)
251251
}
252+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
253+
// The Go build system's swarming user is known not to support
254+
// starting a process with CLONE_NEWNS.
255+
// Unfortunately, it doesn't get recognized as such due the current
256+
// implementation of a no-network check using 'unshare -n -r'.
257+
// Since this test does need start this process, we need to skip it.
258+
t.Skipf("skipping: could not start process with CLONE_NEWNS: %v", err)
259+
}
252260
t.Fatalf("unshare failed: %v\n%s", err, o)
253261
}
254262

@@ -301,6 +309,14 @@ func TestUnshareMountNameSpaceChroot(t *testing.T) {
301309
if testenv.SyscallIsNotSupported(err) {
302310
t.Skipf("skipping: could not start process with CLONE_NEWNS and Chroot %q: %v", d, err)
303311
}
312+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
313+
// The Go build system's swarming user is known not to support
314+
// starting a process with CLONE_NEWNS and Chroot.
315+
// Unfortunately, it doesn't get recognized as such due the current
316+
// implementation of a no-network check using 'unshare -n -r'.
317+
// Since this test does need start this process, we need to skip it.
318+
t.Skipf("skipping: could not start process with CLONE_NEWNS and Chroot %q: %v", d, err)
319+
}
304320
t.Fatalf("unshare failed: %v\n%s", err, o)
305321
}
306322

src/syscall/exec_pdeathsig_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package syscall_test
99
import (
1010
"bufio"
1111
"fmt"
12+
"internal/testenv"
1213
"io"
1314
"os"
1415
"os/exec"
@@ -23,6 +24,13 @@ func TestDeathSignal(t *testing.T) {
2324
if os.Getuid() != 0 {
2425
t.Skip("skipping root only test")
2526
}
27+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
28+
// The Go build system's swarming user is known not to be root.
29+
// Unfortunately, it sometimes appears as root due the current
30+
// implementation of a no-network check using 'unshare -n -r'.
31+
// Since this test does need root to work, we need to skip it.
32+
t.Skip("skipping root only test on a non-root builder")
33+
}
2634

2735
// Copy the test binary to a location that a non-root user can read/execute
2836
// after we drop privileges

src/syscall/syscall_linux_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package syscall_test
66

77
import (
88
"fmt"
9+
"internal/testenv"
910
"io"
1011
"io/fs"
1112
"os"
@@ -198,6 +199,13 @@ func TestSyscallNoError(t *testing.T) {
198199
if os.Getuid() != 0 {
199200
t.Skip("skipping root only test")
200201
}
202+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
203+
// The Go build system's swarming user is known not to be root.
204+
// Unfortunately, it sometimes appears as root due the current
205+
// implementation of a no-network check using 'unshare -n -r'.
206+
// Since this test does need root to work, we need to skip it.
207+
t.Skip("skipping root only test on a non-root builder")
208+
}
201209

202210
if runtime.GOOS == "android" {
203211
t.Skip("skipping on rooted android, see issue 27364")
@@ -516,6 +524,13 @@ func TestSetuidEtc(t *testing.T) {
516524
if syscall.Getuid() != 0 {
517525
t.Skip("skipping root only test")
518526
}
527+
if testing.Short() && testenv.Builder() != "" && os.Getenv("USER") == "swarming" {
528+
// The Go build system's swarming user is known not to be root.
529+
// Unfortunately, it sometimes appears as root due the current
530+
// implementation of a no-network check using 'unshare -n -r'.
531+
// Since this test does need root to work, we need to skip it.
532+
t.Skip("skipping root only test on a non-root builder")
533+
}
519534
if _, err := os.Stat("/etc/alpine-release"); err == nil {
520535
t.Skip("skipping glibc test on alpine - go.dev/issue/19938")
521536
}

0 commit comments

Comments
 (0)