Skip to content

Commit dbafdac

Browse files
committed
runtime: implement TestCallbackInAnotherThread
Updates #6751 Change-Id: Ibb176a17e67c67f855bc4f3e5462dddaedaa8a58 Reviewed-on: https://go-review.googlesource.com/114755 Run-TryBot: Alex Brainman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 1ba26a3 commit dbafdac

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/runtime/syscall_windows_test.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,39 @@ func TestBlockingCallback(t *testing.T) {
251251
}
252252

253253
func TestCallbackInAnotherThread(t *testing.T) {
254-
// TODO: test a function which calls back in another thread: QueueUserAPC() or CreateThread()
254+
t.Skip("Skipping failing test (see golang.org/issue/6751 for details)")
255+
256+
d := GetDLL(t, "kernel32.dll")
257+
258+
f := func(p uintptr) uintptr {
259+
return p
260+
}
261+
r, _, err := d.Proc("CreateThread").Call(0, 0, syscall.NewCallback(f), 123, 0, 0)
262+
if r == 0 {
263+
t.Fatalf("CreateThread failed: %v", err)
264+
}
265+
h := syscall.Handle(r)
266+
defer syscall.CloseHandle(h)
267+
268+
switch s, err := syscall.WaitForSingleObject(h, 100); s {
269+
case syscall.WAIT_OBJECT_0:
270+
break
271+
case syscall.WAIT_TIMEOUT:
272+
t.Fatal("timeout waiting for thread to exit")
273+
case syscall.WAIT_FAILED:
274+
t.Fatalf("WaitForSingleObject failed: %v", err)
275+
default:
276+
t.Fatalf("WaitForSingleObject returns unexpected value %v", s)
277+
}
278+
279+
var ec uint32
280+
r, _, err = d.Proc("GetExitCodeThread").Call(uintptr(h), uintptr(unsafe.Pointer(&ec)))
281+
if r == 0 {
282+
t.Fatalf("GetExitCodeThread failed: %v", err)
283+
}
284+
if ec != 123 {
285+
t.Fatalf("expected 123, but got %d", ec)
286+
}
255287
}
256288

257289
type cbDLLFunc int // int determines number of callback parameters

0 commit comments

Comments
 (0)