[PATCH 1/2] kernel32: refine conditional variable test

Marcus Meissner meissner at suse.de
Sat Dec 29 13:04:48 CST 2012


From: Marcus Meissner <marcus at jet.(none)>

Hi,

test some border cases... make sure we test timeout cases
too and their lasterror.

Ciao, Marcus
---
 dlls/kernel32/tests/sync.c |   26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/dlls/kernel32/tests/sync.c b/dlls/kernel32/tests/sync.c
index 10f1682..af57657 100644
--- a/dlls/kernel32/tests/sync.c
+++ b/dlls/kernel32/tests/sync.c
@@ -1249,7 +1249,7 @@ static BOOL condvar_stop = FALSE, condvar_sleeperr = FALSE;
 static LONG bufferlen,totalproduced,totalconsumed;
 static LONG condvar_producer_sleepcnt,condvar_consumer_sleepcnt;
 
-#define BUFFER_SIZE 10
+#define BUFFER_SIZE 5
 
 static DWORD WINAPI condvar_producer(LPVOID x) {
     while (1) {
@@ -1258,8 +1258,10 @@ static DWORD WINAPI condvar_producer(LPVOID x) {
         EnterCriticalSection(&buffercrit);
         while ((bufferlen == BUFFER_SIZE) && !condvar_stop) {
             condvar_producer_sleepcnt++;
-            if (!pSleepConditionVariableCS(&buffernotfull, &buffercrit, 2000))
-                condvar_sleeperr = TRUE;
+            if (!pSleepConditionVariableCS(&buffernotfull, &buffercrit, rand()%100)) {
+                if (GetLastError() != ERROR_TIMEOUT)
+                    condvar_sleeperr = TRUE;
+            }
         }
         if (condvar_stop) {
             LeaveCriticalSection(&buffercrit);
@@ -1280,8 +1282,10 @@ static DWORD WINAPI condvar_consumer(LPVOID x) {
         EnterCriticalSection(&buffercrit);
         while ((bufferlen == 0) && !condvar_stop) {
             condvar_consumer_sleepcnt++;
-            if (!pSleepConditionVariableCS (&buffernotempty, &buffercrit, 2000))
-                condvar_sleeperr = TRUE;
+            if (!pSleepConditionVariableCS (&buffernotempty, &buffercrit, rand()%100)) {
+                if (GetLastError() != ERROR_TIMEOUT)
+                    condvar_sleeperr = TRUE;
+            }
         }
         if (condvar_stop && (bufferlen == 0)) {
             LeaveCriticalSection(&buffercrit);
@@ -1299,9 +1303,9 @@ static DWORD WINAPI condvar_consumer(LPVOID x) {
 
 static void test_condvars(void)
 {
-    HANDLE hp1,hp2,hc1,hc2;
+    HANDLE hp1,hp2,hp3,hc1,hc2,hc3;
     DWORD dummy;
-    DWORD cnt1,cnt2;
+    DWORD cnt1,cnt2,cnt3;
 
     if (!pInitializeConditionVariable) {
         /* function is not yet in XP, only in newer Windows */
@@ -1314,12 +1318,14 @@ static void test_condvars(void)
     pInitializeConditionVariable(&buffernotfull);
     pInitializeConditionVariable(&buffernotempty);
     InitializeCriticalSection(&buffercrit);
-    bufferlen = totalproduced = totalconsumed = cnt1 = cnt2 = 0;
+    bufferlen = totalproduced = totalconsumed = cnt1 = cnt2 = cnt3 = 0;
 
     hp1 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
     hp2 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
+    hp3 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
     hc1 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt1, 0, &dummy);
     hc2 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt2, 0, &dummy);
+    hc3 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt3, 0, &dummy);
 
     /* Limit run to 0.5 seconds. */
     Sleep(500);
@@ -1333,8 +1339,10 @@ static void test_condvars(void)
 
     WaitForSingleObject(hp1, 1000);
     WaitForSingleObject(hp2, 1000);
+    WaitForSingleObject(hp3, 1000);
     WaitForSingleObject(hc1, 1000);
     WaitForSingleObject(hc2, 1000);
+    WaitForSingleObject(hc3, 1000);
 
     ok(totalconsumed == totalproduced,
        "consumed %d != produced %d\n", totalconsumed, totalproduced);
@@ -1342,7 +1350,7 @@ static void test_condvars(void)
 
     /* Checking cnt1 - cnt2 for non-0 would be not good, the case where
      * one consumer does not get anything to do is possible. */
-    trace("produced %d, c1 %d, c2 %d\n", totalproduced, cnt1, cnt2);
+    trace("produced %d, c1 %d, c2 %d, c3 %d\n", totalproduced, cnt1, cnt2, cnt3);
     /* The sleeps of the producer or consumer should not go above 100* produced count,
      * otherwise the implementation does not sleep correctly. But yet again, this is
      * not hard defined. */
-- 
1.7.10.4




More information about the wine-patches mailing list