diff options
-rw-r--r-- | lib/common/Test.h | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/common/Test.h b/lib/common/Test.h index 3c7b00fd..ada42eb2 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -104,30 +104,19 @@ inline int RunCommand(const char *pCommandLine) return ::system(command.c_str()); } -inline int LaunchServer(const char *pCommandLine, const char *pidFile) +inline int ReadPidFile(const char *pidFile) { - if(RunCommand(pCommandLine) != 0) - { - printf("Server: %s\n", pCommandLine); - TEST_FAIL_WITH_MESSAGE("Couldn't start server"); - return -1; - } - // time for it to start up - ::sleep(1); - - // read pid file if(!TestFileExists(pidFile)) { - printf("Server: %s\n", pCommandLine); TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); return -1; } - FILE *f = fopen(pidFile, "r"); int pid = -1; + + FILE *f = fopen(pidFile, "r"); if(f == NULL || fscanf(f, "%d", &pid) != 1) { - printf("Server: %s (pidfile %s)\n", pCommandLine, pidFile); TEST_FAIL_WITH_MESSAGE("Couldn't read PID file"); return -1; } @@ -136,6 +125,30 @@ inline int LaunchServer(const char *pCommandLine, const char *pidFile) return pid; } +inline int LaunchServer(const char *pCommandLine, const char *pidFile) +{ + if(RunCommand(pCommandLine) != 0) + { + printf("Server: %s\n", pCommandLine); + TEST_FAIL_WITH_MESSAGE("Couldn't start server"); + return -1; + } + + // give it time to start up + ::sleep(1); + + // read pid file + int pid = ReadPidFile(pidFile); + + if(pid == -1) + { + // helps with debugging: + printf("Server: %s (pidfile %s)\n", pCommandLine, pidFile); + } + + return pid; +} + #ifdef WIN32 #include "WinNamedPipeStream.h" @@ -335,4 +348,3 @@ inline void TestRemoteProcessMemLeaks(const char *filename) } #endif // TEST__H - |