[Box Backup-commit] COMMIT r1562 - in box/chris/general: . bin/bbackupd infrastructure lib/common lib/server test/bbackupd test/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Apr 22 16:13:59 BST 2007


Author: chris
Date: 2007-04-22 16:13:59 +0100 (Sun, 22 Apr 2007)
New Revision: 1562

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
   box/chris/general/configure.ac
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
   box/chris/general/infrastructure/makebuildenv.pl.in
   box/chris/general/lib/common/Box.h
   box/chris/general/lib/common/Logging.cpp
   box/chris/general/lib/common/Logging.h
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/common/Utils.cpp
   box/chris/general/lib/server/Daemon.cpp
   box/chris/general/lib/server/Daemon.h
   box/chris/general/test/bbackupd/testbbackupd.cpp
   box/chris/general/test/common/testcommon.cpp
Log:
Merge from chris/merge:

 * [1545] Detect whether getopt.h is present on system.

 * [1546] Pass all arguments from test scripts to test executable with
   proper quoting.

 * [1547] Declare global std::string variables that hold extra arguments
   for executables run in tests.

 * [1547] ConvertPaths, LaunchServer and RunCommand all take std::string
   references instead of char*.

 * [1547] Move safe_sleep from test/common to lib/server/Test.h so that
   all tests can use it.

 * [1548] Use logging framework to log exceptions.

 * [1549] Use logging framework to log stack traces from exceptions.

 * [1550] Log event name instead of numeric code when notifying sysadmin
   in BackupDaemon.

 * [1551] Add options to log timestamps, and a custom tag, with each
   message to the console.

 * [1552] Add Daemon -V option, which sets maximum verbosity in one go.

 * [1552] Add Daemon -T option, which adds timestamps to console logs.

 * [1552] Add Daemon -t option, which enabled and sets the tag used on
   console logs.

 * [1552] Add Daemon -k option, which keeps console open after forking.

 * [1553] Add test --bbackupd-args and --bbstored-args options, which
   may be used to pass additional command-line parameters to bbackupd
   and bbstored in some tests.

 * [1553] Add test -t and -T options, which add tags and timestamps to
   log messages using the logging framework inside the tests themselves.

 * [1554] Use additional arguments from command line options when
   starting bbackupd and bbstored in test/bbackupd.

 * [1555] Replace sleep() with safe_sleep() everywhere in test/bbackupd.

 * [1556] Fix excessively verbose warnings while waiting for daemon to
   start in test/bbackupd.

