From 49dd5577eba8b270386e4b4187ba50a6ddc2725e Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Fri, 23 Oct 2015 04:15:52 +0200 Subject: [PATCH] kernel32/tests: Add test to show that multiple user APCs are processed at once. Signed-off-by: Sebastian Lackner Signed-off-by: Alexandre Julliard --- dlls/kernel32/tests/sync.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/dlls/kernel32/tests/sync.c b/dlls/kernel32/tests/sync.c index e842bf39587..173793c339a 100644 --- a/dlls/kernel32/tests/sync.c +++ b/dlls/kernel32/tests/sync.c @@ -2333,6 +2333,13 @@ static DWORD WINAPI alertable_wait_thread(void *param) todo_wine ok(status == STATUS_WAIT_0, "expected STATUS_WAIT_0, got %08x\n", status); + ReleaseSemaphore(semaphores[0], 1, NULL); + timeout.QuadPart = -10000000; + status = pNtWaitForMultipleObjects(1, &semaphores[1], FALSE, TRUE, &timeout); + ok(status == STATUS_USER_APC, "expected STATUS_USER_APC, got %08x\n", status); + result = WaitForSingleObject(semaphores[0], 0); + ok(result == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", result); + return 0; } @@ -2342,12 +2349,21 @@ static void CALLBACK alertable_wait_apc(ULONG_PTR userdata) ReleaseSemaphore(semaphores[1], 1, NULL); } +static void CALLBACK alertable_wait_apc2(ULONG_PTR userdata) +{ + HANDLE *semaphores = (void *)userdata; + DWORD result; + + result = WaitForSingleObject(semaphores[0], 1000); + ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result); +} + static void test_alertable_wait(void) { HANDLE thread, semaphores[2]; DWORD result; - semaphores[0] = CreateSemaphoreW(NULL, 0, 1, NULL); + semaphores[0] = CreateSemaphoreW(NULL, 0, 2, NULL); ok(semaphores[0] != NULL, "CreateSemaphore failed with %u\n", GetLastError()); semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL); ok(semaphores[1] != NULL, "CreateSemaphore failed with %u\n", GetLastError()); @@ -2366,6 +2382,15 @@ static void test_alertable_wait(void) result = QueueUserAPC(alertable_wait_apc, thread, (ULONG_PTR)semaphores); ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError()); + result = WaitForSingleObject(semaphores[0], 1000); + ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result); + Sleep(100); /* ensure the thread is blocking in NtWaitForMultipleObjects */ + result = QueueUserAPC(alertable_wait_apc2, thread, (ULONG_PTR)semaphores); + ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError()); + result = QueueUserAPC(alertable_wait_apc2, thread, (ULONG_PTR)semaphores); + ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError()); + ReleaseSemaphore(semaphores[0], 2, NULL); + result = WaitForSingleObject(thread, 1000); ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result); CloseHandle(thread);