Changeset 911


Ignore:
Timestamp:
01/09/2006 08:48:12 (5 years ago)
Author:
chris
Message:

Revert to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/merge/test/backupdiff/testbackupdiff.cpp

    r710 r911  
    6767void make_file_of_zeros(const char *filename, size_t size) 
    6868{ 
    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); 
    8385 
    8486        TEST_THAT((size_t)TestGetFileSize(filename) == size); 
     
    117119                { 
    118120                        nnew++; 
    119                         #ifdef WIN32 
    120                         TRACE2("%8I64d this  s=%8I64d", b, s); 
    121                         #else 
    122121                        TRACE2("%8lld this  s=%8lld", b, s); 
    123                         #endif 
    124122                } 
    125123                else 
    126124                { 
    127125                        nold++; 
    128                         #ifdef WIN32 
    129                         TRACE2("%8I64d other i=%8I64d", b, 0 - s);               
    130                         #else 
    131126                        TRACE2("%8lld other i=%8lld", b, 0 - s);                 
    132                         #endif 
    133127                } 
    134128                // Decode the rest 
     
    214208        else 
    215209        { 
    216 #ifdef WIN32 
    217                 // 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 #else 
    223210                // Emulate the above stage! 
    224211                char cmd[256]; 
    225212                sprintf(cmd, "cp testfiles/f%d.diff testfiles/f%d.encoded", to, to); 
    226213                ::system(cmd); 
    227 #endif 
    228214        } 
    229215 
     
    370356        // Want to trace out all the details 
    371357        #ifndef NDEBUG 
    372         #ifndef WIN32 
    373358        BackupStoreFile::TraceDetailsOfDiffProcess = true; 
    374         #endif 
    375359        #endif 
    376360 
     
    387371                std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f0", 1 /* dir ID */, f0name)); 
    388372                encoded->CopyStreamTo(out); 
    389                 out.Close(); 
    390373                check_encoded_file("testfiles/f0.encoded", 0, 33, 0); 
    391374        } 
     
    448431                        std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/f9", 1 /* dir ID */, fn)); 
    449432                        encoded->CopyStreamTo(out); 
    450                         out.Close(); 
    451433                        check_encoded_file("testfiles/f9.zerotest", 0, 0, 0);            
    452434                } 
     
    459441        } 
    460442         
    461 #ifndef WIN32    
    462443        // Check that symlinks aren't diffed 
    463444        TEST_THAT(::symlink("f2", "testfiles/f2.symlink") == 0) 
     
    487468                check_encoded_file("testfiles/f2.symlink.diff", 0, 0, 0);                
    488469        } 
    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 
    493472        { 
    494473                FileStream blockindex("testfiles/f1.diff"); 
     
    502481        } 
    503482 
    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! 
    514485        make_file_of_zeros("testfiles/zero.0", 20*1024*1024); 
    515486        make_file_of_zeros("testfiles/zero.1", 200*1024*1024); 
    516  
    517487        // Generate a first encoded file 
    518488        { 
     
    534504                        0, 0)); 
    535505                encoded->CopyStreamTo(out); 
    536  
    537                 printf("Time taken: %d seconds\n", (int)(time(0) - beginTime)); 
    538  
    539                 #ifdef WIN32 
    540                 TEST_THAT(time(0) < (beginTime + 300)); 
    541                 #else 
    542506                TEST_THAT(time(0) < (beginTime + 40)); 
    543                 #endif 
    544507        } 
    545508        // Remove zero-files to save disk space 
Note: See TracChangeset for help on using the changeset viewer.