diff options
Diffstat (limited to 'libgo/go/runtime/proc_test.go')
-rw-r--r-- | libgo/go/runtime/proc_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libgo/go/runtime/proc_test.go b/libgo/go/runtime/proc_test.go index a693937..b9828d9 100644 --- a/libgo/go/runtime/proc_test.go +++ b/libgo/go/runtime/proc_test.go @@ -6,6 +6,8 @@ package runtime_test import ( "fmt" + "internal/race" + "internal/testenv" "math" "net" "runtime" @@ -428,6 +430,11 @@ func TestPingPongHog(t *testing.T) { if testing.Short() { t.Skip("skipping in -short mode") } + if race.Enabled { + // The race detector randomizes the scheduler, + // which causes this test to fail (#38266). + t.Skip("skipping in -race mode") + } defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1)) done := make(chan bool) @@ -930,6 +937,29 @@ func TestLockOSThreadAvoidsStatePropagation(t *testing.T) { } } +func TestLockOSThreadTemplateThreadRace(t *testing.T) { + testenv.MustHaveGoRun(t) + + exe, err := buildTestProg(t, "testprog") + if err != nil { + t.Fatal(err) + } + + iterations := 100 + if testing.Short() { + // Reduce run time to ~100ms, with much lower probability of + // catching issues. + iterations = 5 + } + for i := 0; i < iterations; i++ { + want := "OK\n" + output := runBuiltTestProg(t, exe, "LockOSThreadTemplateThreadRace") + if output != want { + t.Fatalf("run %d: want %q, got %q", i, want, output) + } + } +} + // fakeSyscall emulates a system call. //go:nosplit func fakeSyscall(duration time.Duration) { @@ -1038,3 +1068,22 @@ loop: t.Errorf("netpollBreak did not interrupt netpoll: slept for: %v", dur) } } + +// TestBigGOMAXPROCS tests that setting GOMAXPROCS to a large value +// doesn't cause a crash at startup. See issue 38474. +func TestBigGOMAXPROCS(t *testing.T) { + t.Parallel() + output := runTestProg(t, "testprog", "NonexistentTest", "GOMAXPROCS=1024") + // Ignore error conditions on small machines. + for _, errstr := range []string{ + "failed to create new OS thread", + "cannot allocate memory", + } { + if strings.Contains(output, errstr) { + t.Skipf("failed to create 1024 threads") + } + } + if !strings.Contains(output, "unknown function: NonexistentTest") { + t.Errorf("output:\n%s\nwanted:\nunknown function: NonexistentTest", output) + } +} |