diff options
| author | Shulhan <m.shulhan@gmail.com> | 2025-07-20 12:45:21 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2025-07-20 13:09:31 +0700 |
| commit | 60302d4951164495cfbdd97c755e0f44cab64c60 (patch) | |
| tree | 84a127b41e1f0059e99ec70ae69bb6033c9415d4 | |
| parent | 2363897932cfb279dd8810d2c92438f7ddcfd951 (diff) | |
| download | go-fix-runtime-test-GOMAXPROCS.tar.xz | |
internal/testenv: exclude GOMAXPROCS when building test programfix-runtime-test-GOMAXPROCS
In the environment where GOMAXPROCS set explicitly, for example to 3 in
shell profile, the runtime tests will fail with the following error,
----
ok regexp/syntax 0.428s
--- FAIL: TestCgroupGOMAXPROCS (0.81s)
crash_test.go:186: running /home/ms/src/go/bin/go build -o /tmp/go-build1753772192/testprog.exe
crash_test.go:208: built testprog in 796.664277ms
--- FAIL: TestCgroupGOMAXPROCS/containermaxprocs=0 (0.00s)
cgroup_linux_test.go:60: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (907.06µs): ok
cgroup_linux_test.go:63: output got "3\n" want "4\n"
--- FAIL: TestCgroupGOMAXPROCSNoLimit (0.00s)
cgroup_linux_test.go:82: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (879.194µs): ok
cgroup_linux_test.go:85: output got "3\n" want "4\n"
--- FAIL: TestCgroupGOMAXPROCSHigherThanNumCPU (0.00s)
cgroup_linux_test.go:102: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (852.396µs): ok
cgroup_linux_test.go:105: output got "3\n" want "4\n"
--- FAIL: TestCgroupGOMAXPROCSRound (0.01s)
--- FAIL: TestCgroupGOMAXPROCSRound/50000 (0.00s)
cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (852.099µs): ok
cgroup_linux_test.go:159: output got "3\n" want "2\n"
--- FAIL: TestCgroupGOMAXPROCSRound/100000 (0.00s)
cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (894.001µs): ok
cgroup_linux_test.go:159: output got "3\n" want "2\n"
--- FAIL: TestCgroupGOMAXPROCSRound/150000 (0.00s)
cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (850.897µs): ok
cgroup_linux_test.go:159: output got "3\n" want "2\n"
--- FAIL: TestCgroupGOMAXPROCSSchedAffinity (0.00s)
cgroup_linux_test.go:229: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (867.987µs): ok
cgroup_linux_test.go:232: output got "3\n" want "2\n"
FAIL
FAIL runtime 23.088s
----
This changes exclude the GOMAXPROCS when building program for testing so it
does not affect the tests.
Change-Id: I590d9eca57026539413cf4c93b37f624f179d534
| -rw-r--r-- | src/internal/cgrouptest/cgrouptest_linux.go | 2 | ||||
| -rw-r--r-- | src/internal/runtime/strconv/atoi.go | 1 | ||||
| -rw-r--r-- | src/internal/runtime/strconv/atoi_test.go | 1 | ||||
| -rw-r--r-- | src/internal/testenv/exec.go | 4 | ||||
| -rw-r--r-- | src/runtime/debug.go | 8 | ||||
| -rw-r--r-- | src/unicode/utf8/utf8.go | 4 |
6 files changed, 11 insertions, 9 deletions
diff --git a/src/internal/cgrouptest/cgrouptest_linux.go b/src/internal/cgrouptest/cgrouptest_linux.go index f23c37a705..8437f992f7 100644 --- a/src/internal/cgrouptest/cgrouptest_linux.go +++ b/src/internal/cgrouptest/cgrouptest_linux.go @@ -114,7 +114,7 @@ func findCurrent(t *testing.T) (string, string) { if ver != cgroup.V2 { t.Skipf("cgroup: running on cgroup v%d want v2", ver) } - rel := string(buf[1:n]) // The returned path always starts with /, skip it. + rel := string(buf[1:n]) // The returned path always starts with /, skip it. rel = filepath.Join(".", rel) // Make sure this isn't empty string at root. return mount, rel } diff --git a/src/internal/runtime/strconv/atoi.go b/src/internal/runtime/strconv/atoi.go index 87b3faf6d5..0308757c6f 100644 --- a/src/internal/runtime/strconv/atoi.go +++ b/src/internal/runtime/strconv/atoi.go @@ -73,4 +73,3 @@ func Atoi32(s string) (int32, bool) { } return 0, false } - diff --git a/src/internal/runtime/strconv/atoi_test.go b/src/internal/runtime/strconv/atoi_test.go index 49cd6f160a..71a8030b1d 100644 --- a/src/internal/runtime/strconv/atoi_test.go +++ b/src/internal/runtime/strconv/atoi_test.go @@ -102,4 +102,3 @@ func TestAtoi32(t *testing.T) { } } } - diff --git a/src/internal/testenv/exec.go b/src/internal/testenv/exec.go index 7b251b6022..1ad77fe21a 100644 --- a/src/internal/testenv/exec.go +++ b/src/internal/testenv/exec.go @@ -137,6 +137,10 @@ func CleanCmdEnv(cmd *exec.Cmd) *exec.Cmd { if strings.HasPrefix(env, "GOTRACEBACK=") { continue } + // Exclude for TestCgroupGOMAXPROCSXxx. + if strings.HasPrefix(env, "GOMAXPROCS=") { + continue + } cmd.Env = append(cmd.Env, env) } return cmd diff --git a/src/runtime/debug.go b/src/runtime/debug.go index 206cf39f02..dacadd2721 100644 --- a/src/runtime/debug.go +++ b/src/runtime/debug.go @@ -19,10 +19,10 @@ import ( // GOMAXPROCS defaults to that value. // // Otherwise, the Go runtime selects an appropriate default value from a combination of -// - the number of logical CPUs on the machine, -// - the process’s CPU affinity mask, -// - and, on Linux, the process’s average CPU throughput limit based on cgroup CPU -// quota, if any. +// - the number of logical CPUs on the machine, +// - the process’s CPU affinity mask, +// - and, on Linux, the process’s average CPU throughput limit based on cgroup CPU +// quota, if any. // // If GODEBUG=containermaxprocs=0 is set and GOMAXPROCS is not set by the // environment variable, then GOMAXPROCS instead defaults to the value of diff --git a/src/unicode/utf8/utf8.go b/src/unicode/utf8/utf8.go index 82fa7c0d4d..3be2f15e8a 100644 --- a/src/unicode/utf8/utf8.go +++ b/src/unicode/utf8/utf8.go @@ -263,7 +263,7 @@ func DecodeLastRune(p []byte) (r rune, size int) { // guard against O(n^2) behavior when traversing // backwards through strings with long sequences of // invalid UTF-8. - lim := max(end - UTFMax, 0) + lim := max(end-UTFMax, 0) for start--; start >= lim; start-- { if RuneStart(p[start]) { break @@ -300,7 +300,7 @@ func DecodeLastRuneInString(s string) (r rune, size int) { // guard against O(n^2) behavior when traversing // backwards through strings with long sequences of // invalid UTF-8. - lim := max(end - UTFMax, 0) + lim := max(end-UTFMax, 0) for start--; start >= lim; start-- { if RuneStart(s[start]) { break |
