Francois Gouget : testbot/TestLauncher: Add a RunTest() function.
Alexandre Julliard
julliard at winehq.org
Wed Mar 31 15:25:38 CDT 2021
Module: tools
Branch: master
Commit: 6e92cb8730243ed55a27bf595d36cb631d6c45cc
URL: https://source.winehq.org/git/tools.git/?a=commit;h=6e92cb8730243ed55a27bf595d36cb631d6c45cc
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Wed Mar 31 13:14:47 2021 +0200
testbot/TestLauncher: Add a RunTest() function.
This moves running and waiting for the test executable out of main().
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
testbot/src/TestLauncher/TestLauncher.c | 162 +++++++++++++++++---------------
1 file changed, 85 insertions(+), 77 deletions(-)
diff --git a/testbot/src/TestLauncher/TestLauncher.c b/testbot/src/TestLauncher/TestLauncher.c
index b024714..022f25c 100644
--- a/testbot/src/TestLauncher/TestLauncher.c
+++ b/testbot/src/TestLauncher/TestLauncher.c
@@ -208,6 +208,86 @@ BOOL CALLBACK DetectCriticalErrorDialog(HWND TopWnd, LPARAM lParam)
return TRUE;
}
+DWORD Start;
+
+DWORD RunTest(char *TestExeFileName, char* CommandLine, DWORD TimeOut, DWORD *Pid)
+{
+ STARTUPINFOA StartupInfo;
+ PROCESS_INFORMATION ProcessInformation;
+ DWORD ExitCode, WaitTimeOut;
+
+ StartupInfo.cb = sizeof(STARTUPINFOA);
+ GetStartupInfoA(&StartupInfo);
+ StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
+ StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
+ StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+ StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+
+ /* Unlike WineTest we do not have the luxury of first running the test with
+ * a --list argument. This means we cannot use SetErrorMode() to check
+ * whether there are missing dependencies as it could modify the test
+ * results...
+ */
+ if (! CreateProcessA(NULL, CommandLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartupInfo, &ProcessInformation))
+ {
+ Error("CreateProcess failed (error %lu)\n", GetLastError());
+ ExitProcess(1);
+ }
+ CloseHandle(ProcessInformation.hThread);
+ *Pid = ProcessInformation.dwProcessId;
+
+ WaitTimeOut = 100;
+ ExitCode = WAIT_TIMEOUT;
+ while (ExitCode == WAIT_TIMEOUT)
+ {
+ DWORD Elapsed, Remaining;
+
+ ExitCode = WaitForSingleObject(ProcessInformation.hProcess, WaitTimeOut);
+ Elapsed = GetTickCount() - Start;
+ if (ExitCode != WAIT_TIMEOUT || Elapsed > TimeOut)
+ break;
+
+ /* ...instead detect the critical error dialog that pops up */
+ EnumWindows(DetectCriticalErrorDialog, (LPARAM)TestExeFileName);
+ if (Skips)
+ {
+ ExitCode = WAIT_OBJECT_0;
+ break;
+ }
+
+ Remaining = TimeOut == INFINITE ? TimeOut : TimeOut - Elapsed;
+ WaitTimeOut = (Elapsed > 3000) ? Remaining :
+ (2 * WaitTimeOut < Remaining) ? 2 * WaitTimeOut :
+ Remaining;
+ }
+
+ if (ExitCode != WAIT_OBJECT_0)
+ {
+ switch (ExitCode)
+ {
+ case WAIT_FAILED:
+ Error("Wait for child failed (error %lu)\n", GetLastError());
+ break;
+
+ case WAIT_TIMEOUT:
+ /* The 'exit code' on the done line identifies timeouts */
+ break;
+
+ default:
+ Error("Unexpected return value %lu from wait for child\n", ExitCode);
+ break;
+ }
+ if (!TerminateProcess(ProcessInformation.hProcess, 257))
+ Error("TerminateProcess failed (error %lu)\n", GetLastError());
+ }
+ else if (!Skips && !GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode))
+ {
+ Error("Could not get the child exit code (error %lu)\n", GetLastError());
+ ExitCode = 259;
+ }
+ CloseHandle(ProcessInformation.hProcess);
+ return ExitCode;
+}
/*
* Command line parsing and test running.
@@ -216,7 +296,7 @@ BOOL CALLBACK DetectCriticalErrorDialog(HWND TopWnd, LPARAM lParam)
int main(int argc, char *argv[])
{
int Arg;
- DWORD Start, TimeOut, WaitTimeOut;
+ DWORD TimeOut;
BOOL UsageError;
char TestExeFullName[MAX_PATH];
char *TestExeFileName;
@@ -225,9 +305,7 @@ int main(int argc, char *argv[])
int TestArg;
char *CommandLine, *p;
int CommandLen;
- STARTUPINFOA StartupInfo;
- PROCESS_INFORMATION ProcessInformation;
- DWORD ExitCode;
+ DWORD Pid, ExitCode;
Name0 = p = argv[0];
while (*p != '\0')
@@ -340,82 +418,12 @@ int main(int argc, char *argv[])
printf("%s:%s start -\n", TestName, Subtest);
fflush(stdout);
- StartupInfo.cb = sizeof(STARTUPINFOA);
- GetStartupInfoA(&StartupInfo);
- StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
- StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
- StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
-
- /* Unlike WineTest we do not have the luxury of first running the test with
- * a --list argument. This means we cannot use SetErrorMode() to check
- * whether there are missing dependencies as it could modify the test
- * results...
- */
- if (! CreateProcessA(NULL, CommandLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartupInfo, &ProcessInformation))
- {
- Error("CreateProcess failed (error %lu)\n", GetLastError());
- return 1;
- }
- CloseHandle(ProcessInformation.hThread);
-
- WaitTimeOut = 100;
- ExitCode = WAIT_TIMEOUT;
- while (ExitCode == WAIT_TIMEOUT)
- {
- DWORD Elapsed, Remaining;
-
- ExitCode = WaitForSingleObject(ProcessInformation.hProcess, WaitTimeOut);
- Elapsed = GetTickCount() - Start;
- if (ExitCode != WAIT_TIMEOUT || Elapsed > TimeOut)
- break;
-
- /* ...instead detect the critical error dialog that pops up */
- EnumWindows(DetectCriticalErrorDialog, (LPARAM)TestExeFileName);
- if (Skips)
- {
- ExitCode = WAIT_OBJECT_0;
- break;
- }
-
- Remaining = TimeOut == INFINITE ? TimeOut : TimeOut - Elapsed;
- WaitTimeOut = (Elapsed > 3000) ? Remaining :
- (2 * WaitTimeOut < Remaining) ? 2 * WaitTimeOut :
- Remaining;
- }
-
- if (ExitCode != WAIT_OBJECT_0)
- {
- switch (ExitCode)
- {
- case WAIT_FAILED:
- Error("Wait for child failed (error %lu)\n", GetLastError());
- break;
-
- case WAIT_TIMEOUT:
- /* The 'exit code' on the done line identifies timeouts */
- break;
-
- default:
- Error("Unexpected return value %lu from wait for child\n", ExitCode);
- break;
- }
- if (!TerminateProcess(ProcessInformation.hProcess, 257))
- Error("TerminateProcess failed (error %lu)\n", GetLastError());
- }
- else if (!Skips && !GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode))
- {
- Error("Could not get the child exit code (error %lu)\n", GetLastError());
- ExitCode = 259;
- }
- CloseHandle(ProcessInformation.hProcess);
-
+ ExitCode = RunTest(TestExeFileName, CommandLine, TimeOut, &Pid);
if (Skips)
- printf("%04lx:%s: 0 tests executed (0 marked as todo, 0 failures), %u skipped.\n", ProcessInformation.dwProcessId, Subtest, Skips);
+ printf("%04lx:%s: 0 tests executed (0 marked as todo, 0 failures), %u skipped.\n", Pid, Subtest, Skips);
printf("%s:%s:%04lx done (%ld) in %lds\n", TestName, Subtest,
- ProcessInformation.dwProcessId, ExitCode,
- (GetTickCount() - Start) / 1000);
+ Pid, ExitCode, (GetTickCount() - Start) / 1000);
return 0;
}
More information about the wine-cvs
mailing list