[Box Backup-dev] COMMIT r665 - box/chris/general/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Jul 23 00:17:58 BST 2006


Author: chris
Date: 2006-07-22 23:17:52 +0000 (Sat, 22 Jul 2006)
New Revision: 665

Modified:
   box/chris/general/lib/common/Test.h
Log:
* Test.h
- Removed the message about expected exceptions, since they're not printed
  in release mode.
- Moved ServerIsAlive() up in the file, so that LaunchServer() can call it
- Made LaunchServer() wait for server to start, show progress, and check 
  that it doesn't die before writing PID file (Win32 only) 
- Moved terminate_bbackupd from test/bbackupd, since test/backupdiff needs
  it as well (under Win32)


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-07-22 17:54:46 UTC (rev 664)
+++ box/chris/general/lib/common/Test.h	2006-07-22 23:17:52 UTC (rev 665)
@@ -44,8 +44,6 @@
 // NOTE: The 0- bit is to allow this to work with stuff which has negative constants for flags (eg ConnectionException)
 #define TEST_CHECK_THROWS(statement, excepttype, subtype)									\
 	{																						\
-		printf("[Test] Expect an exception below: (" \
-			#excepttype "/" #subtype ")\n"); \
 		bool didthrow = false;																\
 		try																					\
 		{																					\
@@ -93,6 +91,31 @@
 	return -1;
 }
 
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+inline bool ServerIsAlive(int pid)
+{
+#ifdef WIN32
+	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
+	if (hProcess == NULL)
+	{
+		if (GetLastError() != ERROR_INVALID_PARAMETER)
+		{
+			printf("Failed to open process %d: error %d\n",
+				pid, (int)GetLastError());
+		}
+		return false;
+	}
+	CloseHandle(hProcess);
+	return true;
+#else // !WIN32
+	if(pid == 0) return false;
+	return ::kill(pid, 0) != -1;
+#endif // WIN32
+}
+
 inline int LaunchServer(const char *CommandLine, const char *pidFile)
 {
 #ifdef WIN32
@@ -154,16 +177,40 @@
 	{
 #endif
 	// time for it to start up
-	::sleep(1);
-	
-	// read pid file
-	if(!TestFileExists(pidFile))
+	::fprintf(stdout, "Starting server: %s\n", CommandLine);
+	::fprintf(stdout, "Waiting for server to start: ");
+
+	for (int i = 0; i < 5; i++)
 	{
-		printf("Server: %s\n", CommandLine);
+		if (TestFileExists(pidFile))	
+			break;
+		if (!ServerIsAlive((int)procInfo.dwProcessId))
+			break;
+		::fprintf(stdout, ".");
+		::fflush(stdout);
+		::sleep(1);
+	}
+
+	#ifdef WIN32
+	if (!ServerIsAlive((int)procInfo.dwProcessId))
+	{
+		::fprintf(stdout, "server died!\n");
+		TEST_FAIL_WITH_MESSAGE("Server died!");	
+		return -1;
+	}
+	else 
+	#endif
+	if (!TestFileExists(pidFile))
+	{
+		::fprintf(stdout, "timed out!\n");
 		TEST_FAIL_WITH_MESSAGE("Server didn't save PID file");	
 		return -1;
 	}
-	
+	else
+	{
+		::fprintf(stdout, "done.\n");
+	}
+
 	FILE *f = fopen(pidFile, "r");
 	if(f == NULL || fscanf(f, "%d", &pid) != 1)
 	{
@@ -188,31 +235,6 @@
 	return pid;
 }
 
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-inline bool ServerIsAlive(int pid)
-{
-#ifdef WIN32
-	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
-	if (hProcess == NULL)
-	{
-		if (GetLastError() != ERROR_INVALID_PARAMETER)
-		{
-			printf("Failed to open process %d: error %d\n",
-				pid, (int)GetLastError());
-		}
-		return false;
-	}
-	CloseHandle(hProcess);
-	return true;
-#else // !WIN32
-	if(pid == 0) return false;
-	return ::kill(pid, 0) != -1;
-#endif // WIN32
-}
-
 inline void TestRemoteProcessMemLeaks(const char *filename)
 {
 #ifdef BOX_MEMORY_LEAK_TESTING
@@ -245,6 +267,35 @@
 #endif
 }
 
+#ifdef WIN32
+#define BBACKUPCTL "..\\..\\bin\\bbackupctl\\bbackupctl"
+#define BBACKUPQUERY "..\\..\\bin\\bbackupquery\\bbackupquery.exe"
+#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected);
+#else
+#define BBACKUPCTL "../../bin/bbackupctl/bbackupctl"
+#define BBACKUPQUERY "../../bin/bbackupquery/bbackupquery"
+#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected*256);
+#endif
+
+inline void terminate_bbackupd(int pid)
+{
+	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
+		"terminate") == 0);
+	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
+
+	for (int i = 0; i < 20; i++)
+	{
+		if (!ServerIsAlive(pid)) break;
+		fprintf(stdout, ".");
+		fflush(stdout);
+		sleep(1);
+	}
+
+	TEST_THAT(!ServerIsAlive(pid));
+	TestRemoteProcessMemLeaks("bbackupd.memleaks");
+}
+
+
 // Wait a given number of seconds for something to complete
 inline void wait_for_operation(int seconds)
 {




More information about the Boxbackup-dev mailing list