Module: tools Branch: master Commit: 856584a4acfb31e14d3ce770114ce0395317405a URL: https://source.winehq.org/git/tools.git/?a=commit;h=856584a4acfb31e14d3ce770...
Author: Francois Gouget fgouget@codeweavers.com Date: Tue Mar 16 12:14:03 2021 +0100
testbot/TestLauncher: Show the tool name in error messages.
Format the error messages so that they are easily recognized as such.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/src/TestLauncher/TestLauncher.c | 58 +++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-)
diff --git a/testbot/src/TestLauncher/TestLauncher.c b/testbot/src/TestLauncher/TestLauncher.c index 7b58c9a..5ff8060 100644 --- a/testbot/src/TestLauncher/TestLauncher.c +++ b/testbot/src/TestLauncher/TestLauncher.c @@ -27,6 +27,28 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+/* + * Error handling + */ + +#ifdef __GNUC__ +# define FORMAT(fmt, arg1) __attribute__((format (printf, fmt, arg1) )) +#else +# define FORMAT(fmt, arg1) +#endif +void Error(const char* Format, ...) FORMAT(1,2); + +static const char *Name0; +void Error(const char* Format, ...) +{ + va_list valist; + fprintf(stderr, "%s:error: ", Name0); + va_start(valist, Format); + vfprintf(stderr, Format, valist); + va_end(valist); +} + + /* * Missing dll and entry point detection. */ @@ -112,12 +134,20 @@ int main(int argc, char *argv[]) const char *Suffix; char TestName[MAX_PATH]; int TestArg; - char *CommandLine; + char *CommandLine, *p; int CommandLen; STARTUPINFOA StartupInfo; PROCESS_INFORMATION ProcessInformation; DWORD ExitCode;
+ Name0 = p = argv[0]; + while (*p != '\0') + { + if (*p == '/' || *p == '\') + Name0 = p + 1; + p++; + } + TimeOut = INFINITE; CommandLine = NULL; Arg = 1; @@ -134,8 +164,8 @@ int main(int argc, char *argv[]) TimeOut = (DWORD) strtoul(argv[Arg + 1], &EndPtr, 10) * 1000; if (*EndPtr != '\0') { - fprintf(stderr, "Invalid TimeOut value %s\n", argv[Arg + 1]); - exit(1); + Error("Invalid TimeOut value %s\n", argv[Arg + 1]); + return 1; } } else @@ -146,9 +176,9 @@ int main(int argc, char *argv[]) { if (GetFullPathNameA(argv[Arg], ARRAY_SIZE(TestExeFullName), TestExeFullName, &TestExeFileName) == 0) { - fprintf(stderr, "Can't determine full path of test executable %s, error %lu\n", + Error("Cauld not get the test executable full path %s (error %lu)\n", argv[Arg], GetLastError()); - exit(1); + return 1; } Suffix = strstr(TestExeFileName, "_test.exe"); if (Suffix == NULL) @@ -171,8 +201,8 @@ int main(int argc, char *argv[]) CommandLine = (char *) malloc(CommandLen); if (CommandLine == NULL) { - fprintf(stderr, "Unable to allocate memory for child command line\n"); - exit(1); + Error("Unable to allocate memory for child command line\n"); + return 1; }
CommandLine[0] = '"'; @@ -193,7 +223,7 @@ int main(int argc, char *argv[]) if (UsageError) { fprintf(stderr, "Usage: %s [-t TimeOut] TestExecutable.exe [TestParameter...]\n", argv[0]); - exit(1); + return 1; }
Start = GetTickCount(); @@ -214,8 +244,8 @@ int main(int argc, char *argv[]) */ if (! CreateProcessA(NULL, CommandLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartupInfo, &ProcessInformation)) { - fprintf(stderr, "CreateProcess failed with error %lu\n", GetLastError()); - exit(1); + Error("CreateProcess failed (error %lu)\n", GetLastError()); + return 1; } CloseHandle(ProcessInformation.hThread);
@@ -249,7 +279,7 @@ int main(int argc, char *argv[]) switch (ExitCode) { case WAIT_FAILED: - fprintf(stderr, "Wait for child failed, error %lu\n", GetLastError()); + Error("Wait for child failed (error %lu)\n", GetLastError()); break;
case WAIT_TIMEOUT: @@ -257,15 +287,15 @@ int main(int argc, char *argv[]) break;
default: - fprintf(stderr, "Unexpected return value %lu from wait for child\n", ExitCode); + Error("Unexpected return value %lu from wait for child\n", ExitCode); break; } if (!TerminateProcess(ProcessInformation.hProcess, 257)) - fprintf(stderr, "TerminateProcess failed, error %lu\n", GetLastError()); + Error("TerminateProcess failed (error %lu)\n", GetLastError()); } else if (!Skips && !GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode)) { - fprintf(stderr, "Can't get child exit code, error %lu\n", GetLastError()); + Error("Could not get the child exit code (error %lu)\n", GetLastError()); ExitCode = 259; } CloseHandle(ProcessInformation.hProcess);