From 5cf9d57447c66eb4b286fea39ebbe0731f0f8084 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 22 Apr 2007 14:05:55 +0000 Subject: Declare global std::string variables that hold extra arguments for executables run in tests, to be implemented in a follow-up patch. ConvertPaths, LaunchServer and RunCommand all take std::string references instead of char*. Move safe_sleep from test/common to lib/server/Test.h so that all tests can use it. (refs #3) --- lib/common/Test.h | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'lib/common/Test.h') diff --git a/lib/common/Test.h b/lib/common/Test.h index e6a05220..e485f2ee 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -25,6 +25,7 @@ extern int failures; extern int first_fail_line; extern std::string first_fail_file; +extern std::string bbackupd_args, bbstored_args, bbackupquery_args; #define TEST_FAIL_WITH_MESSAGE(msg) \ { \ @@ -92,34 +93,33 @@ inline int TestGetFileSize(const char *Filename) return -1; } -inline std::string ConvertPaths(const char *pCommandLine) +inline std::string ConvertPaths(const std::string& rOriginal) { #ifdef WIN32 // convert UNIX paths to native - std::string command; - for (int i = 0; pCommandLine[i] != 0; i++) + std::string converted; + for (int i = 0; i < rOriginal.size(); i++) { - if (pCommandLine[i] == '/') + if (rOriginal[i] == '/') { - command += '\\'; + converted += '\\'; } else { - command += pCommandLine[i]; + converted += rOriginal[i]; } } + return converted; #else // !WIN32 - std::string command = pCommandLine; + return rOriginal; #endif - - return command; } -inline int RunCommand(const char *pCommandLine) +inline int RunCommand(const std::string& rCommandLine) { - return ::system(ConvertPaths(pCommandLine).c_str()); + return ::system(ConvertPaths(rCommandLine).c_str()); } #ifdef WIN32 @@ -169,7 +169,7 @@ inline int ReadPidFile(const char *pidFile) return pid; } -inline int LaunchServer(const char *pCommandLine, const char *pidFile) +inline int LaunchServer(const std::string& rCommandLine, const char *pidFile) { #ifdef WIN32 @@ -184,7 +184,7 @@ inline int LaunchServer(const char *pCommandLine, const char *pidFile) startInfo.cbReserved2 = 0; startInfo.lpReserved2 = NULL; - std::string cmd = ConvertPaths(pCommandLine); + std::string cmd = ConvertPaths(rCommandLine); CHAR* tempCmd = strdup(cmd.c_str()); DWORD result = CreateProcess @@ -215,9 +215,9 @@ inline int LaunchServer(const char *pCommandLine, const char *pidFile) #else // !WIN32 - if(RunCommand(pCommandLine) != 0) + if(RunCommand(rCommandLine) != 0) { - printf("Server: %s\n", pCommandLine); + printf("Server: %s\n", rCommandLine.c_str()); TEST_FAIL_WITH_MESSAGE("Couldn't start server"); return -1; } @@ -235,7 +235,7 @@ inline int LaunchServer(const char *pCommandLine, const char *pidFile) #endif // time for it to start up - ::fprintf(stdout, "Starting server: %s\n", pCommandLine); + ::fprintf(stdout, "Starting server: %s\n", rCommandLine.c_str()); ::fprintf(stdout, "Waiting for server to start: "); for (int i = 0; i < 15; i++) @@ -398,4 +398,13 @@ inline void wait_for_operation(int seconds) fflush(stdout); } +inline void safe_sleep(int seconds) +{ + struct timespec ts; + ts.tv_sec = seconds; + ts.tv_nsec = 0; + while (nanosleep(&ts, &ts) == -1 && errno == EINTR) + { /* sleep again */ } +} + #endif // TEST__H -- cgit v1.2.3