Fix SyncAllowScript test on Unix, where multiple simultaneous connections
to the store are allowed, so we have to wait for backup to finish.


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -1141,7 +1141,7 @@
 		std::string line;
 		if(getLine.GetLine(line, true, 30000)) // 30 seconds should be enough
 		{
-			// Got a string, intepret
+			// Got a string, interpret
 			if(line == "now")
 			{
 				// Script says do it now. Obey.
@@ -2201,7 +2201,8 @@
 		0
 	};
 
-	BOX_TRACE("BackupDaemon::NotifySysadmin() called, event = " << Event);
+	BOX_TRACE("BackupDaemon::NotifySysadmin() called, event = " << 
+		sEventNames[Event]);
 
 	if(Event < 0 || Event >= NotifyEvent__MAX)
 	{

Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/configure.ac	2007-04-22 15:13:59 UTC (rev 1562)
@@ -102,7 +102,7 @@
 
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([dlfcn.h execinfo.h process.h pwd.h signal.h])
+AC_CHECK_HEADERS([dlfcn.h execinfo.h getopt.h process.h pwd.h signal.h])
 AC_CHECK_HEADERS([syslog.h time.h])
 AC_CHECK_HEADERS([netinet/in.h])
 AC_CHECK_HEADERS([sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h])

Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -28,12 +28,17 @@
 #include <errno.h>
 #include <string>
 
+#ifdef HAVE_GETOPT_H
+	#include <getopt.h>
+#endif
+
 #ifdef WIN32
 	#include "emu.h"
 #else
 	#include <syslog.h>
 #endif
 
+#include "Logging.h"
 #include "Test.h"
 #include "Timer.h"
 
@@ -50,13 +55,14 @@
 int failures = 0;
 int first_fail_line;
 std::string first_fail_file;
+std::string bbackupd_args, bbstored_args, bbackupquery_args;
 
 int filedes_open_at_beginning = -1;
 
 #ifdef WIN32
 
 // any way to check for open file descriptors on Win32?
-inline int count_filedes() { return 0; }
+inline int  count_filedes()      { return 0;     }
 inline bool checkfilesleftopen() { return false; }
 
 #else // !WIN32
@@ -96,11 +102,72 @@
 
 #endif
 
-int main(int argc, const char *argv[])
+int main(int argc, char * const * argv)
 {
 	// Start memory leak testing
 	MEMLEAKFINDER_START
 
+#ifdef HAVE_GETOPT_H
+	struct option longopts[] = 
+	{
+		{ "bbackupd-args",	required_argument, NULL, 'c' },
+		{ "bbstored-args",	required_argument, NULL, 's' },
+		{ NULL,			0,                 NULL,  0  }
+	};
+	
+	int ch;
+	
+	while ((ch = getopt_long(argc, argv, "c:s:t:T", longopts, NULL))
+		!= -1)
+	{
+		switch(ch)
+		{
+			case 'c':
+			{
+				bbackupd_args += " ";
+				bbackupd_args += optarg;
+			}
+			break;
+
+			case 's':
+			{
+				bbstored_args += " ";
+				bbstored_args += optarg;
+			}
+			break;
+
+			case 't':
+			{
+				Console::SetTag(optarg);
+			}
+			break;
+
+			case 'T':
+			{
+				Console::SetShowTime(true);
+			}
+			break;
+
+			case '?':
+			{
+				fprintf(stderr, "Unknown option: %s\n",
+					optarg);
+				exit(2);
+			}
+
+			default:
+			{
+				fprintf(stderr, "Unknown option code '%c'\n",
+					ch);
+				exit(2);
+			}
+		}
+	}
+
+	argc -= optind - 1;
+	argv += optind - 1;
+#endif // HAVE_GETOPT_H
+
 	// If there is more than one argument, then the test is doing something advanced, so leave it alone
 	bool fulltestmode = (argc == 1);
 
@@ -120,6 +187,7 @@
 			TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)
 		#endif
 	}
+
 	try
 	{
 		#ifdef BOX_MEMORY_LEAK_TESTING
@@ -127,7 +195,7 @@
 		#endif
 
 		Timers::Init();
-		int returncode = test(argc, argv);
+		int returncode = test(argc, (const char **)argv);
 		Timers::Cleanup();
 		
 		// check for memory leaks, if enabled

Modified: box/chris/general/infrastructure/makebuildenv.pl.in
===================================================================
--- box/chris/general/infrastructure/makebuildenv.pl.in	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/infrastructure/makebuildenv.pl.in	2007-04-22 15:13:59 UTC (rev 1562)
@@ -445,9 +445,9 @@
 		}
 		
 		writetestfile("$mod/_t", "GLIBCXX_FORCE_NEW=1 ".
-			'./test' . $platform_exe_ext . ' $1 $2 $3 $4 $5', $mod);
+			'./test' . $platform_exe_ext . ' "$@"', $mod);
 		writetestfile("$mod/_t-gdb", "GLIBCXX_FORCE_NEW=1 ".
-			'gdb ./test' . $platform_exe_ext . ' $*', $mod);
+			'gdb ./test' . $platform_exe_ext . ' "$@"', $mod);
 		
 	}
 	

Modified: box/chris/general/lib/common/Box.h
===================================================================
--- box/chris/general/lib/common/Box.h	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/common/Box.h	2007-04-22 15:13:59 UTC (rev 1562)
@@ -27,13 +27,14 @@
 #endif
 
 #ifdef SHOW_BACKTRACE_ON_EXCEPTION
-  #include "Utils.h"
+	#include "Utils.h"
 	#define OPTIONAL_DO_BACKTRACE DumpStackBacktrace();
 #else
 	#define OPTIONAL_DO_BACKTRACE
 #endif
 
 #include "CommonException.h"
+#include "Logging.h"
 
 #ifndef NDEBUG
 	
@@ -108,11 +109,12 @@
 	#define MEMLEAKFINDER_STOP
 #endif
 
