]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: implement TestCallbackInAnotherThread
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 25 May 2018 23:08:51 +0000 (09:08 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Sat, 26 May 2018 03:56:12 +0000 (03:56 +0000)
Updates #6751

Change-Id: Ibb176a17e67c67f855bc4f3e5462dddaedaa8a58
Reviewed-on: https://go-review.googlesource.com/114755
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/syscall_windows_test.go

index dfde12a211c939159c73481ee69eb9488762a233..2b057213f237a91641061e1af4fe9749181a824a 100644 (file)
@@ -251,7 +251,39 @@ func TestBlockingCallback(t *testing.T) {
 }
 
 func TestCallbackInAnotherThread(t *testing.T) {
-       // TODO: test a function which calls back in another thread: QueueUserAPC() or CreateThread()
+       t.Skip("Skipping failing test (see golang.org/issue/6751 for details)")
+
+       d := GetDLL(t, "kernel32.dll")
+
+       f := func(p uintptr) uintptr {
+               return p
+       }
+       r, _, err := d.Proc("CreateThread").Call(0, 0, syscall.NewCallback(f), 123, 0, 0)
+       if r == 0 {
+               t.Fatalf("CreateThread failed: %v", err)
+       }
+       h := syscall.Handle(r)
+       defer syscall.CloseHandle(h)
+
+       switch s, err := syscall.WaitForSingleObject(h, 100); s {
+       case syscall.WAIT_OBJECT_0:
+               break
+       case syscall.WAIT_TIMEOUT:
+               t.Fatal("timeout waiting for thread to exit")
+       case syscall.WAIT_FAILED:
+               t.Fatalf("WaitForSingleObject failed: %v", err)
+       default:
+               t.Fatalf("WaitForSingleObject returns unexpected value %v", s)
+       }
+
+       var ec uint32
+       r, _, err = d.Proc("GetExitCodeThread").Call(uintptr(h), uintptr(unsafe.Pointer(&ec)))
+       if r == 0 {
+               t.Fatalf("GetExitCodeThread failed: %v", err)
+       }
+       if ec != 123 {
+               t.Fatalf("expected 123, but got %d", ec)
+       }
 }
 
 type cbDLLFunc int // int determines number of callback parameters