Changeset 911
- Timestamp:
- 01/09/2006 08:48:12 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/chris/merge/test/backupdiff/testbackupdiff.cpp
r710 r911 67 67 void make_file_of_zeros(const char *filename, size_t size) 68 68 { 69 #ifdef WIN32 70 HANDLE handle = openfile(filename, O_WRONLY | O_CREAT | O_EXCL, 0); 71 TEST_THAT(handle != INVALID_HANDLE_VALUE); 72 SetFilePointer(handle, size, NULL, FILE_BEGIN); 73 TEST_THAT(GetLastError() == NO_ERROR); 74 TEST_THAT(SetEndOfFile(handle) == true); 75 TEST_THAT(CloseHandle(handle) == true); 76 #else 77 int fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600); 78 if (fd < 0) perror(filename); 79 TEST_THAT(fd >= 0); 80 TEST_THAT(ftruncate(fd, size) == 0); 81 TEST_THAT(close(fd) == 0); 82 #endif 69 static const size_t bs = 0x10000; 70 size_t remSize = size; 71 void *b = malloc(bs); 72 memset(b, 0, bs); 73 FILE *f = fopen(filename, "wb"); 74 75 // Using largish blocks like this is much faster, while not consuming too much RAM 76 while(remSize > bs) 77 { 78 fwrite(b, bs, 1, f); 79 remSize -= bs; 80 } 81 fwrite(b, remSize, 1, f); 82 83 fclose(f); 84 free(b); 83 85 84 86 TEST_THAT((size_t)TestGetFileSize(filename) == size); … … 117 119 { 118 120 nnew++; 119 #ifdef WIN32120 TRACE2("%8I64d this s=%8I64d", b, s);121 #else122 121 TRACE2("%8lld this s=%8lld", b, s); 123 #endif124 122 } 125 123 else 126 124 { 127 125 nold++; 128 #ifdef WIN32129 TRACE2("%8I64d other i=%8I64d", b, 0 - s);130 #else131 126 TRACE2("%8lld other i=%8lld", b, 0 - s); 132 #endif133 127 } 134 128 // Decode the rest … … 214 208 else 215 209 { 216 #ifdef WIN32217 // Emulate the above stage!218 char src[256], dst[256];219 sprintf(src, "testfiles\\f%d.diff", to);220 sprintf(dst, "testfiles\\f%d.encoded", to);221 TEST_THAT(CopyFile(src, dst, FALSE) != 0)222 #else223 210 // Emulate the above stage! 224 211 char cmd[256]; 225 212 sprintf(cmd, "cp testfiles/f%d.diff testfiles/f%d.encoded", to, to); 226 213 ::system(cmd); 227 #endif228 214 } 229 215 … … 370 356 // Want to trace out all the details 371 357 #ifndef NDEBUG 372 #ifndef WIN32373 358 BackupStoreFile::TraceDetailsOfDiffProcess = true; 374 #endif375 359 #endif 376 360 … … 387 371 std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f0", 1 /* dir ID */, f0name)); 388 372 encoded->CopyStreamTo(out); 389 out.Close();390 373 check_encoded_file("testfiles/f0.encoded", 0, 33, 0); 391 374 } … … 448 431 std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f9", 1 /* dir ID */, fn)); 449 432 encoded->CopyStreamTo(out); 450 out.Close();451 433 check_encoded_file("testfiles/f9.zerotest", 0, 0, 0); 452 434 } … … 459 441 } 460 442 461 #ifndef WIN32462 443 // Check that symlinks aren't diffed 463 444 TEST_THAT(::symlink("f2", "testfiles/f2.symlink") == 0) … … 487 468 check_encoded_file("testfiles/f2.symlink.diff", 0, 0, 0); 488 469 } 489 #endif 490 491 // Check that diffing against a file which isn't "complete" and 492 // references another isn't allowed 470 471 // Check that diffing against a file which isn't "complete" and referes another isn't allowed 493 472 { 494 473 FileStream blockindex("testfiles/f1.diff"); … … 502 481 } 503 482 504 // Found a nasty case where files of lots of the same thing 505 // suck up lots of processor time -- because of lots of matches 506 // found. Check this out! 507 508 #ifdef WIN32 509 ::fprintf(stdout, "Testing diffing two large streams, " 510 "may take a while!\n"); 511 ::fflush(stdout); 512 #endif 513 483 // Found a nasty case where files of lots of the same thing sock up lots of processor 484 // time -- because of lots of matches found. Check this out! 514 485 make_file_of_zeros("testfiles/zero.0", 20*1024*1024); 515 486 make_file_of_zeros("testfiles/zero.1", 200*1024*1024); 516 517 487 // Generate a first encoded file 518 488 { … … 534 504 0, 0)); 535 505 encoded->CopyStreamTo(out); 536 537 printf("Time taken: %d seconds\n", (int)(time(0) - beginTime));538 539 #ifdef WIN32540 TEST_THAT(time(0) < (beginTime + 300));541 #else542 506 TEST_THAT(time(0) < (beginTime + 40)); 543 #endif544 507 } 545 508 // Remove zero-files to save disk space
Note: See TracChangeset
for help on using the changeset viewer.
