Module: tools Branch: master Commit: e549044d4e5de6bc7368b6b81f2017a05aa535a3 URL: https://source.winehq.org/git/tools.git/?a=commit;h=e549044d4e5de6bc7368b6b8...
Author: Francois Gouget fgouget@codeweavers.com Date: Mon Mar 15 19:15:33 2021 +0100
testbot/TestLauncher: Simplify waiting for the test process.
There is no point waiting again after terminating the process. Make sure to report the WaitForSingleObject() status if the process exit code is not available.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/src/TestLauncher/TestLauncher.c | 48 +++++++++------------------------ 1 file changed, 13 insertions(+), 35 deletions(-)
diff --git a/testbot/src/TestLauncher/TestLauncher.c b/testbot/src/TestLauncher/TestLauncher.c index 02acde0..bfc9f0f 100644 --- a/testbot/src/TestLauncher/TestLauncher.c +++ b/testbot/src/TestLauncher/TestLauncher.c @@ -3,6 +3,7 @@ * Verifies that the dlls needed for the test are present. * * Copyright 2009 Ge van Geldorp + * Copyright 2012-2021 Francois Gouget * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -295,9 +296,8 @@ int main(int argc, char *argv[]) int CommandLen; STARTUPINFOA StartupInfo; PROCESS_INFORMATION ProcessInformation; - DWORD WaitStatus; DWORD ExitCode; - + TimeOut = INFINITE; CommandLine = NULL; Arg = 1; @@ -401,54 +401,32 @@ int main(int argc, char *argv[]) fprintf(stderr, "CreateProcess failed with error %lu\n", GetLastError()); exit(1); } - CloseHandle(ProcessInformation.hThread); - WaitStatus = WaitForSingleObject(ProcessInformation.hProcess, TimeOut); - if (WaitStatus != WAIT_OBJECT_0) + + ExitCode = WaitForSingleObject(ProcessInformation.hProcess, TimeOut); + if (ExitCode != WAIT_OBJECT_0) { - switch(WaitStatus) + switch (ExitCode) { case WAIT_FAILED: fprintf(stderr, "Wait for child failed, error %lu\n", GetLastError()); break;
case WAIT_TIMEOUT: + /* The 'exit code' on the done line identifies timeouts */ break;
default: - fprintf(stderr, "Unexpected return value %lu from wait for child\n", WaitStatus); - break; - } - - ExitCode = WaitStatus; - if (! TerminateProcess(ProcessInformation.hProcess, 257)) - fprintf(stderr, "TerminateProcess failed with error %lu\n", GetLastError()); - - switch (WaitForSingleObject(ProcessInformation.hProcess, 5000)) - { - case WAIT_OBJECT_0: - break; - - case WAIT_FAILED: - fprintf(stderr, "Wait for terminate failed, error %lu\n", GetLastError()); - break; - - case WAIT_TIMEOUT: - fprintf(stderr, "Can't kill child\n"); - break; - - default: - fprintf(stderr, "Unexpected return value %lu from wait for terminate\n", WaitStatus); + fprintf(stderr, "Unexpected return value %lu from wait for child\n", ExitCode); break; } + if (!TerminateProcess(ProcessInformation.hProcess, 257)) + fprintf(stderr, "TerminateProcess failed, error %lu\n", GetLastError()); } - else + else if (!GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode)) { - if (! GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode)) - { - ExitCode = 259; - fprintf(stderr, "Can't get child exit code, error %lu\n", GetLastError()); - } + fprintf(stderr, "Can't get child exit code, error %lu\n", GetLastError()); + ExitCode = 259; } CloseHandle(ProcessInformation.hProcess);