diff options
Diffstat (limited to 'lib/server/ServerControl.cpp')
-rw-r--r-- | lib/server/ServerControl.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index b9650cee..c698319f 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -226,3 +226,41 @@ bool KillServer(int pid, bool WaitForProcess) return !ServerIsAlive(pid); } +int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file) +{ + TEST_THAT_OR(current_pid == 0, return false); + + int new_pid = LaunchServer(cmd_line, pid_file); + + TEST_THAT_OR(new_pid != -1 && new_pid != 0, return false); + + ::sleep(1); + TEST_THAT_OR(ServerIsAlive(new_pid), return 0); + return new_pid; +} + +bool StopDaemon(int current_pid, const std::string& pid_file, + const std::string& memleaks_file, bool wait_for_process) +{ + TEST_THAT_OR(current_pid != 0, return false); + TEST_THAT_OR(ServerIsAlive(current_pid), return false); + TEST_THAT_OR(KillServer(current_pid, wait_for_process), return false); + ::sleep(1); + + TEST_THAT_OR(!ServerIsAlive(current_pid), return false); + + #ifdef WIN32 + int unlink_result = unlink(pid_file.c_str()); + TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file); + if(unlink_result != 0) + { + return false; + } + #else + TestRemoteProcessMemLeaks(memleaks_file.c_str()); + #endif + + return true; +} + + |