-#define THROW_EXCEPTION(type, subtype)														\
-	{																						\
-		OPTIONAL_DO_BACKTRACE																\
-		TRACE1("Exception thrown: " #type "(" #subtype ") at " __FILE__ "(%d)\n", __LINE__)	\
-		throw type(type::subtype);															\
+#define THROW_EXCEPTION(type, subtype) \
+	{ \
+		OPTIONAL_DO_BACKTRACE \
+		BOX_TRACE("Exception thrown: " #type "(" #subtype ") at " \
+			__FILE__ "(" << __LINE__ << ")") \
+		throw type(type::subtype); \
 	}
 
 // extra macros for converting to network byte order

Modified: box/chris/general/lib/common/Logging.cpp
===================================================================
--- box/chris/general/lib/common/Logging.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/common/Logging.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -9,12 +9,16 @@
 
 #include "Box.h"
 
+#include <time.h>
+
 #ifdef HAVE_SYSLOG_H
 	#include <syslog.h>
 #endif
 
 #include "Logging.h"
 
+#include <iomanip>
+
 bool Logging::sLogToSyslog  = false;
 bool Logging::sLogToConsole = false;
 bool Logging::sContextSet   = false;
@@ -172,6 +176,21 @@
 	Logging::Remove(this);
 }
 
+bool Console::sShowTime = false;
+bool Console::sShowTag  = false;
+std::string Console::sTag;
+
+void Console::SetTag(const std::string& rTag)
+{
+	sTag = rTag;
+	sShowTag = true;
+}
+
+void Console::SetShowTime(bool enabled)
+{
+	sShowTime = enabled;
+}
+
 bool Console::Log(Log::Level level, const std::string& rFile, 
 	int line, std::string& rMessage)
 {
@@ -186,8 +205,43 @@
 	{
 		target = stderr;
 	}
+
+	std::string msg;
+
+	if (sShowTime)
+	{
+		struct tm time_now;
+		time_t time_t_now = time(NULL);
+
+		if (time_t_now == ((time_t)-1))
+		{
+			msg += strerror(errno);
+			msg += " ";
+		}
+		else if (localtime_r(&time_t_now, &time_now) != NULL)
+		{
+			std::ostringstream buf;
+			buf << std::setfill('0') <<
+				std::setw(2) << time_now.tm_hour << ":" << 
+				std::setw(2) << time_now.tm_min  << ":" <<
+				std::setw(2) << time_now.tm_sec  << " ";
+			msg += buf.str();
+		}
+		else
+		{
+			msg += strerror(errno);
+			msg += " ";
+		}
+	}
+
+	if (sShowTag)
+	{
+		msg += "[" + sTag + "] ";
+	}
 	
-	fprintf(target, "%s\n", rMessage.c_str());
+	msg += rMessage;
+
+	fprintf(target, "%s\n", msg.c_str());
 	
 	return true;
 }

Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/common/Logging.h	2007-04-22 15:13:59 UTC (rev 1562)
@@ -102,11 +102,19 @@
 
 class Console : public Logger
 {
+	private:
+	static bool sShowTime;
+	static bool sShowTag;
+	static std::string sTag;
+
 	public:
 	virtual bool Log(Log::Level level, const std::string& rFile, 
 		int line, std::string& rMessage);
 	virtual const char* GetType() { return "Console"; }
 	virtual void SetProgramName(const std::string& rProgramName) { }
+
+	static void SetTag(const std::string& rTag);
+	static void SetShowTime(bool enabled);
 };
 
 // --------------------------------------------------------------------------

Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/common/Test.h	2007-04-22 15:13:59 UTC (rev 1562)
@@ -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 @@
 	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 @@
 	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 @@
 	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 @@
 
 #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 @@
 	#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++)
@@ -400,4 +400,13 @@
 	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

Modified: box/chris/general/lib/common/Utils.cpp
===================================================================
--- box/chris/general/lib/common/Utils.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/common/Utils.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -20,6 +20,7 @@
 
 #include "Utils.h"
 #include "CommonException.h"
+#include "Logging.h"
 
 #include "MemLeakFindOn.h"
 
@@ -71,11 +72,11 @@
 	size = backtrace (array, 10);
 	strings = backtrace_symbols (array, size);
 
-	printf ("Obtained %zd stack frames.\n", size);
+	BOX_TRACE("Obtained " << size << " stack frames.");
 
 	for(i = 0; i < size; i++)
 	{
-		printf("%s\n", strings[i]);
+		BOX_TRACE(strings[i]);
 	}
 
 #include "MemLeakFindOff.h"

Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/server/Daemon.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -51,7 +51,8 @@
 Daemon::Daemon()
 	: mpConfiguration(NULL),
 	  mReloadConfigWanted(false),
-	  mTerminateWanted(false)
+	  mTerminateWanted(false),
+	  mKeepConsoleOpenAfterFork(false)
 {
 	if(spDaemon != NULL)
 	{
@@ -109,8 +110,9 @@
 	#endif
 
 	char c;
+	optind = 0; // just in case anybody used getopt before
 
-	while((c = getopt(argc, (char * const *)argv, "c:Dqv")) != -1)
+	while((c = getopt(argc, (char * const *)argv, "c:DqvVt:Tk")) != -1)
 	{
 		switch(c)
 		{
@@ -153,10 +155,34 @@
 			}
 			break;
 
+			case 'V':
+			{
+				masterLevel = Log::EVERYTHING;
+			}
+			break;
+
+			case 't':
+			{
+				Console::SetTag(optarg);
+			}
+			break;
+
+			case 'T':
+			{
+				Console::SetShowTime(true);
+			}
+			break;
+
+			case 'k':
+			{
+				mKeepConsoleOpenAfterFork = true;
+			}
+			break;
+
 			case '?':
 			{
 				BOX_FATAL("Unknown option on command line: " 
-					<< "'" << optopt << "'");
+					<< "'" << (char)optopt << "'");
 				return 2;
 			}
 			break;
@@ -377,7 +403,7 @@
 		}
 		#endif // BOX_MEMORY_LEAK_TESTING
 	
-		if(asDaemon)
+		if(asDaemon && !mKeepConsoleOpenAfterFork)
 		{
 #ifndef WIN32
 			// Close standard streams

Modified: box/chris/general/lib/server/Daemon.h
===================================================================
--- box/chris/general/lib/server/Daemon.h	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/lib/server/Daemon.h	2007-04-22 15:13:59 UTC (rev 1562)
@@ -77,6 +77,7 @@
 	box_time_t mLoadedConfigModifiedTime;
 	bool mReloadConfigWanted;
 	bool mTerminateWanted;
+	bool mKeepConsoleOpenAfterFork;
 	static Daemon *spDaemon;
 };
 

Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -419,14 +419,14 @@
 
 int test_run_bbstored()
 {
-	bbstored_pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", 
-		"testfiles/bbstored.pid");
+	std::string cmd = BBSTORED + bbstored_args + " testfiles/bbstored.conf";
+	bbstored_pid = LaunchServer(cmd, "testfiles/bbstored.pid");
 
 	TEST_THAT(bbstored_pid != -1 && bbstored_pid != 0);
 
 	if(bbstored_pid > 0)
 	{
-		::sleep(1);
+		::safe_sleep(1);
 		TEST_THAT(ServerIsAlive(bbstored_pid));
 		return 0;	// success
 	}
@@ -437,7 +437,7 @@
 int test_kill_bbstored()
 {
 	TEST_THAT(KillServer(bbstored_pid));
-	::sleep(1);
+	::safe_sleep(1);
 	TEST_THAT(!ServerIsAlive(bbstored_pid));
 
 	#ifndef WIN32
@@ -640,9 +640,13 @@
 	{
 		printf(".");
 		fflush(stdout);
-		sleep(1);
+		safe_sleep(1);
 
-		pid = ReadPidFile("testfiles/bbackupd.pid");
+		if (TestFileExists("testfiles/bbackupd.pid"))
+		{
+			pid = ReadPidFile("testfiles/bbackupd.pid");
+		}
+
 		if (pid > 0)
 		{
 			break;
@@ -1043,12 +1047,12 @@
 	}
 #endif // PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
 
-	bbackupd_pid = LaunchServer(BBACKUPD " testfiles/bbackupd.conf", 
-		"testfiles/bbackupd.pid");
+	std::string cmd = BBACKUPD + bbackupd_args + " testfiles/bbackupd.conf";
+	bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 
 	TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
 
-	::sleep(1);
+	::safe_sleep(1);
 
 	TEST_THAT(ServerIsAlive(bbackupd_pid));
 	TEST_THAT(ServerIsAlive(bbstored_pid));
@@ -1435,7 +1439,6 @@
 		if (!ServerIsAlive(bbackupd_pid)) return 1;
 		if (!ServerIsAlive(bbstored_pid)) return 1;
 
-		// Check that SyncAllowScript is executed and can pause backup
 		printf("\n==== Check that SyncAllowScript is executed and can "
 			"pause backup\n");
 		fflush(stdout);
@@ -1481,10 +1484,10 @@
 			// next poll should happen within the next
 			// 5 seconds (normally about 3 seconds)
 
-			sleep(1); // 2 seconds before
+			safe_sleep(1); // 2 seconds before
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
 				"syncallowscript.notifyran.1", &st) != 0);
-			sleep(4); // 2 seconds after
+			safe_sleep(4); // 2 seconds after
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
 				"syncallowscript.notifyran.1", &st) == 0);
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
@@ -1493,10 +1496,10 @@
 			// next poll should happen within the next
 			// 10 seconds (normally about 8 seconds)
 
