Commit dd4fad93 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

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: 's avatarFrancois Gouget <fgouget@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent ecf70b83
...@@ -2832,7 +2832,8 @@ static void test_WaitForJobObject(void) ...@@ -2832,7 +2832,8 @@ static void test_WaitForJobObject(void)
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret); ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
sprintf(buffer, "sync kernel32-process-%x", GetCurrentProcessId()); 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); create_process(buffer, &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess); ret = pAssignProcessToJobObject(job, pi.hProcess);
...@@ -2842,10 +2843,11 @@ static void test_WaitForJobObject(void) ...@@ -2842,10 +2843,11 @@ static void test_WaitForJobObject(void)
dwret = WaitForSingleObject(job, 100); dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret); ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
WaitForSingleObject(pi.hProcess, 1000); wait_child_process(pi.hProcess);
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
CloseHandle(job); CloseHandle(job);
CloseHandle(sem);
} }
static HANDLE test_AddSelfToJob(void) static HANDLE test_AddSelfToJob(void)
...@@ -4057,9 +4059,14 @@ START_TEST(process) ...@@ -4057,9 +4059,14 @@ START_TEST(process)
} }
else if (!strcmp(myARGV[2], "sync") && myARGC >= 4) else if (!strcmp(myARGV[2], "sync") && myARGC >= 4)
{ {
HANDLE sem = CreateSemaphoreA(NULL, 0, 1, myARGV[3]); HANDLE sem = OpenSemaphoreA(SYNCHRONIZE, FALSE, myARGV[3]);
ok(sem != 0, "Could not get the %s semaphore: le=%u\n", myARGV[3], GetLastError()); ok(sem != 0, "OpenSemaphoreA(%s) failed le=%u\n", myARGV[3], GetLastError());
if (sem) WaitForSingleObject(sem, 30000); if (sem)
{
DWORD ret = WaitForSingleObject(sem, 30000);
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject(%s) returned %u\n", myARGV[3], ret);
CloseHandle(sem);
}
return; return;
} }
else if (!strcmp(myARGV[2], "exit")) else if (!strcmp(myARGV[2], "exit"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment