]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add more tests for LockOSThread()
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 14 Feb 2013 20:02:12 +0000 (00:02 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 14 Feb 2013 20:02:12 +0000 (00:02 +0400)
Just test some additional paths through the scheduler.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7331044

src/pkg/runtime/proc_test.go

index bf97fb148dde187cca41edaf45b153e7a0bed116..927bd7b816a7d36706c3f3176b18560fcff40ca8 100644 (file)
@@ -8,6 +8,7 @@ import (
        "runtime"
        "sync/atomic"
        "testing"
+       "time"
 )
 
 var stop = make(chan bool, 1)
@@ -45,6 +46,36 @@ func TestStopTheWorldDeadlock(t *testing.T) {
        runtime.GOMAXPROCS(maxprocs)
 }
 
+func TestYieldLocked(t *testing.T) {
+       const N = 10
+       c := make(chan bool)
+       go func() {
+               runtime.LockOSThread()
+               for i := 0; i < N; i++ {
+                       runtime.Gosched()
+                       time.Sleep(time.Millisecond)
+               }
+               c <- true
+               // runtime.UnlockOSThread() is deliberately omitted
+       }()
+       <-c
+}
+
+func TestBlockLocked(t *testing.T) {
+       const N = 10
+       c := make(chan bool)
+       go func() {
+               runtime.LockOSThread()
+               for i := 0; i < N; i++ {
+                       c <- true
+               }
+               runtime.UnlockOSThread()
+       }()
+       for i := 0; i < N; i++ {
+               <-c
+       }
+}
+
 func stackGrowthRecursive(i int) {
        var pad [128]uint64
        if i != 0 && pad[0] == 0 {