-			sleep(6); // 2 seconds before
+			safe_sleep(6); // 2 seconds before
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
 				"syncallowscript.notifyran.2", &st) != 0);
-			sleep(4); // 2 seconds after
+			safe_sleep(4); // 2 seconds after
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
 				"syncallowscript.notifyran.2", &st) == 0);
 
@@ -1520,6 +1523,7 @@
 			TEST_THAT(wait_time >= 8);
 			TEST_THAT(wait_time <= 12);
 
+			wait_for_sync_end();
 			// check that backup has run (compare succeeds)
 			compareReturnValue = ::system(BBACKUPQUERY " -q "
 				"-c testfiles/bbackupd.conf "
@@ -1527,6 +1531,12 @@
 				"\"compare -acQ\" quit");
 			TEST_RETURN(compareReturnValue, 1);
 			TestRemoteProcessMemLeaks("bbackupquery.memleaks");
+
+			if (failures > 0)
+			{
+				// stop early to make debugging easier
+				return 1;
+			}
 		}
 
 		TEST_THAT(ServerIsAlive(bbackupd_pid));
@@ -1785,7 +1795,7 @@
 		TEST_THAT(fd2 > 0);
 		TEST_THAT(write(fd1, "hello", 5) == 5);
 		TEST_THAT(close(fd1) == 0);
