From 6f2b0fbf94b23fb98c050dd96d8b7f2084995e57 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Tue, 21 Mar 2006 13:43:06 +0000 Subject: [PATCH] kernel: Add a test for QueueUserWorkItem. --- dlls/kernel/tests/thread.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dlls/kernel/tests/thread.c b/dlls/kernel/tests/thread.c index 444217da5d2..97884475abe 100644 --- a/dlls/kernel/tests/thread.c +++ b/dlls/kernel/tests/thread.c @@ -677,6 +677,42 @@ static void test_SetThreadContext(void) #endif /* __i386__ */ +static HANDLE finish_event; +static LONG times_executed; + +static DWORD CALLBACK work_function(void *p) +{ + LONG executed = InterlockedIncrement(×_executed); + + if (executed == 100) + SetEvent(finish_event); + return 0; +} + +static void test_QueueUserWorkItem(void) +{ + int i; + DWORD wait_result; + DWORD before, after; + + finish_event = CreateEvent(NULL, TRUE, FALSE, NULL); + + before = GetTickCount(); + + for (i = 0; i < 100; i++) + { + BOOL ret = QueueUserWorkItem(work_function, (void *)i, WT_EXECUTEDEFAULT); + ok(ret, "QueueUserWorkItem failed with error %ld\n", GetLastError()); + } + + wait_result = WaitForSingleObject(finish_event, 10000); + + after = GetTickCount(); + trace("100 QueueUserWorkItem calls took %ldms\n", after - before); + ok(wait_result == WAIT_OBJECT_0, "wait failed with error 0x%lx\n", wait_result); + + ok(times_executed == 100, "didn't execute all of the work items\n"); +} START_TEST(thread) { @@ -702,4 +738,5 @@ START_TEST(thread) #ifdef __i386__ test_SetThreadContext(); #endif + test_QueueUserWorkItem(); }