Format the error messages so that they are easily recognized as such.
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
---
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 b92d09bf2..dd34a7626 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.
*/
@@ -116,12 +138,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;
@@ -138,8 +168,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
@@ -150,9 +180,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)
@@ -175,8 +205,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] = '"';
@@ -197,7 +227,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();
@@ -218,8 +248,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);
@@ -253,7 +283,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:
@@ -261,15 +291,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);
--
2.20.1