Module: wine Branch: master Commit: 508b793ec915bae900edb42e10d7bf8d659cd32a URL: https://gitlab.winehq.org/wine/wine/-/commit/508b793ec915bae900edb42e10d7bf8...
Author: Francois Gouget fgouget@codeweavers.com Date: Thu Dec 8 03:39:39 2022 +0100
kernel32/tests: Avoid failures when processes start during the process test.
On Windows processes sometimes start during test_services_exe() so that the size returned by the first NtQuerySystemInformation() is no longer sufficient for the second call.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54094
---
dlls/kernel32/tests/process.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c index a15f8dd1fa8..5ac6ed57bbe 100644 --- a/dlls/kernel32/tests/process.c +++ b/dlls/kernel32/tests/process.c @@ -4949,16 +4949,25 @@ static void test_job_list_attribute(HANDLE parent_job) static void test_services_exe(void) { NTSTATUS status; - ULONG size, offset; + ULONG size, offset, try; char *buf; SYSTEM_PROCESS_INFORMATION *spi; ULONG services_pid = 0, services_session_id = ~0;
- status = NtQuerySystemInformation(SystemProcessInformation, NULL, 0, &size); - ok(status == STATUS_INFO_LENGTH_MISMATCH, "got %#lx\n", status); + /* Check that passing a zero size returns a size suitable for the next call, + * taking into account that in rare cases processes may start between the + * two NtQuerySystemInformation() calls. So this may require a few tries. + */ + for (try = 0; try < 3; try++) + { + status = NtQuerySystemInformation(SystemProcessInformation, NULL, 0, &size); + ok(status == STATUS_INFO_LENGTH_MISMATCH, "got %#lx\n", status);
- buf = malloc(size); - status = NtQuerySystemInformation(SystemProcessInformation, buf, size, &size); + buf = malloc(size); + status = NtQuerySystemInformation(SystemProcessInformation, buf, size, &size); + if (status != STATUS_INFO_LENGTH_MISMATCH) break; + free(buf); + } ok(status == STATUS_SUCCESS, "got %#lx\n", status);
spi = (SYSTEM_PROCESS_INFORMATION *)buf;