Francois Gouget : kernel32/test: Fix the semaphore handling in test_WaitForJobObject().

Alexandre Julliard julliard at winehq.org
Fri Mar 20 17:08:21 CDT 2020


Module: wine
Branch: master
Commit: dd4fad93e4bad742c3757b22ca921fb6335d505a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=dd4fad93e4bad742c3757b22ca921fb6335d505a

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Mar 20 15:21:48 2020 +0100

kernel32/test: Fix the semaphore handling in test_WaitForJobObject().

Don't include 'sync ' in the semaphore name because it will end up as
a separate argument in the child process, causing it to not find the
semaphore.  Switch the child to OpenSemaphoreA() to reduce the risk of
accidentally create a new semaphore instead of opening the parent's
one.  Use wait_child_process() instead of a raw
WaitForSingleObject(). The timeout is longer but the process is
expected to exit immediately anyway and this allows proper handling of
child failures (such as if there is a bug with the semaphore
handling).

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/tests/process.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 264f737178..e54c43ca94 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -2832,7 +2832,8 @@ static void test_WaitForJobObject(void)
     ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
 
     sprintf(buffer, "sync kernel32-process-%x", GetCurrentProcessId());
-    sem = CreateSemaphoreA(NULL, 0, 1, buffer);
+    sem = CreateSemaphoreA(NULL, 0, 1, buffer + 5);
+    ok(sem != NULL, "CreateSemaphoreA failed le=%u\n", GetLastError());
     create_process(buffer, &pi);
 
     ret = pAssignProcessToJobObject(job, pi.hProcess);
@@ -2842,10 +2843,11 @@ static void test_WaitForJobObject(void)
     dwret = WaitForSingleObject(job, 100);
     ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
 
-    WaitForSingleObject(pi.hProcess, 1000);
+    wait_child_process(pi.hProcess);
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
     CloseHandle(job);
+    CloseHandle(sem);
 }
 
 static HANDLE test_AddSelfToJob(void)
@@ -4057,9 +4059,14 @@ START_TEST(process)
         }
         else if (!strcmp(myARGV[2], "sync") && myARGC >= 4)
         {
-            HANDLE sem = CreateSemaphoreA(NULL, 0, 1, myARGV[3]);
-            ok(sem != 0, "Could not get the %s semaphore: le=%u\n", myARGV[3], GetLastError());
-            if (sem) WaitForSingleObject(sem, 30000);
+            HANDLE sem = OpenSemaphoreA(SYNCHRONIZE, FALSE, myARGV[3]);
+            ok(sem != 0, "OpenSemaphoreA(%s) failed le=%u\n", myARGV[3], GetLastError());
+            if (sem)
+            {
+                DWORD ret = WaitForSingleObject(sem, 30000);
+                ok(ret == WAIT_OBJECT_0, "WaitForSingleObject(%s) returned %u\n", myARGV[3], ret);
+                CloseHandle(sem);
+            }
             return;
         }
         else if (!strcmp(myARGV[2], "exit"))




More information about the wine-cvs mailing list