-		sleep(1);
+		safe_sleep(1);
 		TEST_THAT(write(fd2, "world", 5) == 5);
 		TEST_THAT(close(fd2) == 0);
 		TEST_THAT(TestFileExists("testfiles/TestDir1/untracked-1"));
@@ -1835,7 +1845,7 @@
 		TEST_THAT(write(fd1, "hello", 5) == 5);
 		TEST_THAT(write(fd1, buffer, sizeof(buffer)) == sizeof(buffer));
 		TEST_THAT(close(fd1) == 0);
-		sleep(1);
+		safe_sleep(1);
 		TEST_THAT(write(fd2, "world", 5) == 5);
 		TEST_THAT(write(fd2, buffer, sizeof(buffer)) == sizeof(buffer));
 		TEST_THAT(close(fd2) == 0);
@@ -1920,13 +1930,13 @@
 			"\"compare -acQ\" quit");
 		TEST_RETURN(compareReturnValue, 1);
 		TestRemoteProcessMemLeaks("bbackupquery.memleaks");
-
+		
 		TEST_THAT(ServerIsAlive(bbackupd_pid));
 		TEST_THAT(ServerIsAlive(bbstored_pid));
 		if (!ServerIsAlive(bbackupd_pid)) return 1;
 		if (!ServerIsAlive(bbstored_pid)) return 1;
 
-		// Check that modifying files with old timestamps 
+		// Check that modifying files with old timestamps
 		// still get added
 		printf("\n==== Modify existing file, but change timestamp "
 			"to rather old\n");
@@ -2158,7 +2168,7 @@
 		wait_for_sync_start();
 
 		// Then wait a second, to make sure the scan is complete
-		::sleep(1);
+		::safe_sleep(1);
 
 		{
 			// Open a file, then save something to it every second
@@ -2172,7 +2182,7 @@
 
 				printf(".");
 				fflush(stdout);
-				sleep(1);
+				safe_sleep(1);
 			}
 			printf("\n");
 			fflush(stdout);
@@ -2202,7 +2212,7 @@
 
 				printf(".");
 				fflush(stdout);
-				sleep(1);
+				safe_sleep(1);
 			}
 			printf("\n");
 			fflush(stdout);
@@ -2474,7 +2484,7 @@
 		wait_for_sync_start();
 
 		// Then wait a second, to make sure the scan is complete
-		::sleep(1);
+		::safe_sleep(1);
 
 		// Then modify an existing file
 		{
@@ -2754,9 +2764,8 @@
 		terminate_bbackupd(bbackupd_pid);
 		
 		// Start it again
-		bbackupd_pid = LaunchServer(BBACKUPD 
-			" testfiles/bbackupd.conf", 
-			"testfiles/bbackupd.pid");
+		cmd = BBACKUPD + bbackupd_args + " testfiles/bbackupd.conf";
+		bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
 

Modified: box/chris/general/test/common/testcommon.cpp
===================================================================
--- box/chris/general/test/common/testcommon.cpp	2007-04-22 14:45:44 UTC (rev 1561)
+++ box/chris/general/test/common/testcommon.cpp	2007-04-22 15:13:59 UTC (rev 1562)
@@ -137,19 +137,6 @@
 	0
 };
 
-void safe_sleep(int seconds)
-{
-#ifdef WIN32
-	Sleep(seconds * 1000);
-#else
-	struct timespec ts;
-	ts.tv_sec  = seconds;
-	ts.tv_nsec = 0;
-	while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
-	{ /* sleep again */ }
-#endif
-}
-
 class TestLogger : public Logger
 {
 	private:




More information about the Boxbackup-commit mailing list