diff options
Diffstat (limited to 'libgo/go/runtime/proc_test.go')
-rw-r--r-- | libgo/go/runtime/proc_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libgo/go/runtime/proc_test.go b/libgo/go/runtime/proc_test.go index fee03be6e58..a693937aa1e 100644 --- a/libgo/go/runtime/proc_test.go +++ b/libgo/go/runtime/proc_test.go @@ -362,6 +362,17 @@ func TestPreemptionGC(t *testing.T) { atomic.StoreUint32(&stop, 1) } +func TestAsyncPreempt(t *testing.T) { + if !runtime.PreemptMSupported { + t.Skip("asynchronous preemption not supported on this platform") + } + output := runTestProg(t, "testprog", "AsyncPreempt") + want := "OK\n" + if output != want { + t.Fatalf("want %s, got %s\n", want, output) + } +} + func TestGCFairness(t *testing.T) { output := runTestProg(t, "testprog", "GCFairness") want := "OK\n" @@ -988,3 +999,42 @@ func TestPreemptionAfterSyscall(t *testing.T) { func TestGetgThreadSwitch(t *testing.T) { runtime.RunGetgThreadSwitchTest() } + +// TestNetpollBreak tests that netpollBreak can break a netpoll. +// This test is not particularly safe since the call to netpoll +// will pick up any stray files that are ready, but it should work +// OK as long it is not run in parallel. +func TestNetpollBreak(t *testing.T) { + if runtime.GOMAXPROCS(0) == 1 { + t.Skip("skipping: GOMAXPROCS=1") + } + + // Make sure that netpoll is initialized. + runtime.NetpollGenericInit() + + start := time.Now() + c := make(chan bool, 2) + go func() { + c <- true + runtime.Netpoll(10 * time.Second.Nanoseconds()) + c <- true + }() + <-c + // Loop because the break might get eaten by the scheduler. + // Break twice to break both the netpoll we started and the + // scheduler netpoll. +loop: + for { + runtime.Usleep(100) + runtime.NetpollBreak() + runtime.NetpollBreak() + select { + case <-c: + break loop + default: + } + } + if dur := time.Since(start); dur > 5*time.Second { + t.Errorf("netpollBreak did not interrupt netpoll: slept for: %v", dur) + } +} |