[Box Backup-dev] COMMIT r911 - box/chris/merge/test/backupdiff

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Fri Sep 1 08:48:13 BST 2006


Author: chris
Date: 2006-09-01 08:48:12 +0100 (Fri, 01 Sep 2006)
New Revision: 911

Modified:
   box/chris/merge/test/backupdiff/testbackupdiff.cpp
Log:
Revert to trunk


Modified: box/chris/merge/test/backupdiff/testbackupdiff.cpp
===================================================================
--- box/chris/merge/test/backupdiff/testbackupdiff.cpp	2006-08-31 23:43:40 UTC (rev 910)
+++ box/chris/merge/test/backupdiff/testbackupdiff.cpp	2006-09-01 07:48:12 UTC (rev 911)
@@ -66,21 +66,23 @@
 
 void make_file_of_zeros(const char *filename, size_t size)
 {
-	#ifdef WIN32
-	HANDLE handle = openfile(filename, O_WRONLY | O_CREAT | O_EXCL, 0);
-	TEST_THAT(handle != INVALID_HANDLE_VALUE);
-	SetFilePointer(handle, size, NULL, FILE_BEGIN);
-	TEST_THAT(GetLastError() == NO_ERROR);
-	TEST_THAT(SetEndOfFile(handle) == true);
-	TEST_THAT(CloseHandle(handle)  == true);
-	#else
-	int fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
-	if (fd < 0) perror(filename);
-	TEST_THAT(fd >= 0);
-	TEST_THAT(ftruncate(fd, size) == 0);
-	TEST_THAT(close(fd) == 0);
-	#endif
+	static const size_t bs = 0x10000;
+	size_t remSize = size;
+	void *b = malloc(bs);
+	memset(b, 0, bs);
+	FILE *f = fopen(filename, "wb");
 
+	// Using largish blocks like this is much faster, while not consuming too much RAM
+	while(remSize > bs)
+	{
+		fwrite(b, bs, 1, f);
+		remSize -= bs;
+	}
+	fwrite(b, remSize, 1, f);
+
+	fclose(f);
+	free(b);
+
 	TEST_THAT((size_t)TestGetFileSize(filename) == size);
 }
 
@@ -116,20 +118,12 @@
 		if(s > 0)
 		{
 			nnew++;
-			#ifdef WIN32
-			TRACE2("%8I64d this  s=%8I64d", b, s);
-			#else
 			TRACE2("%8lld this  s=%8lld", b, s);
-			#endif
 		}
 		else
 		{
 			nold++;
-			#ifdef WIN32
-			TRACE2("%8I64d other i=%8I64d", b, 0 - s);		
-			#else
 			TRACE2("%8lld other i=%8lld", b, 0 - s);		
-			#endif
 		}
 		// Decode the rest
 		uint64_t iv = box_ntoh64(hdr.mEntryIVBase);
@@ -213,18 +207,10 @@
 	}
 	else
 	{
-#ifdef WIN32
 		// Emulate the above stage!
-		char src[256], dst[256];
-		sprintf(src, "testfiles\\f%d.diff", to);
-		sprintf(dst, "testfiles\\f%d.encoded", to);
-		TEST_THAT(CopyFile(src, dst, FALSE) != 0)
-#else
-		// Emulate the above stage!
 		char cmd[256];
 		sprintf(cmd, "cp testfiles/f%d.diff testfiles/f%d.encoded", to, to);
 		::system(cmd);
-#endif
 	}
 
 	// Decode it
@@ -369,10 +355,8 @@
 {
 	// Want to trace out all the details
 	#ifndef NDEBUG
-	#ifndef WIN32
 	BackupStoreFile::TraceDetailsOfDiffProcess = true;
 	#endif
-	#endif
 
 	// Create all the test files
 	create_test_files();
@@ -386,7 +370,6 @@
 		FileStream out("testfiles/f0.encoded", O_WRONLY | O_CREAT | O_EXCL);
 		std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f0", 1 /* dir ID */, f0name));
 		encoded->CopyStreamTo(out);
-		out.Close();
 		check_encoded_file("testfiles/f0.encoded", 0, 33, 0);
 	}
 	
@@ -447,7 +430,6 @@
 			FileStream out("testfiles/f9.zerotest", O_WRONLY | O_CREAT | O_EXCL);
 			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f9", 1 /* dir ID */, fn));
 			encoded->CopyStreamTo(out);
-			out.Close();
 			check_encoded_file("testfiles/f9.zerotest", 0, 0, 0);		
 		}
 		{
@@ -458,7 +440,6 @@
 		}
 	}
 	
-#ifndef WIN32	
 	// Check that symlinks aren't diffed
 	TEST_THAT(::symlink("f2", "testfiles/f2.symlink") == 0)
 	// And go and diff it against the previous encoded file
@@ -486,10 +467,8 @@
 		TEST_THAT(completelyDifferent == true);
 		check_encoded_file("testfiles/f2.symlink.diff", 0, 0, 0);		
 	}
-#endif
 
-	// Check that diffing against a file which isn't "complete" and 
-	// references another isn't allowed
+	// Check that diffing against a file which isn't "complete" and referes another isn't allowed
 	{
 		FileStream blockindex("testfiles/f1.diff");
 		BackupStoreFile::MoveStreamPositionToBlockIndex(blockindex);
@@ -501,19 +480,10 @@
 			0, 0), BackupStoreException, CannotDiffAnIncompleteStoreFile);
 	}
 
-	// Found a nasty case where files of lots of the same thing 
-	// suck up lots of processor time -- because of lots of matches 
-	// found. Check this out!
-
-	#ifdef WIN32
-	::fprintf(stdout, "Testing diffing two large streams, "
-		"may take a while!\n");
-	::fflush(stdout);
-	#endif
-
+	// Found a nasty case where files of lots of the same thing sock up lots of processor
+	// time -- because of lots of matches found. Check this out!
 	make_file_of_zeros("testfiles/zero.0", 20*1024*1024);
 	make_file_of_zeros("testfiles/zero.1", 200*1024*1024);
-
 	// Generate a first encoded file
 	{
 		BackupStoreFilenameClear f0name("zero.0");
@@ -533,14 +503,7 @@
 			2000 /* object ID of the file diffing from */, blockindex, IOStream::TimeOutInfinite,
 			0, 0));
 		encoded->CopyStreamTo(out);
-
-		printf("Time taken: %d seconds\n", (int)(time(0) - beginTime));
-
-		#ifdef WIN32
-		TEST_THAT(time(0) < (beginTime + 300));
-		#else
 		TEST_THAT(time(0) < (beginTime + 40));
-		#endif
 	}
 	// Remove zero-files to save disk space
 	remove("testfiles/zero.0");




More information about the Boxbackup-dev mailing list