Robert Shearman : kernel: Add a test for QueueUserWorkItem.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Mar 21 13:21:17 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 6f2b0fbf94b23fb98c050dd96d8b7f2084995e57
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=6f2b0fbf94b23fb98c050dd96d8b7f2084995e57

Author: Robert Shearman <rob at codeweavers.com>
Date:   Tue Mar 21 13:43:06 2006 +0000

kernel: Add a test for QueueUserWorkItem.

---

 dlls/kernel/tests/thread.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel/tests/thread.c b/dlls/kernel/tests/thread.c
index 444217d..9788447 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(&times_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();
 }




More information about the wine-cvs mailing list