diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/backupstore/Makefile.extra | 4 | ||||
-rw-r--r-- | test/backupstore/testbackupstore.cpp | 1118 | ||||
-rw-r--r-- | test/backupstorefix/testbackupstorefix.cpp | 746 | ||||
-rwxr-xr-x | test/backupstorefix/testfiles/testbackupstorefix.pl.in | 4 | ||||
-rw-r--r-- | test/backupstorepatch/testbackupstorepatch.cpp | 48 | ||||
-rw-r--r-- | test/basicserver/Makefile.extra | 11 | ||||
-rw-r--r-- | test/basicserver/TestCommands.cpp | 53 | ||||
-rw-r--r-- | test/basicserver/testbasicserver.cpp | 37 | ||||
-rw-r--r-- | test/bbackupd/Makefile.extra | 11 | ||||
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 916 | ||||
-rw-r--r-- | test/bbackupd/testfiles/bbackupd-temploc.conf.in | 58 | ||||
-rw-r--r-- | test/common/testcommon.cpp | 40 |
12 files changed, 3046 insertions, 0 deletions
diff --git a/test/backupstore/Makefile.extra b/test/backupstore/Makefile.extra index e2e2d27c..2ce40389 100644 --- a/test/backupstore/Makefile.extra +++ b/test/backupstore/Makefile.extra @@ -1 +1,5 @@ +<<<<<<< HEAD link-extra: ../../bin/bbstored/HousekeepStoreAccount.o +======= +link-extra: ../../lib/backupstore/HousekeepStoreAccount.o +>>>>>>> 0.12 diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 646e6b45..cc708da0 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -12,6 +12,7 @@ #include <stdlib.h> #include <string.h> +<<<<<<< HEAD #include "Test.h" #include "autogen_BackupProtocolClient.h" #include "SSLLib.h" @@ -38,6 +39,36 @@ #include "BackupStoreRefCountDatabase.h" #include "BackupStoreAccounts.h" #include "HousekeepStoreAccount.h" +======= +#include "Archive.h" +#include "BackupClientCryptoKeys.h" +#include "BackupClientFileAttributes.h" +#include "BackupStoreAccountDatabase.h" +#include "BackupStoreAccounts.h" +#include "BackupStoreConstants.h" +#include "BackupStoreDirectory.h" +#include "BackupStoreException.h" +#include "BackupStoreInfo.h" +#include "BackupStoreFilenameClear.h" +#include "BackupStoreRefCountDatabase.h" +#include "BackupStoreFile.h" +#include "BoxPortsAndFiles.h" +#include "CollectInBufferStream.h" +#include "FileStream.h" +#include "HousekeepStoreAccount.h" +#include "MemBlockStream.h" +#include "RaidFileController.h" +#include "RaidFileException.h" +#include "RaidFileRead.h" +#include "RaidFileWrite.h" +#include "SSLLib.h" +#include "ServerControl.h" +#include "Socket.h" +#include "SocketStreamTLS.h" +#include "TLSContext.h" +#include "Test.h" +#include "autogen_BackupProtocol.h" +>>>>>>> 0.12 #include "MemLeakFindOn.h" @@ -221,10 +252,13 @@ void CheckEntries(BackupStoreDirectory &rDir, int16_t FlagsMustBeSet, int16_t Fl int test1(int argc, const char *argv[]) { +<<<<<<< HEAD // Initialise the raid file controller RaidFileController &rcontroller = RaidFileController::GetController(); rcontroller.Initialise("testfiles/raidfile.conf"); +======= +>>>>>>> 0.12 // test some basics -- encoding and decoding filenames { // Make some filenames in various ways @@ -437,6 +471,7 @@ void test_test_file(int t, IOStream &rStream) void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) { +<<<<<<< HEAD printf("Test for del: %llx\n", DirID); // Command @@ -444,6 +479,15 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) DirID, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + printf("Test for del: %llx\n", (unsigned long long)DirID); + + // Command + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + DirID, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -455,7 +499,11 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) int dirs = 0; while((en = i.Next()) != 0) { +<<<<<<< HEAD if(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Dir) +======= + if(en->GetFlags() & BackupProtocolListDirectory::Flags_Dir) +>>>>>>> 0.12 { dirs++; // Recurse @@ -466,7 +514,11 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID) files++; } // Check it's deleted +<<<<<<< HEAD TEST_THAT(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Deleted); +======= + TEST_THAT(en->GetFlags() & BackupProtocolListDirectory::Flags_Deleted); +>>>>>>> 0.12 } // Check there were the right number of files and directories @@ -478,7 +530,11 @@ std::vector<uint32_t> ExpectedRefCounts; void set_refcount(int64_t ObjectID, uint32_t RefCount = 1) { +<<<<<<< HEAD if (ExpectedRefCounts.size() <= ObjectID); +======= + if ((int64_t)ExpectedRefCounts.size() <= ObjectID); +>>>>>>> 0.12 { ExpectedRefCounts.resize(ObjectID + 1, 0); } @@ -491,7 +547,11 @@ void create_file_in_dir(std::string name, std::string source, int64_t parentId, BackupStoreFilenameClear name_encoded("file_One"); std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile( source.c_str(), parentId, name_encoded)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored( +======= + std::auto_ptr<BackupProtocolSuccess> stored( +>>>>>>> 0.12 protocol.QueryStoreFile( parentId, 0x123456789abcdefLL, /* modification time */ @@ -515,13 +575,22 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, // Create with dummy attributes int attrS = 0; MemBlockStream attr(&attrS, sizeof(attrS)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory( +======= + std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory( +>>>>>>> 0.12 indir, 9837429842987984LL, dirname, attr)); subdirid = dirCreate->GetObjectID(); } +<<<<<<< HEAD printf("Create subdirs, depth = %d, dirid = %llx\n", depth, subdirid); +======= + printf("Create subdirs, depth = %d, dirid = %llx\n", depth, + (unsigned long long)subdirid); +>>>>>>> 0.12 TEST_EQUAL(subdirid, rRefCount.GetLastObjectIDUsed()); TEST_EQUAL(1, rRefCount.GetRefCount(subdirid)) @@ -550,11 +619,19 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMemBlock &Attributes) { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); TEST_THAT(dirreply->GetObjectID() == BackupProtocolClientListDirectory::RootDirectory); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); + TEST_THAT(dirreply->GetObjectID() == BackupProtocolListDirectory::RootDirectory); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -575,9 +652,15 @@ void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMem TEST_THAT(en->GetName() == uploads[t].name); TEST_THAT(en->GetObjectID() == uploads[t].allocated_objid); TEST_THAT(en->GetModificationTime() == uploads[t].mod_time); +<<<<<<< HEAD int correct_flags = BackupProtocolClientListDirectory::Flags_File; if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolClientListDirectory::Flags_OldVersion; if(uploads[t].delete_file) correct_flags |= BackupProtocolClientListDirectory::Flags_Deleted; +======= + int correct_flags = BackupProtocolListDirectory::Flags_File; + if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolListDirectory::Flags_OldVersion; + if(uploads[t].delete_file) correct_flags |= BackupProtocolListDirectory::Flags_Deleted; +>>>>>>> 0.12 TEST_THAT(en->GetFlags() == correct_flags); if(t == UPLOAD_ATTRS_EN) { @@ -606,10 +689,17 @@ typedef struct void recursive_count_objects_r(BackupProtocolClient &protocol, int64_t id, recursive_count_objects_results &results) { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( id, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + id, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -649,9 +739,15 @@ void recursive_count_objects(const char *hostname, int64_t id, recursive_count_o BackupProtocolClient protocolReadOnly(connReadOnly); { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly)); +======= + std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); +>>>>>>> 0.12 } // Count objects @@ -758,10 +854,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco for(int l = 0; l < 3; ++l) { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -772,10 +875,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Read the dir from the readonly connection (make sure it gets in the cache) { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -787,7 +897,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco BackupStoreFilenameClear store1name("testfiles/file1"); { FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT | O_EXCL); +<<<<<<< HEAD std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolClientListDirectory::RootDirectory, store1name)); +======= + std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolListDirectory::RootDirectory, store1name)); +>>>>>>> 0.12 encoded->CopyStreamTo(out); } @@ -797,8 +911,13 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco int64_t store1objid = 0; { FileStream upload("testfiles/file1_upload1"); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( BackupProtocolClientListDirectory::RootDirectory, +======= + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 0x123456789abcdefLL, /* modification time */ 0x7362383249872dfLL, /* attr hash */ 0, /* diff from ID */ @@ -811,7 +930,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // And retrieve it { // Retrieve as object +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getfile(protocol.QueryGetObject(store1objid)); +======= + std::auto_ptr<BackupProtocolSuccess> getfile(protocol.QueryGetObject(store1objid)); +>>>>>>> 0.12 TEST_THAT(getfile->GetObjectID() == store1objid); // BLOCK { @@ -826,7 +949,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco } // Retrieve as file +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, store1objid)); +======= + std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, store1objid)); +>>>>>>> 0.12 TEST_THAT(getobj->GetObjectID() == store1objid); // BLOCK { @@ -852,7 +979,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Retrieve the block index, by ID { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid)); +======= + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid)); +>>>>>>> 0.12 TEST_THAT(getblockindex->GetObjectID() == store1objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); // Check against uploaded file @@ -860,7 +991,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco } // and again, by name { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolClientListDirectory::RootDirectory, store1name)); +======= + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolListDirectory::RootDirectory, store1name)); +>>>>>>> 0.12 TEST_THAT(getblockindex->GetObjectID() == store1objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); // Check against uploaded file @@ -870,10 +1005,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Get the directory again, and see if the entry is in it { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -896,7 +1038,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco // Try using GetFile on a directory { +<<<<<<< HEAD TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::RootDirectory)), +======= + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> getFile(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, BackupProtocolListDirectory::RootDirectory)), +>>>>>>> 0.12 ConnectionException, Conn_Protocol_UnexpectedReply); } } @@ -919,6 +1065,7 @@ std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname, return conn; } +<<<<<<< HEAD std::auto_ptr<BackupProtocolClient> test_server_login(SocketStreamTLS& rConn) { // Make a protocol @@ -927,11 +1074,28 @@ std::auto_ptr<BackupProtocolClient> test_server_login(SocketStreamTLS& rConn) // Check the version std::auto_ptr<BackupProtocolClientVersion> serverVersion( +======= +std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname, + TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn) +{ + rapConn = open_conn(hostname, rContext); + + // Make a protocol + std::auto_ptr<BackupProtocolClient> protocol(new + BackupProtocolClient(*rapConn)); + + // Check the version + std::auto_ptr<BackupProtocolVersion> serverVersion( +>>>>>>> 0.12 protocol->QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf( +======= + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf( +>>>>>>> 0.12 protocol->QueryLogin(0x01234567, 0)); return protocol; @@ -948,6 +1112,7 @@ void run_housekeeping(BackupStoreAccountDatabase::Entry& rAccount) housekeeping.DoHousekeeping(true /* keep trying forever */); } +<<<<<<< HEAD int test_server(const char *hostname) { TLSContext context; @@ -955,6 +1120,37 @@ int test_server(const char *hostname) std::auto_ptr<BackupProtocolClient> apProtocol( test_server_login(*conn)); BackupProtocolClient& protocol(*apProtocol); +======= +// Run housekeeping (for which we need to disconnect ourselves) and check +// that it doesn't change the numbers of files. +// +// Also check that bbstoreaccounts doesn't change anything + +void run_housekeeping_and_check_account(const char *hostname, + TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn, + std::auto_ptr<BackupProtocolClient>& rapProtocol) +{ + rapProtocol->QueryFinished(); + std::auto_ptr<BackupStoreAccountDatabase> apAccounts( + BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); + BackupStoreAccountDatabase::Entry account = + apAccounts->GetEntry(0x1234567); + run_housekeeping(account); + + TEST_THAT(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf check 01234567 fix") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + rapProtocol = test_server_login(hostname, rContext, rapConn); +} + +int test_server(const char *hostname) +{ + TLSContext context; + std::auto_ptr<SocketStreamTLS> conn; + std::auto_ptr<BackupProtocolClient> apProtocol = + test_server_login(hostname, context, conn); +>>>>>>> 0.12 // Make some test attributes #define ATTR1_SIZE 245 @@ -975,7 +1171,11 @@ int test_server(const char *hostname) // Get it logging FILE *protocolLog = ::fopen("testfiles/protocol.log", "w"); TEST_THAT(protocolLog != 0); +<<<<<<< HEAD protocol.SetLogToFile(protocolLog); +======= + apProtocol->SetLogToFile(protocolLog); +>>>>>>> 0.12 #ifndef WIN32 // Check that we can't open a new connection which requests write permissions @@ -984,16 +1184,26 @@ int test_server(const char *hostname) conn.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED_TEST); BackupProtocolClient protocol(conn); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), +======= + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), +>>>>>>> 0.12 ConnectionException, Conn_Protocol_UnexpectedReply); protocol.QueryFinished(); } #endif // Set the client store marker +<<<<<<< HEAD protocol.QuerySetClientStoreMarker(0x8732523ab23aLL); +======= + apProtocol->QuerySetClientStoreMarker(0x8732523ab23aLL); +>>>>>>> 0.12 #ifndef WIN32 // Open a new connection which is read only @@ -1008,18 +1218,51 @@ int test_server(const char *hostname) protocolReadOnly.SetLogToFile(protocolReadOnlyLog); { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly)); +======= + std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); +>>>>>>> 0.12 // Check client store marker TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL); } #else // WIN32 +<<<<<<< HEAD BackupProtocolClient& protocolReadOnly(protocol); #endif test_server_1(protocol, protocolReadOnly); +======= + #define protocolReadOnly (*apProtocol) +#endif + + test_server_1(*apProtocol, protocolReadOnly); + + #define TEST_NUM_FILES(files, old, deleted, dirs) \ + { \ + std::auto_ptr<BackupStoreInfo> apInfo = \ + BackupStoreInfo::Load(0x1234567, \ + "backup/01234567/", 0, true); \ + TEST_EQUAL_LINE(files, apInfo->GetNumFiles(), \ + "num files"); \ + TEST_EQUAL_LINE(old, apInfo->GetNumOldFiles(), \ + "old files"); \ + TEST_EQUAL_LINE(deleted, apInfo->GetNumDeletedFiles(), \ + "deleted files"); \ + TEST_EQUAL_LINE(dirs, apInfo->GetNumDirectories(), \ + "directories"); \ + } + + TEST_NUM_FILES(1, 0, 0, 1); + run_housekeeping_and_check_account(hostname, context, + conn, apProtocol); + TEST_NUM_FILES(1, 0, 0, 1); +>>>>>>> 0.12 // sleep to ensure that the timestamp on the file will change ::safe_sleep(1); @@ -1033,6 +1276,7 @@ int test_server(const char *hostname) std::string filename("testfiles/test"); filename += uploads[t].fnextra; int64_t modtime = 0; +<<<<<<< HEAD std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolClientListDirectory::RootDirectory, uploads[t].name, &modtime)); TEST_THAT(modtime != 0); @@ -1042,6 +1286,17 @@ int test_server(const char *hostname) modtime, modtime, /* use it for attr hash too */ 0, /* diff from ID */ +======= + + std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolListDirectory::RootDirectory, uploads[t].name, &modtime)); + TEST_THAT(modtime != 0); + + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, + modtime, + modtime, /* use it for attr hash too */ + 0, /* diff from ID */ +>>>>>>> 0.12 uploads[t].name, *upload)); uploads[t].allocated_objid = stored->GetObjectID(); @@ -1051,31 +1306,61 @@ int test_server(const char *hostname) BOX_TRACE("wrote file " << filename << " to server " "as object " << BOX_FORMAT_OBJECTID(stored->GetObjectID())); +<<<<<<< HEAD +======= + TEST_NUM_FILES(t + 2, 0, 0, 1); + + run_housekeeping_and_check_account(hostname, context, + conn, apProtocol); + TEST_NUM_FILES(t + 2, 0, 0, 1); +>>>>>>> 0.12 } // Add some attributes onto one of them { +<<<<<<< HEAD MemBlockStream attrnew(attr3, sizeof(attr3)); std::auto_ptr<BackupProtocolClientSuccess> set(protocol.QuerySetReplacementFileAttributes( BackupProtocolClientListDirectory::RootDirectory, +======= + TEST_NUM_FILES(UPLOAD_NUM + 1, 0, 0, 1); + MemBlockStream attrnew(attr3, sizeof(attr3)); + std::auto_ptr<BackupProtocolSuccess> set(apProtocol->QuerySetReplacementFileAttributes( + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 32498749832475LL, uploads[UPLOAD_ATTRS_EN].name, attrnew)); TEST_THAT(set->GetObjectID() == uploads[UPLOAD_ATTRS_EN].allocated_objid); +<<<<<<< HEAD +======= + TEST_NUM_FILES(UPLOAD_NUM + 1, 0, 0, 1); +>>>>>>> 0.12 } // Delete one of them (will implicitly delete an old version) { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> del(protocol.QueryDeleteFile( BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); } +======= + std::auto_ptr<BackupProtocolSuccess> del(apProtocol->QueryDeleteFile( + BackupProtocolListDirectory::RootDirectory, + uploads[UPLOAD_DELETE_EN].name)); + TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); + TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1); + } + +>>>>>>> 0.12 // Check that the block index can be obtained by name even though it's been deleted { // Fetch the raw object { FileStream out("testfiles/downloaddelobj", O_WRONLY | O_CREAT); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid)); std::auto_ptr<IOStream> objstream(protocol.ReceiveStream()); objstream->CopyStreamTo(out); @@ -1085,6 +1370,17 @@ int test_server(const char *hostname) BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); +======= + std::auto_ptr<BackupProtocolSuccess> getobj(apProtocol->QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid)); + std::auto_ptr<IOStream> objstream(apProtocol->ReceiveStream()); + objstream->CopyStreamTo(out); + } + // query index and test + std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name)); + TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid); + std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream()); +>>>>>>> 0.12 TEST_THAT(check_block_index("testfiles/downloaddelobj", *blockIndexStream)); } @@ -1092,9 +1388,15 @@ int test_server(const char *hostname) for(int t = 0; t < UPLOAD_NUM; ++t) { printf("%d\n", t); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, uploads[t].allocated_objid)); TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid); std::auto_ptr<IOStream> filestream(protocol.ReceiveStream()); +======= + std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, uploads[t].allocated_objid)); + TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid); + std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream()); +>>>>>>> 0.12 test_test_file(t, *filestream); } @@ -1106,7 +1408,11 @@ int test_server(const char *hostname) check_dir_after_uploads(protocolReadOnly, attrtest); printf("done.\n\n"); // And on the read/write one +<<<<<<< HEAD check_dir_after_uploads(protocol, attrtest); +======= + check_dir_after_uploads(*apProtocol, attrtest); +>>>>>>> 0.12 } // sleep to ensure that the timestamp on the file will change @@ -1128,12 +1434,43 @@ int test_server(const char *hostname) out.Write(buf, TEST_FILE_FOR_PATCHING_SIZE - TEST_FILE_FOR_PATCHING_PATCH_AT); ::free(buf); } +<<<<<<< HEAD { // Fetch the block index for this one std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByName( BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name)); TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); +======= + + TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1); + + // Run housekeeping (for which we need to disconnect + // ourselves) and check that it doesn't change the numbers + // of files + apProtocol->QueryFinished(); + std::auto_ptr<BackupStoreAccountDatabase> apAccounts( + BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); + BackupStoreAccountDatabase::Entry account = + apAccounts->GetEntry(0x1234567); + run_housekeeping(account); + + // Also check that bbstoreaccounts doesn't change anything + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf check 01234567 fix") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + apProtocol = test_server_login(hostname, context, conn); + + TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1); + + { + // Fetch the block index for this one + std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name)); + TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid); + std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream()); +>>>>>>> 0.12 // Do the patching bool isCompletelyDifferent = false; @@ -1141,7 +1478,11 @@ int test_server(const char *hostname) std::auto_ptr<IOStream> patchstream( BackupStoreFile::EncodeFileDiff( TEST_FILE_FOR_PATCHING ".mod", +<<<<<<< HEAD BackupProtocolClientListDirectory::RootDirectory, +======= + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 uploads[UPLOAD_PATCH_EN].name, uploads[UPLOAD_PATCH_EN].allocated_objid, *blockIndexStream, @@ -1160,8 +1501,13 @@ int test_server(const char *hostname) int64_t patchedID = 0; { FileStream uploadpatch(TEST_FILE_FOR_PATCHING ".patch"); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( BackupProtocolClientListDirectory::RootDirectory, +======= + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 modtime, modtime, /* use it for attr hash too */ uploads[UPLOAD_PATCH_EN].allocated_objid, /* diff from ID */ @@ -1175,12 +1521,23 @@ int test_server(const char *hostname) set_refcount(patchedID, 1); // Then download it to check it's OK +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, patchedID)); TEST_THAT(getFile->GetObjectID() == patchedID); std::auto_ptr<IOStream> filestream(protocol.ReceiveStream()); BackupStoreFile::DecodeFile(*filestream, TEST_FILE_FOR_PATCHING ".downloaded", IOStream::TimeOutInfinite); // Check it's the same TEST_THAT(check_files_same(TEST_FILE_FOR_PATCHING ".downloaded", TEST_FILE_FOR_PATCHING ".mod")); +======= + std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, patchedID)); + TEST_THAT(getFile->GetObjectID() == patchedID); + std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream()); + BackupStoreFile::DecodeFile(*filestream, TEST_FILE_FOR_PATCHING ".downloaded", IOStream::TimeOutInfinite); + // Check it's the same + TEST_THAT(check_files_same(TEST_FILE_FOR_PATCHING ".downloaded", TEST_FILE_FOR_PATCHING ".mod")); + + TEST_NUM_FILES(UPLOAD_NUM, 1, 1, 1); +>>>>>>> 0.12 } // Create a directory @@ -1189,11 +1546,21 @@ int test_server(const char *hostname) { // Attributes MemBlockStream attr(attr1, sizeof(attr1)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory( BackupProtocolClientListDirectory::RootDirectory, 9837429842987984LL, dirname, attr)); subdirid = dirCreate->GetObjectID(); TEST_THAT(subdirid == maxID + 1); +======= + std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory( + BackupProtocolListDirectory::RootDirectory, + 9837429842987984LL, dirname, attr)); + subdirid = dirCreate->GetObjectID(); + TEST_THAT(subdirid == maxID + 1); + + TEST_NUM_FILES(UPLOAD_NUM, 1, 1, 2); +>>>>>>> 0.12 } set_refcount(subdirid, 1); @@ -1205,7 +1572,11 @@ int test_server(const char *hostname) int64_t modtime; std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), subdirid, uploads[0].name, &modtime)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( +======= + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( +>>>>>>> 0.12 subdirid, modtime, modtime, /* use for attr hash too */ @@ -1213,6 +1584,11 @@ int test_server(const char *hostname) uploads[0].name, *upload)); subdirfileid = stored->GetObjectID(); +<<<<<<< HEAD +======= + + TEST_NUM_FILES(UPLOAD_NUM + 1, 1, 1, 2); +>>>>>>> 0.12 } set_refcount(subdirfileid, 1); @@ -1221,10 +1597,17 @@ int test_server(const char *hostname) // Check the directories on the read only connection { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream +>>>>>>> 0.12 BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite); @@ -1246,17 +1629,28 @@ int test_server(const char *hostname) } // Does it look right? TEST_THAT(en->GetName() == dirname); +<<<<<<< HEAD TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir); +======= + TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_Dir); +>>>>>>> 0.12 TEST_THAT(en->GetObjectID() == subdirid); TEST_THAT(en->GetModificationTime() == 0); // dirs don't have modification times. } { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + subdirid, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */)); +>>>>>>> 0.12 TEST_THAT(dirreply->GetObjectID() == subdirid); // Stream BackupStoreDirectory dir; @@ -1271,7 +1665,11 @@ int test_server(const char *hostname) TEST_THAT(en != 0); // Does it look right? TEST_THAT(en->GetName() == uploads[0].name); +<<<<<<< HEAD TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_File); +======= + TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_File); +>>>>>>> 0.12 TEST_THAT(en->GetObjectID() == subdirfileid); TEST_THAT(en->GetModificationTime() != 0); @@ -1286,10 +1684,17 @@ int test_server(const char *hostname) // Check that we don't get attributes if we don't ask for them { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + subdirid, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1303,7 +1708,11 @@ int test_server(const char *hostname) // Change attributes on the directory { MemBlockStream attrnew(attr2, sizeof(attr2)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> changereply(protocol.QueryChangeDirAttributes( +======= + std::auto_ptr<BackupProtocolSuccess> changereply(apProtocol->QueryChangeDirAttributes( +>>>>>>> 0.12 subdirid, 329483209443598LL, attrnew)); @@ -1312,10 +1721,17 @@ int test_server(const char *hostname) // Check the new attributes { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, 0, // no flags BackupProtocolClientListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + subdirid, + 0, // no flags + BackupProtocolListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1336,15 +1752,22 @@ int test_server(const char *hostname) { BackupStoreFilenameClear newName("moved-files"); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> rep(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, BackupProtocolClientListDirectory::RootDirectory, subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName)); +======= + std::auto_ptr<BackupProtocolSuccess> rep(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, + BackupProtocolListDirectory::RootDirectory, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName)); +>>>>>>> 0.12 TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid); } // Try some dodgy renames { BackupStoreFilenameClear newName("moved-files"); +<<<<<<< HEAD TEST_CHECK_THROWS(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, BackupProtocolClientListDirectory::RootDirectory, subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName), @@ -1352,24 +1775,46 @@ int test_server(const char *hostname) TEST_CHECK_THROWS(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, subdirid, subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName), +======= + TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, + BackupProtocolListDirectory::RootDirectory, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName), + ConnectionException, Conn_Protocol_UnexpectedReply); + TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, + subdirid, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName), +>>>>>>> 0.12 ConnectionException, Conn_Protocol_UnexpectedReply); } // Rename within a directory { BackupStoreFilenameClear newName("moved-files-x"); +<<<<<<< HEAD protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, subdirid, subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName); +======= + apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid, + subdirid, + subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName); +>>>>>>> 0.12 } // Check it's all gone from the root directory... { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1388,10 +1833,17 @@ int test_server(const char *hostname) BackupStoreFilenameClear lookFor("moved-files-x"); // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( subdirid, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + subdirid, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1423,14 +1875,22 @@ int test_server(const char *hostname) BackupStoreFilenameClear nd("sub2"); // Attributes MemBlockStream attr(attr1, sizeof(attr1)); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory( +======= + std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory( +>>>>>>> 0.12 subdirid, 9837429842987984LL, nd, attr)); subsubdirid = dirCreate->GetObjectID(); FileStream upload("testfiles/file1_upload1"); BackupStoreFilenameClear nf("file2"); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( +======= + std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile( +>>>>>>> 0.12 subsubdirid, 0x123456789abcdefLL, /* modification time */ 0x7362383249872dfLL, /* attr hash */ @@ -1445,6 +1905,7 @@ int test_server(const char *hostname) // Query names -- test that invalid stuff returns not found OK { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(3248972347823478927LL, subsubdirid)); TEST_THAT(nameRep->GetNumNameElements() == 0); } @@ -1458,16 +1919,39 @@ int test_server(const char *hostname) } { std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL)); +======= + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(3248972347823478927LL, subsubdirid)); + TEST_THAT(nameRep->GetNumNameElements() == 0); + } + { + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, 2342378424LL)); + TEST_THAT(nameRep->GetNumNameElements() == 0); + } + { + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(38947234789LL, 2342378424LL)); + TEST_THAT(nameRep->GetNumNameElements() == 0); + } + { + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL)); +>>>>>>> 0.12 TEST_THAT(nameRep->GetNumNameElements() == 0); } // Query names... first, get info for the file { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(subsubfileid, subsubdirid)); std::auto_ptr<IOStream> namestream(protocol.ReceiveStream()); TEST_THAT(nameRep->GetNumNameElements() == 3); TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_File); +======= + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, subsubdirid)); + std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream()); + + TEST_THAT(nameRep->GetNumNameElements() == 3); + TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_File); +>>>>>>> 0.12 TEST_THAT(nameRep->GetModificationTime() == 0x123456789abcdefLL); TEST_THAT(nameRep->GetAttributesHash() == 0x7362383249872dfLL); static const char *testnames[] = {"file2","sub2","lovely_directory"}; @@ -1481,11 +1965,19 @@ int test_server(const char *hostname) // Query names... secondly, for the directory { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, subsubdirid)); std::auto_ptr<IOStream> namestream(protocol.ReceiveStream()); TEST_THAT(nameRep->GetNumNameElements() == 2); TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir); +======= + std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, subsubdirid)); + std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream()); + + TEST_THAT(nameRep->GetNumNameElements() == 2); + TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_Dir); +>>>>>>> 0.12 static const char *testnames[] = {"sub2","lovely_directory"}; for(int l = 0; l < nameRep->GetNumNameElements(); ++l) { @@ -1497,21 +1989,33 @@ int test_server(const char *hostname) //} skip: +<<<<<<< HEAD std::auto_ptr<BackupStoreAccountDatabase> apAccounts( BackupStoreAccountDatabase::Read( "testfiles/accounts.txt")); +======= +>>>>>>> 0.12 std::auto_ptr<BackupStoreRefCountDatabase> apRefCount( BackupStoreRefCountDatabase::Load( apAccounts->GetEntry(0x1234567), true)); // Create some nice recursive directories +<<<<<<< HEAD int64_t dirtodelete = create_test_data_subdirs(protocol, BackupProtocolClientListDirectory::RootDirectory, +======= + int64_t dirtodelete = create_test_data_subdirs(*apProtocol, + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 "test_delete", 6 /* depth */, *apRefCount); // And delete them { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirdel(protocol.QueryDeleteDirectory( +======= + std::auto_ptr<BackupProtocolSuccess> dirdel(apProtocol->QueryDeleteDirectory( +>>>>>>> 0.12 dirtodelete)); TEST_THAT(dirdel->GetObjectID() == dirtodelete); } @@ -1519,10 +2023,17 @@ int test_server(const char *hostname) // Get the root dir, checking for deleted items { // Command +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_Dir | BackupProtocolClientListDirectory::Flags_Deleted, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_Dir | BackupProtocolListDirectory::Flags_Deleted, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream()); @@ -1549,7 +2060,11 @@ int test_server(const char *hostname) #ifndef WIN32 protocolReadOnly.QueryFinished(); #endif +<<<<<<< HEAD protocol.QueryFinished(); +======= + apProtocol->QueryFinished(); +>>>>>>> 0.12 // Close logs #ifndef WIN32 @@ -1742,6 +2257,10 @@ int test3(int argc, const char *argv[]) TEST_CHECK_THROWS(info->ChangeBlocksInDeletedFiles(1), BackupStoreException, StoreInfoIsReadOnly); TEST_CHECK_THROWS(info->RemovedDeletedDirectory(2), BackupStoreException, StoreInfoIsReadOnly); TEST_CHECK_THROWS(info->AddDeletedDirectory(2), BackupStoreException, StoreInfoIsReadOnly); +<<<<<<< HEAD +======= + TEST_CHECK_THROWS(info->SetAccountName("hello"), BackupStoreException, StoreInfoIsReadOnly); +>>>>>>> 0.12 } { std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, false)); @@ -1758,6 +2277,10 @@ int test3(int argc, const char *argv[]) info->AddDeletedDirectory(3); info->AddDeletedDirectory(4); info->RemovedDeletedDirectory(3); +<<<<<<< HEAD +======= + info->SetAccountName("whee"); +>>>>>>> 0.12 TEST_CHECK_THROWS(info->RemovedDeletedDirectory(9), BackupStoreException, StoreInfoDirNotInList); info->Save(); } @@ -1768,6 +2291,10 @@ int test3(int argc, const char *argv[]) TEST_THAT(info->GetBlocksInDeletedFiles() == 1); TEST_THAT(info->GetBlocksSoftLimit() == 3461231233455433LL); TEST_THAT(info->GetBlocksHardLimit() == 2934852487LL); +<<<<<<< HEAD +======= + TEST_THAT(info->GetAccountName() == "whee"); +>>>>>>> 0.12 const std::vector<int64_t> &delfiles(info->GetDeletedDirectories()); TEST_THAT(delfiles.size() == 2); TEST_THAT(delfiles[0] == 2); @@ -1791,6 +2318,7 @@ int test3(int argc, const char *argv[]) int pid = LaunchServer(cmd.c_str(), "testfiles/bbstored.pid"); TEST_THAT(pid != -1 && pid != 0); +<<<<<<< HEAD if(pid > 0) { ::sleep(1); @@ -2021,6 +2549,276 @@ int test3(int argc, const char *argv[]) TestRemoteProcessMemLeaks("bbstored.memleaks"); #endif } +======= + if(pid <= 0) + { + return 1; + } + + ::sleep(1); + TEST_THAT(ServerIsAlive(pid)); + + // BLOCK + { + // Open a connection to the server + SocketStreamTLS conn; + conn.Open(context, Socket::TypeINET, "localhost", + BOX_PORT_BBSTORED_TEST); + + // Make a protocol + BackupProtocolClient protocol(conn); + + // Check the version + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + + // Login + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)), + ConnectionException, Conn_Protocol_UnexpectedReply); + + // Finish the connection + protocol.QueryFinished(); + } + + // Create an account for the test client + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf create 01234567 0 " + "10000B 20000B") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567")); + TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567")); + TEST_THAT(TestDirExists("testfiles/0_2/backup/01234567")); + TEST_THAT(TestGetFileSize("testfiles/accounts.txt") > 8); + // make sure something is written to it + + std::auto_ptr<BackupStoreAccountDatabase> apAccounts( + BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); + + std::auto_ptr<BackupStoreRefCountDatabase> apReferences( + BackupStoreRefCountDatabase::Load( + apAccounts->GetEntry(0x1234567), true)); + TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID, + apReferences->GetLastObjectIDUsed()); + TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID)) + apReferences.reset(); + + // Test that login fails on a disabled account + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf enabled 01234567 no") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + // BLOCK + { + // Open a connection to the server + SocketStreamTLS conn; + conn.Open(context, Socket::TypeINET, "localhost", + BOX_PORT_BBSTORED_TEST); + + // Make a protocol + BackupProtocolClient protocol(conn); + + // Check the version + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + + // Login + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> + loginConf(protocol.QueryLogin(0x01234567, 0)), + ConnectionException, Conn_Protocol_UnexpectedReply); + int type, subType; + TEST_EQUAL_LINE(true, protocol.GetLastError(type, subType), + "expected a protocol error"); + TEST_EQUAL_LINE(BackupProtocolError::ErrorType, type, + "expected a BackupProtocolError"); + TEST_EQUAL_LINE(BackupProtocolError::Err_DisabledAccount, subType, + "expected an Err_DisabledAccount"); + + // Finish the connection + protocol.QueryFinished(); + } + + // Re-enable the account so that subsequent logins should succeed + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf enabled 01234567 yes") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + // Delete the refcount database and log in again, + // check that it is recreated automatically but with + // no objects in it, to ensure seamless upgrade. + TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); + + std::auto_ptr<SocketStreamTLS> conn; + test_server_login("localhost", context, conn)->QueryFinished(); + + BackupStoreAccountDatabase::Entry account = + apAccounts->GetEntry(0x1234567); + apReferences = BackupStoreRefCountDatabase::Load(account, true); + TEST_EQUAL(0, apReferences->GetLastObjectIDUsed()); + + TEST_THAT(ServerIsAlive(pid)); + + run_housekeeping(account); + + // Check that housekeeping fixed the ref counts + TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID, + apReferences->GetLastObjectIDUsed()); + TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID)) + + TEST_THAT(ServerIsAlive(pid)); + + set_refcount(BACKUPSTORE_ROOT_DIRECTORY_ID, 1); + + TEST_THAT(test_server("localhost") == 0); + + // test that all object reference counts have the + // expected values + TEST_EQUAL(ExpectedRefCounts.size() - 1, + apReferences->GetLastObjectIDUsed()); + for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID; + i < ExpectedRefCounts.size(); i++) + { + TEST_EQUAL_LINE(ExpectedRefCounts[i], + apReferences->GetRefCount(i), + "object " << BOX_FORMAT_OBJECTID(i)); + } + + // Delete the refcount database again, and let + // housekeeping recreate it and fix the ref counts. + // This could also happen after upgrade, if a housekeeping + // runs before the user logs in. + apReferences.reset(); + TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); + run_housekeeping(account); + apReferences = BackupStoreRefCountDatabase::Load(account, true); + + TEST_EQUAL(ExpectedRefCounts.size() - 1, + apReferences->GetLastObjectIDUsed()); + for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID; + i < ExpectedRefCounts.size(); i++) + { + TEST_EQUAL_LINE(ExpectedRefCounts[i], + apReferences->GetRefCount(i), + "object " << BOX_FORMAT_OBJECTID(i)); + } + + // Test the deletion of objects by the housekeeping system + // First, things as they are now. + recursive_count_objects_results before = {0,0,0}; + + recursive_count_objects("localhost", BackupProtocolListDirectory::RootDirectory, before); + + TEST_THAT(before.objectsNotDel != 0); + TEST_THAT(before.deleted != 0); + TEST_THAT(before.old != 0); + + // Kill it + TEST_THAT(KillServer(pid)); + ::sleep(1); + TEST_THAT(!ServerIsAlive(pid)); + + #ifdef WIN32 + TEST_THAT(unlink("testfiles/bbstored.pid") == 0); + #else + TestRemoteProcessMemLeaks("bbstored.memleaks"); + #endif + + // Set a new limit on the account -- leave the hard limit + // high to make sure the target for freeing space is the + // soft limit. + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf setlimit 01234567 " + "10B 20000B") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + // Start things up + pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", + "testfiles/bbstored.pid"); + + ::sleep(1); + TEST_THAT(ServerIsAlive(pid)); + + // wait for housekeeping to happen + printf("waiting for housekeeping:\n"); + for(int l = 0; l < 30; ++l) + { + ::sleep(1); + printf("."); + fflush(stdout); + } + printf("\n"); + + // Count the objects again + recursive_count_objects_results after = {0,0,0}; + recursive_count_objects("localhost", + BackupProtocolListDirectory::RootDirectory, + after); + + // If these tests fail then try increasing the timeout above + TEST_THAT(after.objectsNotDel == before.objectsNotDel); + TEST_THAT(after.deleted == 0); + TEST_THAT(after.old == 0); + + // Set a really small hard limit + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf setlimit 01234567 " + "10B 20B") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + // Try to upload a file and create a directory, and check an error is generated + { + // Open a connection to the server + SocketStreamTLS conn; + conn.Open(context, Socket::TypeINET, "localhost", + BOX_PORT_BBSTORED_TEST); + + // Make a protocol + BackupProtocolClient protocol(conn); + + // Check the version + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); + TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + + // Login + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)); + + int64_t modtime = 0; + + BackupStoreFilenameClear fnx("exceed-limit"); + std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/test3", BackupProtocolListDirectory::RootDirectory, fnx, &modtime)); + TEST_THAT(modtime != 0); + + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, + modtime, + modtime, /* use it for attr hash too */ + 0, /* diff from ID */ + fnx, + *upload)), + ConnectionException, Conn_Protocol_UnexpectedReply); + + MemBlockStream attr(&modtime, sizeof(modtime)); + BackupStoreFilenameClear fnxd("exceed-limit-dir"); + TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory( + BackupProtocolListDirectory::RootDirectory, + 9837429842987984LL, fnxd, attr)), + ConnectionException, Conn_Protocol_UnexpectedReply); + + + // Finish the connection + protocol.QueryFinished(); + } + + // Kill it again + TEST_THAT(KillServer(pid)); + ::sleep(1); + TEST_THAT(!ServerIsAlive(pid)); + + #ifdef WIN32 + TEST_THAT(unlink("testfiles/bbstored.pid") == 0); + #else + TestRemoteProcessMemLeaks("bbstored.memleaks"); + #endif +>>>>>>> 0.12 return 0; } @@ -2068,25 +2866,36 @@ int multi_server() return 0; } +<<<<<<< HEAD #ifdef WIN32 WCHAR* ConvertUtf8ToWideString(const char* pString); std::string ConvertPathToAbsoluteUnicode(const char *pFileName); #endif int test(int argc, const char *argv[]) +======= +void test_open_files_with_limited_win32_permissions() +>>>>>>> 0.12 { #ifdef WIN32 // this had better work, or bbstored will die when combining diffs char* file = "foo"; +<<<<<<< HEAD std::string abs = ConvertPathToAbsoluteUnicode(file); WCHAR* wfile = ConvertUtf8ToWideString(abs.c_str()); +======= +>>>>>>> 0.12 DWORD accessRights = FILE_READ_ATTRIBUTES | FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | FILE_WRITE_EA /*| FILE_ALL_ACCESS*/; DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; +<<<<<<< HEAD HANDLE h1 = CreateFileW(wfile, accessRights, shareMode, +======= + HANDLE h1 = CreateFileA(file, accessRights, shareMode, +>>>>>>> 0.12 NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); assert(h1 != INVALID_HANDLE_VALUE); TEST_THAT(h1 != INVALID_HANDLE_VALUE); @@ -2094,23 +2903,328 @@ int test(int argc, const char *argv[]) accessRights = FILE_READ_ATTRIBUTES | FILE_LIST_DIRECTORY | FILE_READ_EA; +<<<<<<< HEAD HANDLE h2 = CreateFileW(wfile, accessRights, shareMode, +======= + HANDLE h2 = CreateFileA(file, accessRights, shareMode, +>>>>>>> 0.12 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); assert(h2 != INVALID_HANDLE_VALUE); TEST_THAT(h2 != INVALID_HANDLE_VALUE); CloseHandle(h2); CloseHandle(h1); +<<<<<<< HEAD delete [] wfile; h1 = openfile("foo", O_CREAT | O_RDWR, 0); TEST_THAT(h1 != INVALID_HANDLE_VALUE); h2 = openfile("foo", O_RDWR, 0); +======= + + h1 = openfile(file, O_CREAT | O_RDWR, 0); + TEST_THAT(h1 != INVALID_HANDLE_VALUE); + h2 = openfile(file, O_RDWR, 0); +>>>>>>> 0.12 TEST_THAT(h2 != INVALID_HANDLE_VALUE); CloseHandle(h2); CloseHandle(h1); #endif +<<<<<<< HEAD + +======= +} + +void compare_backupstoreinfo_values_to_expected +( + const std::string& test_phase, + const info_StreamFormat_1& expected, + const BackupStoreInfo& actual, + const std::string& expected_account_name, + bool expected_account_enabled, + const MemBlockStream& extra_data = MemBlockStream(/* empty */) +) +{ + TEST_EQUAL_LINE(ntohl(expected.mAccountID), actual.GetAccountID(), + test_phase << " AccountID"); + #define TEST_INFO_EQUAL(property) \ + TEST_EQUAL_LINE(box_ntoh64(expected.m ## property), \ + actual.Get ## property (), test_phase << " " #property) + TEST_INFO_EQUAL(ClientStoreMarker); + TEST_INFO_EQUAL(LastObjectIDUsed); + TEST_INFO_EQUAL(BlocksUsed); + TEST_INFO_EQUAL(BlocksInOldFiles); + TEST_INFO_EQUAL(BlocksInDeletedFiles); + TEST_INFO_EQUAL(BlocksInDirectories); + TEST_INFO_EQUAL(BlocksSoftLimit); + TEST_INFO_EQUAL(BlocksHardLimit); + #undef TEST_INFO_EQUAL + + // These attributes of the v2 structure are not supported by v1, + // so they should all be initialised to 0 + TEST_EQUAL_LINE(0, actual.GetBlocksInCurrentFiles(), + test_phase << " BlocksInCurrentFiles"); + TEST_EQUAL_LINE(0, actual.GetNumOldFiles(), + test_phase << " NumOldFiles"); + TEST_EQUAL_LINE(0, actual.GetNumDeletedFiles(), + test_phase << " NumDeletedFiles"); + TEST_EQUAL_LINE(0, actual.GetNumDirectories(), + test_phase << " NumDirectories"); + + // These attributes of the old v1 structure are not actually loaded + // or used: + // TEST_INFO_EQUAL(CurrentMarkNumber); + // TEST_INFO_EQUAL(OptionsPresent); + + TEST_EQUAL_LINE(box_ntoh64(expected.mNumberDeletedDirectories), + actual.GetDeletedDirectories().size(), + test_phase << " number of deleted directories"); + + for (size_t i = 0; i < box_ntoh64(expected.mNumberDeletedDirectories) && + i < actual.GetDeletedDirectories().size(); i++) + { + TEST_EQUAL_LINE(13 + i, actual.GetDeletedDirectories()[i], + test_phase << " deleted directory " << (i+1)); + } + + TEST_EQUAL_LINE(expected_account_name, actual.GetAccountName(), + test_phase << " AccountName"); + TEST_EQUAL_LINE(expected_account_enabled, actual.IsAccountEnabled(), + test_phase << " AccountEnabled"); + + TEST_EQUAL_LINE(extra_data.GetSize(), actual.GetExtraData().GetSize(), + test_phase << " extra data has wrong size"); + TEST_EQUAL_LINE(0, memcmp(extra_data.GetBuffer(), + actual.GetExtraData().GetBuffer(), extra_data.GetSize()), + test_phase << " extra data has wrong contents"); +} + +int test_read_old_backupstoreinfo_files() +{ + // Create an account for the test client + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf create 01234567 0 " + "10000B 20000B") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + std::auto_ptr<BackupStoreInfo> apInfo = BackupStoreInfo::Load(0x1234567, + "backup/01234567/", 0, /* ReadOnly */ false); + TEST_EQUAL_LINE(true, apInfo->IsAccountEnabled(), + "'bbstoreaccounts create' should have set AccountEnabled flag"); + + info_StreamFormat_1 info_v1; + info_v1.mMagicValue = htonl(INFO_MAGIC_VALUE_1); + info_v1.mAccountID = htonl(0x01234567); + info_v1.mClientStoreMarker = box_hton64(3); + info_v1.mLastObjectIDUsed = box_hton64(4); + info_v1.mBlocksUsed = box_hton64(5); + info_v1.mBlocksInOldFiles = box_hton64(6); + info_v1.mBlocksInDeletedFiles = box_hton64(7); + info_v1.mBlocksInDirectories = box_hton64(8); + info_v1.mBlocksSoftLimit = box_hton64(9); + info_v1.mBlocksHardLimit = box_hton64(10); + info_v1.mCurrentMarkNumber = htonl(11); + info_v1.mOptionsPresent = htonl(12); + info_v1.mNumberDeletedDirectories = box_hton64(2); + // Then mNumberDeletedDirectories * int64_t IDs for the deleted directories + + // Generate the filename + std::string info_filename("backup/01234567/" INFO_FILENAME); + std::auto_ptr<RaidFileWrite> rfw(new RaidFileWrite(0, info_filename)); + rfw->Open(/* AllowOverwrite = */ true); + rfw->Write(&info_v1, sizeof(info_v1)); + // Write mNumberDeletedDirectories * int64_t IDs for the deleted directories + std::auto_ptr<Archive> apArchive(new Archive(*rfw, IOStream::TimeOutInfinite)); + apArchive->Write((int64_t) 13); + apArchive->Write((int64_t) 14); + rfw->Commit(/* ConvertToRaidNow */ true); + rfw.reset(); + + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ false); + compare_backupstoreinfo_values_to_expected("loaded from v1", info_v1, + *apInfo, "" /* no name by default */, + true /* enabled by default */); + apInfo->SetAccountName("bonk"); + + // Save the info again + apInfo->Save(/* allowOverwrite */ true); + + // Check that it was saved in the new Archive format + std::auto_ptr<RaidFileRead> rfr(RaidFileRead::Open(0, info_filename, 0)); + int32_t magic; + if(!rfr->ReadFullBuffer(&magic, sizeof(magic), 0)) + { + THROW_FILE_ERROR("Failed to read store info file: " + "short read of magic number", info_filename, + BackupStoreException, CouldNotLoadStoreInfo); + } + TEST_EQUAL_LINE(INFO_MAGIC_VALUE_2, ntohl(magic), + "format version in newly saved BackupStoreInfo"); + rfr.reset(); + + // load it, and check that all values are loaded properly + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ false); + compare_backupstoreinfo_values_to_expected("loaded in v1, resaved in v2", + info_v1, *apInfo, "bonk", true); + + // Check that the new AccountEnabled flag is saved properly + apInfo->SetAccountEnabled(false); + apInfo->Save(/* allowOverwrite */ true); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ false); + compare_backupstoreinfo_values_to_expected("saved in v2, loaded in v2", + info_v1, *apInfo, "bonk", false /* as modified above */); + apInfo->SetAccountEnabled(true); + apInfo->Save(/* allowOverwrite */ true); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ true); + compare_backupstoreinfo_values_to_expected("resaved in v2 with " + "account enabled", info_v1, *apInfo, "bonk", + true /* as modified above */); + + // Now save the info in v2 format without the AccountEnabled flag + // (boxbackup 0.11 format) and check that the flag is set to true + // for backwards compatibility + + rfw.reset(new RaidFileWrite(0, info_filename)); + rfw->Open(/* allowOverwrite */ true); + magic = htonl(INFO_MAGIC_VALUE_2); + apArchive.reset(new Archive(*rfw, IOStream::TimeOutInfinite)); + rfw->Write(&magic, sizeof(magic)); + apArchive->Write(apInfo->GetAccountID()); + apArchive->Write(std::string("test")); + apArchive->Write(apInfo->GetClientStoreMarker()); + apArchive->Write(apInfo->GetLastObjectIDUsed()); + apArchive->Write(apInfo->GetBlocksUsed()); + apArchive->Write(apInfo->GetBlocksInCurrentFiles()); + apArchive->Write(apInfo->GetBlocksInOldFiles()); + apArchive->Write(apInfo->GetBlocksInDeletedFiles()); + apArchive->Write(apInfo->GetBlocksInDirectories()); + apArchive->Write(apInfo->GetBlocksSoftLimit()); + apArchive->Write(apInfo->GetBlocksHardLimit()); + apArchive->Write(apInfo->GetNumFiles()); + apArchive->Write(apInfo->GetNumOldFiles()); + apArchive->Write(apInfo->GetNumDeletedFiles()); + apArchive->Write(apInfo->GetNumDirectories()); + apArchive->Write((int64_t) apInfo->GetDeletedDirectories().size()); + apArchive->Write(apInfo->GetDeletedDirectories()[0]); + apArchive->Write(apInfo->GetDeletedDirectories()[1]); + rfw->Commit(/* ConvertToRaidNow */ true); + rfw.reset(); + + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ false); + compare_backupstoreinfo_values_to_expected("saved in v2 without " + "AccountEnabled", info_v1, *apInfo, "test", true); + // Default for missing AccountEnabled should be true + + // Rewrite using full length, so that the first 4 bytes of extra data + // doesn't get swallowed by "extra data". + apInfo->Save(/* allowOverwrite */ true); + + // Append some extra data after the known account values, to simulate a + // new addition to the store format. Check that this extra data is loaded + // and resaved with the info file. We made the mistake of deleting it in + // 0.11, let's not make the same mistake again. + CollectInBufferStream info_data; + rfr = RaidFileRead::Open(0, info_filename, 0); + rfr->CopyStreamTo(info_data); + rfr.reset(); + info_data.SetForReading(); + rfw.reset(new RaidFileWrite(0, info_filename)); + rfw->Open(/* allowOverwrite */ true); + info_data.CopyStreamTo(*rfw); + char extra_string[] = "hello!"; + MemBlockStream extra_data(extra_string, strlen(extra_string)); + extra_data.CopyStreamTo(*rfw); + rfw->Commit(/* ConvertToRaidNow */ true); + rfw.reset(); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, + /* ReadOnly */ false); + TEST_EQUAL_LINE(extra_data.GetSize(), apInfo->GetExtraData().GetSize(), + "wrong amount of extra data loaded from info file"); + TEST_EQUAL_LINE(0, memcmp(extra_data.GetBuffer(), + apInfo->GetExtraData().GetBuffer(), extra_data.GetSize()), + "extra data loaded from info file has wrong contents"); + // Save the file and load again, check that the extra data is still there + apInfo->Save(/* allowOverwrite */ true); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true); + compare_backupstoreinfo_values_to_expected("saved in future format " + "with extra_data", info_v1, *apInfo, "test", true, extra_data); + + // Check that the new bbstoreaccounts command sets the flag properly + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf enabled 01234567 no") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true); + TEST_EQUAL_LINE(false, apInfo->IsAccountEnabled(), + "'bbstoreaccounts disabled no' should have reset AccountEnabled flag"); + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf enabled 01234567 yes") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true); + TEST_EQUAL_LINE(true, apInfo->IsAccountEnabled(), + "'bbstoreaccounts disabled yes' should have set AccountEnabled flag"); + + // Check that BackupStoreInfo::CreateForRegeneration saves all the + // expected properties, including any extra data for forward + // compatibility + extra_data.Seek(0, IOStream::SeekType_Absolute); + apInfo = BackupStoreInfo::CreateForRegeneration( + apInfo->GetAccountID(), "spurtle" /* rAccountName */, + "backup/01234567/" /* rRootDir */, 0 /* DiscSet */, + apInfo->GetLastObjectIDUsed(), + apInfo->GetBlocksUsed(), + apInfo->GetBlocksInCurrentFiles(), + apInfo->GetBlocksInOldFiles(), + apInfo->GetBlocksInDeletedFiles(), + apInfo->GetBlocksInDirectories(), + apInfo->GetBlocksSoftLimit(), + apInfo->GetBlocksHardLimit(), + false /* AccountEnabled */, + extra_data); + // CreateForRegeneration always sets the ClientStoreMarker to 0 + info_v1.mClientStoreMarker = 0; + // CreateForRegeneration does not store any deleted directories + info_v1.mNumberDeletedDirectories = 0; + + // check that the store info has the correct values in memory + compare_backupstoreinfo_values_to_expected("stored by " + "BackupStoreInfo::CreateForRegeneration", info_v1, *apInfo, + "spurtle", false /* AccountEnabled */, extra_data); + // Save the file and load again, check that the extra data is still there + apInfo->Save(/* allowOverwrite */ true); + apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true); + compare_backupstoreinfo_values_to_expected("saved by " + "BackupStoreInfo::CreateForRegeneration and reloaded", info_v1, + *apInfo, "spurtle", false /* AccountEnabled */, extra_data); + + // Delete the account to leave the store in the same state as before + apInfo.reset(); + TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS + " -c testfiles/bbstored.conf delete 01234567 yes") == 0); + TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); + + return 0; +} + +int test(int argc, const char *argv[]) +{ + test_open_files_with_limited_win32_permissions(); + + // Initialise the raid file controller + RaidFileController &rcontroller = RaidFileController::GetController(); + rcontroller.Initialise("testfiles/raidfile.conf"); + + int ret = test_read_old_backupstoreinfo_files(); + if (ret != 0) + { + return ret; + } + +>>>>>>> 0.12 // SSL library SSLLib::Initialise(); @@ -2159,7 +3273,11 @@ int test(int argc, const char *argv[]) /* { int64_t modtime = 0; std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("/Users/ben/temp/large.tar", +<<<<<<< HEAD BackupProtocolClientListDirectory::RootDirectory, uploads[0].name, &modtime)); +======= + BackupProtocolListDirectory::RootDirectory, uploads[0].name, &modtime)); +>>>>>>> 0.12 TEST_THAT(modtime != 0); FileStream write("testfiles/large.enc", O_WRONLY | O_CREAT); upload->CopyStreamTo(write); diff --git a/test/backupstorefix/testbackupstorefix.cpp b/test/backupstorefix/testbackupstorefix.cpp index 2d4ce052..a93ffb8f 100644 --- a/test/backupstorefix/testbackupstorefix.cpp +++ b/test/backupstorefix/testbackupstorefix.cpp @@ -17,6 +17,7 @@ #include <map> #include "Test.h" +<<<<<<< HEAD #include "BackupStoreConstants.h" #include "BackupStoreDirectory.h" #include "BackupStoreFile.h" @@ -30,6 +31,28 @@ #include "StoreStructure.h" #include "BackupStoreFileWire.h" #include "ServerControl.h" +======= +#include "BackupClientCryptoKeys.h" +#include "BackupStoreCheck.h" +#include "BackupStoreConstants.h" +#include "BackupStoreContext.h" +#include "BackupStoreDirectory.h" +#include "BackupStoreException.h" +#include "BackupStoreFile.h" +#include "BackupStoreFileWire.h" +#include "BackupStoreFileEncodeStream.h" +#include "BackupStoreInfo.h" +#include "BufferedWriteStream.h" +#include "FileStream.h" +#include "RaidFileController.h" +#include "RaidFileException.h" +#include "RaidFileRead.h" +#include "RaidFileUtil.h" +#include "RaidFileWrite.h" +#include "ServerControl.h" +#include "StoreStructure.h" +#include "ZeroStream.h" +>>>>>>> 0.12 #include "MemLeakFindOn.h" @@ -69,6 +92,29 @@ std::map<int32_t, bool> objectIsDir; ::system(BBSTOREACCOUNTS " -c testfiles/bbstored.conf check 01234567"); \ ::system(BBSTOREACCOUNTS " -c testfiles/bbstored.conf check 01234567 fix"); +<<<<<<< HEAD +======= +bool check_fix_internal(int expected_num_errors) +{ + BackupStoreCheck checker(storeRoot, discSetNum, + 0x01234567, true /* FixErrors */, false /* Quiet */); + checker.Check(); + if (expected_num_errors == -1) + { + TEST_THAT(checker.ErrorsFound()); + return checker.ErrorsFound(); + } + else + { + TEST_EQUAL(expected_num_errors, checker.GetNumErrorsFound()); + return checker.GetNumErrorsFound() == expected_num_errors; + } +} + +#define RUN_CHECK_INTERNAL(expected_num_errors) \ + TEST_THAT(check_fix_internal(expected_num_errors)) + +>>>>>>> 0.12 // Get ID of an object given a filename int32_t getID(const char *name) { @@ -146,7 +192,13 @@ void check_dir(BackupStoreDirectory &dir, dir_en_check *ck) while((en = i.Next()) != 0) { +<<<<<<< HEAD TEST_THAT(ck->name != -1); +======= + BackupStoreFilenameClear clear(en->GetName()); + TEST_LINE(ck->name != -1, "Unexpected entry found in " + "directory: " << clear.GetClearFilename()); +>>>>>>> 0.12 if(ck->name == -1) { break; @@ -178,9 +230,18 @@ void check_dir_dep(BackupStoreDirectory &dir, checkdepinfoen *ck) { break; } +<<<<<<< HEAD TEST_THAT(en->GetObjectID() == ck->id); TEST_THAT(en->GetDependsNewer() == ck->depNewer); TEST_THAT(en->GetDependsOlder() == ck->depOlder); +======= + TEST_EQUAL_LINE(ck->id, en->GetObjectID(), "Wrong object ID " + "for " << BOX_FORMAT_OBJECTID(ck->id)); + TEST_EQUAL_LINE(ck->depNewer, en->GetDependsNewer(), + "Wrong Newer dependency for " << BOX_FORMAT_OBJECTID(ck->id)); + TEST_EQUAL_LINE(ck->depOlder, en->GetDependsOlder(), + "Wrong Older dependency for " << BOX_FORMAT_OBJECTID(ck->id)); +>>>>>>> 0.12 ++ck; } @@ -190,19 +251,50 @@ void check_dir_dep(BackupStoreDirectory &dir, checkdepinfoen *ck) void test_dir_fixing() { +<<<<<<< HEAD { MEMLEAKFINDER_NO_LEAKS; fnames[0].SetAsClearFilename("x1"); fnames[1].SetAsClearFilename("x2"); fnames[2].SetAsClearFilename("x3"); +======= + // Test that entries pointing to nonexistent entries are removed + { + BackupStoreDirectory dir; + BackupStoreDirectory::Entry* e = dir.AddEntry(fnames[0], 12, + 2 /* id */, 1, BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion, 2); + e->SetDependsNewer(3); + + TEST_THAT(dir.CheckAndFix() == true); + TEST_THAT(dir.CheckAndFix() == false); + + dir_en_check ck[] = { + {-1, 0, 0} + }; + + check_dir(dir, ck); +>>>>>>> 0.12 } { BackupStoreDirectory dir; +<<<<<<< HEAD dir.AddEntry(fnames[0], 12, 2 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); dir.AddEntry(fnames[1], 12, 2 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); dir.AddEntry(fnames[0], 12, 3 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); dir.AddEntry(fnames[0], 12, 5 /* id */, 1, BackupStoreDirectory::Entry::Flags_File | BackupStoreDirectory::Entry::Flags_OldVersion, 2); +======= + dir.AddEntry(fnames[0], 12, 2 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File, 2); + dir.AddEntry(fnames[1], 12, 2 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File, 2); + dir.AddEntry(fnames[0], 12, 3 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File, 2); + dir.AddEntry(fnames[0], 12, 5 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion, 2); +>>>>>>> 0.12 dir_en_check ck[] = { {1, 2, BackupStoreDirectory::Entry::Flags_File}, @@ -215,6 +307,10 @@ void test_dir_fixing() TEST_THAT(dir.CheckAndFix() == false); check_dir(dir, ck); } +<<<<<<< HEAD +======= + +>>>>>>> 0.12 { BackupStoreDirectory dir; dir.AddEntry(fnames[0], 12, 2 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); @@ -238,6 +334,7 @@ void test_dir_fixing() // Test dependency fixing { BackupStoreDirectory dir; +<<<<<<< HEAD BackupStoreDirectory::Entry *e2 = dir.AddEntry(fnames[0], 12, 2 /* id */, 1, BackupStoreDirectory::Entry::Flags_File | BackupStoreDirectory::Entry::Flags_OldVersion, 2); TEST_THAT(e2 != 0); @@ -252,6 +349,28 @@ void test_dir_fixing() e4->SetDependsNewer(5); e4->SetDependsOlder(3); BackupStoreDirectory::Entry *e5 = dir.AddEntry(fnames[0], 12, 5 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); +======= + BackupStoreDirectory::Entry *e2 = dir.AddEntry(fnames[0], 12, + 2 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion, 2); + TEST_THAT(e2 != 0); + e2->SetDependsNewer(3); + BackupStoreDirectory::Entry *e3 = dir.AddEntry(fnames[0], 12, + 3 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion, 2); + TEST_THAT(e3 != 0); + e3->SetDependsNewer(4); e3->SetDependsOlder(2); + BackupStoreDirectory::Entry *e4 = dir.AddEntry(fnames[0], 12, + 4 /* id */, 1, + BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion, 2); + TEST_THAT(e4 != 0); + e4->SetDependsNewer(5); e4->SetDependsOlder(3); + BackupStoreDirectory::Entry *e5 = dir.AddEntry(fnames[0], 12, + 5 /* id */, 1, BackupStoreDirectory::Entry::Flags_File, 2); +>>>>>>> 0.12 TEST_THAT(e5 != 0); e5->SetDependsOlder(4); @@ -281,14 +400,135 @@ void test_dir_fixing() } } +<<<<<<< HEAD int test(int argc, const char *argv[]) { // Test the backupstore directory fixing test_dir_fixing(); +======= +int64_t fake_upload(BackupProtocolLocal& client, const std::string& file_path, + int64_t diff_from_id) +{ + std::auto_ptr<IOStream> upload; + if(diff_from_id) + { + std::auto_ptr<BackupProtocolSuccess> getBlockIndex( + client.QueryGetBlockIndexByName( + BACKUPSTORE_ROOT_DIRECTORY_ID, fnames[0])); + std::auto_ptr<IOStream> blockIndexStream(client.ReceiveStream()); + upload = BackupStoreFile::EncodeFileDiff( + file_path, + BACKUPSTORE_ROOT_DIRECTORY_ID, fnames[0], + diff_from_id, *blockIndexStream, + IOStream::TimeOutInfinite, + NULL, // DiffTimer implementation + 0 /* not interested in the modification time */, + NULL // isCompletelyDifferent + ); + } + else + { + upload = BackupStoreFile::EncodeFile( + file_path, + BACKUPSTORE_ROOT_DIRECTORY_ID, fnames[0], + NULL, + NULL, // pLogger + NULL // pRunStatusProvider + ); + } + + return client.QueryStoreFile(BACKUPSTORE_ROOT_DIRECTORY_ID, + 1, // ModificationTime + 2, // AttributesHash + diff_from_id, // DiffFromFileID + fnames[0], // rFilename + upload)->GetObjectID(); +} + +void read_bb_dir(int64_t objectId, BackupStoreDirectory& dir) +{ + std::string fn; + StoreStructure::MakeObjectFilename(1 /* root */, storeRoot, + discSetNum, fn, true /* EnsureDirectoryExists */); + + std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, + fn)); + dir.ReadFromStream(*file, IOStream::TimeOutInfinite); +} + +void login_client_and_check_empty(BackupProtocolCallable& client) +{ + // Check that the initial situation matches our expectations. + BackupStoreDirectory dir; + read_bb_dir(1 /* root */, dir); + + dir_en_check start_entries[] = {{-1, 0, 0}}; + check_dir(dir, start_entries); + static checkdepinfoen start_deps[] = {{-1, 0, 0}}; + check_dir_dep(dir, start_deps); + + client.QueryVersion(BACKUP_STORE_SERVER_VERSION); + client.QueryLogin(0x01234567, 0 /* read/write */); + + read_bb_dir(1 /* root */, dir); + + // Everything should be OK at the moment + TEST_THAT(dir.CheckAndFix() == false); + + // Check that we've ended up with the right preconditions + // for the tests below. + dir_en_check before_entries[] = { + {-1, 0, 0} + }; + check_dir(dir, before_entries); + static checkdepinfoen before_deps[] = {{-1, 0, 0}}; + check_dir_dep(dir, before_deps); +} + +void check_root_dir_ok(dir_en_check after_entries[], + checkdepinfoen after_deps[]) +{ + // Check the store, check that the error is detected and + // repaired, by removing x1 from the directory. + RUN_CHECK_INTERNAL(0); + + // Read the directory back in, check that it's empty + BackupStoreDirectory dir; + read_bb_dir(1 /* root */, dir); + + check_dir(dir, after_entries); + check_dir_dep(dir, after_deps); +} + +void check_and_fix_root_dir(dir_en_check after_entries[], + checkdepinfoen after_deps[]) +{ + // Check the store, check that the error is detected and + // repaired. + RUN_CHECK_INTERNAL(-1); + check_root_dir_ok(after_entries, after_deps); +} + +int test(int argc, const char *argv[]) +{ + { + MEMLEAKFINDER_NO_LEAKS; + fnames[0].SetAsClearFilename("x1"); + fnames[1].SetAsClearFilename("x2"); + fnames[2].SetAsClearFilename("x3"); + } + + // Test the backupstore directory fixing + // FIXME reenable: test_dir_fixing(); +>>>>>>> 0.12 // Initialise the raidfile controller RaidFileController &rcontroller = RaidFileController::GetController(); rcontroller.Initialise("testfiles/raidfile.conf"); +<<<<<<< HEAD +======= + BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys"); +>>>>>>> 0.12 // Create an account TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS @@ -296,6 +536,7 @@ int test(int argc, const char *argv[]) "create 01234567 0 10000B 20000B") == 0); TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); +<<<<<<< HEAD // Start the bbstored server int pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", "testfiles/bbstored.pid"); @@ -608,6 +849,511 @@ int test(int argc, const char *argv[]) TestRemoteProcessMemLeaks("bbstored.memleaks"); #endif } +======= + // Run the perl script to create the initial directories + TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl init") == 0); + + BOX_INFO(" === Test that an entry pointing to a file that doesn't " + "exist is really deleted"); + + { + BackupStoreContext ctx(0x01234567, + *(HousekeepingInterface *)NULL, + "test" /* rConnectionDetails */); + ctx.SetClientHasAccount(storeRoot, discSetNum); + BackupProtocolLocal client(ctx); + login_client_and_check_empty(client); + + std::string file_path = "testfiles/TestDir1/cannes/ict/metegoguered/oats"; + int x1id = fake_upload(client, file_path, 0); + + // Now break the reverse dependency by deleting x1 (the file, + // not the directory entry) + std::string x1FileName; + StoreStructure::MakeObjectFilename(x1id, storeRoot, discSetNum, + x1FileName, true /* EnsureDirectoryExists */); + RaidFileWrite deleteX1(discSetNum, x1FileName); + deleteX1.Delete(); + + dir_en_check after_entries[] = {{-1, 0, 0}}; + static checkdepinfoen after_deps[] = {{-1, 0, 0}}; + check_and_fix_root_dir(after_entries, after_deps); + } + + BOX_INFO(" === Test that an entry pointing to another that doesn't " + "exist is really deleted"); + + { + BackupStoreContext ctx(0x01234567, + *(HousekeepingInterface *)NULL, + "test" /* rConnectionDetails */); + ctx.SetClientHasAccount(storeRoot, discSetNum); + BackupProtocolLocal client(ctx); + login_client_and_check_empty(client); + + std::string file_path = "testfiles/TestDir1/cannes/ict/metegoguered/oats"; + int x1id = fake_upload(client, file_path, 0); + + // Make a small change to the file + FileStream fs(file_path, O_WRONLY | O_APPEND); + const char* more = " and more oats!"; + fs.Write(more, strlen(more)); + fs.Close(); + + int x1aid = fake_upload(client, file_path, x1id); + + // Check that we've ended up with the right preconditions + // for the tests below. + dir_en_check before_entries[] = { + {0, x1id, BackupStoreDirectory::Entry::Flags_File | + BackupStoreDirectory::Entry::Flags_OldVersion}, + {0, x1aid, BackupStoreDirectory::Entry::Flags_File}, + {-1, 0, 0} + }; + static checkdepinfoen before_deps[] = {{x1id, x1aid, 0}, + {x1aid, 0, x1id}, {-1, 0, 0}}; + check_root_dir_ok(before_entries, before_deps); + + // Now break the reverse dependency by deleting x1a (the file, + // not the directory entry) + std::string x1aFileName; + StoreStructure::MakeObjectFilename(x1aid, storeRoot, discSetNum, + x1aFileName, true /* EnsureDirectoryExists */); + RaidFileWrite deleteX1a(discSetNum, x1aFileName); + deleteX1a.Delete(); + + // Check and fix the directory, and check that it's left empty + dir_en_check after_entries[] = {{-1, 0, 0}}; + static checkdepinfoen after_deps[] = {{-1, 0, 0}}; + check_and_fix_root_dir(after_entries, after_deps); + } + + BOX_INFO(" === Test that an entry pointing to a directory whose " + "raidfile is corrupted doesn't crash"); + + // Start the bbstored server + BOX_TRACE(" === Starting bbstored server: " BBSTORED + " testfiles/bbstored.conf"); + int bbstored_pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", + "testfiles/bbstored.pid"); + TEST_THAT(bbstored_pid > 0); + if (bbstored_pid <= 0) return 1; + + ::sleep(1); + TEST_THAT(ServerIsAlive(bbstored_pid)); + + std::string cmd = BBACKUPD " " + bbackupd_args + + " testfiles/bbackupd.conf"; + int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); + TEST_THAT(bbackupd_pid > 0); + if (bbackupd_pid <= 0) return 1; + + ::safe_sleep(1); + TEST_THAT(ServerIsAlive(bbackupd_pid)); + + // Wait 4 more seconds for the files to be old enough + // to upload + ::safe_sleep(4); + + // Upload files to create a nice store directory + ::sync_and_wait(); + + // Stop bbackupd + #ifdef WIN32 + terminate_bbackupd(bbackupd_pid); + // implicit check for memory leaks + #else + TEST_THAT(KillServer(bbackupd_pid)); + TestRemoteProcessMemLeaks("bbackupd.memleaks"); + #endif + + BOX_INFO(" === Add a reference to a file that doesn't exist, check " + "that it's removed"); + { + BackupStoreDirectory dir; + read_bb_dir(1 /* root */, dir); + + dir.AddEntry(fnames[0], 12, 0x1234567890123456LL /* id */, 1, + BackupStoreDirectory::Entry::Flags_File, 2); + + std::string fn; + StoreStructure::MakeObjectFilename(1 /* root */, storeRoot, + discSetNum, fn, true /* EnsureDirectoryExists */); + + std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, + fn)); + RaidFileWrite d(discSetNum, fn); + d.Open(true /* allow overwrite */); + dir.WriteToStream(d); + d.Commit(true /* write now! */); + + read_bb_dir(1 /* root */, dir); + TEST_THAT(dir.FindEntryByID(0x1234567890123456LL) != 0); + + // Check it + BackupStoreCheck checker(storeRoot, discSetNum, + 0x01234567, true /* FixErrors */, false /* Quiet */); + checker.Check(); + + // Should just be greater than 1 really, we don't know quite + // how good the checker is (or will become) at spotting errors! + // But this will help us catch changes in checker behaviour, + // so it's not a bad thing to test. + TEST_EQUAL(2, checker.GetNumErrorsFound()); + + file = RaidFileRead::Open(discSetNum, fn); + dir.ReadFromStream(*file, IOStream::TimeOutInfinite); + TEST_THAT(dir.FindEntryByID(0x1234567890123456LL) == 0); + } + + if (failures > 0) return 1; + + // Generate a list of all the object IDs + TEST_THAT_ABORTONFAIL(::system(BBACKUPQUERY " -Wwarning " + "-c testfiles/bbackupd.conf \"list -r\" quit " + "> testfiles/initial-listing.txt") == 0); + + // And load it in + { + FILE *f = ::fopen("testfiles/initial-listing.txt", "r"); + TEST_THAT_ABORTONFAIL(f != 0); + char line[512]; + int32_t id; + char flags[32]; + char name[256]; + while(::fgets(line, sizeof(line), f) != 0) + { + TEST_THAT(::sscanf(line, "%x %s %s", &id, + flags, name) == 3); + bool isDir = (::strcmp(flags, "-d---") == 0); + //TRACE3("%x,%d,%s\n", id, isDir, name); + MEMLEAKFINDER_NO_LEAKS; + nameToID[std::string(name)] = id; + objectIsDir[id] = isDir; + } + ::fclose(f); + } + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Delete store info, add random file"); + { + // Delete store info + RaidFileWrite del(discSetNum, storeRoot + "info"); + del.Delete(); + } + { + // Add a spurious file + RaidFileWrite random(discSetNum, + storeRoot + "randomfile"); + random.Open(); + random.Write("test", 4); + random.Commit(true); + } + + // Fix it + RUN_CHECK + + // Check everything is as it was + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 0") == 0); + // Check the random file doesn't exist + { + TEST_THAT(!RaidFileRead::FileExists(discSetNum, + storeRoot + "01/randomfile")); + } + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Delete an entry for an object from dir, change that " + "object to be a patch, check it's deleted"); + { + // Open dir and find entry + int64_t delID = getID("Test1/cannes/ict/metegoguered/oats"); + { + BackupStoreDirectory dir; + LoadDirectory("Test1/cannes/ict/metegoguered", dir); + TEST_THAT(dir.FindEntryByID(delID) != 0); + dir.DeleteEntry(delID); + SaveDirectory("Test1/cannes/ict/metegoguered", dir); + } + + // Adjust that entry + // + // IMPORTANT NOTE: There's a special hack in testbackupstorefix.pl to make sure that + // the file we're modifiying has at least two blocks so we can modify it and produce a valid file + // which will pass the verify checks. + // + std::string fn(getObjectName(delID)); + { + std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, fn)); + RaidFileWrite f(discSetNum, fn); + f.Open(true /* allow overwrite */); + // Make a copy of the original + file->CopyStreamTo(f); + // Move to header in both + file->Seek(0, IOStream::SeekType_Absolute); + BackupStoreFile::MoveStreamPositionToBlockIndex(*file); + f.Seek(file->GetPosition(), IOStream::SeekType_Absolute); + // Read header + struct + { + file_BlockIndexHeader hdr; + file_BlockIndexEntry e[2]; + } h; + TEST_THAT(file->Read(&h, sizeof(h)) == sizeof(h)); + file->Close(); + + // Modify + TEST_THAT(box_ntoh64(h.hdr.mOtherFileID) == 0); + TEST_THAT(box_ntoh64(h.hdr.mNumBlocks) >= 2); + h.hdr.mOtherFileID = box_hton64(2345); // don't worry about endianness + h.e[0].mEncodedSize = box_hton64((box_ntoh64(h.e[0].mEncodedSize)) + (box_ntoh64(h.e[1].mEncodedSize))); + h.e[1].mOtherBlockIndex = box_hton64(static_cast<uint64_t>(-2)); + // Write to modified file + f.Write(&h, sizeof(h)); + // Commit new version + f.Commit(true /* write now! */); + } + +#ifndef BOX_RELEASE_BUILD + // Delete two of the three raidfiles and their parent + // directories. This used to crash bbstoreaccounts check. + // We can only do this, without destroying the entire store, + // in debug mode, where the store has a far deeper + // structure. + // This will destroy or damage objects 18-1b and 58-5b, + // some repairably. + #define RUN(x) TEST_THAT(system(x) == 0); + RUN("mv testfiles/0_0/backup/01234567/02/01/o00.rf " + "testfiles/0_0/backup/01234567/02/01/o00.rfw"); // 0x18 + RUN("mv testfiles/0_1/backup/01234567/02/01/o01.rf " + "testfiles/0_1/backup/01234567/02/01/o01.rfw"); // 0x19 + //RUN("mv testfiles/0_2/backup/01234567/02/01/o02.rf " + // "testfiles/0_0/backup/01234567/02/01/o02.rfw"); // 0x1a + RUN("mv testfiles/0_0/backup/01234567/02/01/o03.rf " + "testfiles/0_0/backup/01234567/02/01/o03.rfw"); // 0x1b + RUN("mv testfiles/0_0/backup/01234567/02/01/01/o00.rf " + "testfiles/0_0/backup/01234567/02/01/01/o00.rfw"); // 0x58 + RUN("mv testfiles/0_1/backup/01234567/02/01/01/o01.rf " + "testfiles/0_1/backup/01234567/02/01/01/o01.rfw"); // 0x59 + //RUN("mv testfiles/0_2/backup/01234567/02/01/01/o02.rf " + // "testfiles/0_0/backup/01234567/02/01/01/o02.rfw"); // 0x5a + RUN("mv testfiles/0_0/backup/01234567/02/01/01/o03.rf " + "testfiles/0_0/backup/01234567/02/01/01/o03.rfw"); // 0x5b + // RUN("rm -r testfiles/0_1/backup/01234567/02/01"); + RUN("rm -r testfiles/0_2/backup/01234567/02/01"); + #undef RUN +#endif // BOX_RELEASE_BUILD + + // Fix it + RUN_CHECK_INTERNAL(3); + + // Check + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 1") + == 0); + + // Check the modified file doesn't exist + TEST_THAT(!RaidFileRead::FileExists(discSetNum, fn)); + + // Check that the missing RaidFiles were regenerated and + // committed. FileExists returns NonRaid if it find a .rfw + // file, so checking for AsRaid excludes this possibility. + RaidFileController &rcontroller(RaidFileController::GetController()); + RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(discSetNum)); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/o00")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/o01")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/o02")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/o03")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/01/o00")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/01/o01")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/01/o02")); + TEST_EQUAL(RaidFileUtil::AsRaid, RaidFileUtil::RaidFileExists( + rdiscSet, "backup/01234567/02/01/01/o03")); + } + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Delete directory, change container ID of another, " + "duplicate entry in dir, spurious file size, delete file"); + { + BackupStoreDirectory dir; + LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + dir.SetContainerID(73773); + SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + } + int64_t duplicatedID = 0; + int64_t notSpuriousFileSize = 0; + { + BackupStoreDirectory dir; + LoadDirectory("Test1/cannes/ict/peep", dir); + // Duplicate the second entry + { + BackupStoreDirectory::Iterator i(dir); + i.Next(); + BackupStoreDirectory::Entry *en = i.Next(); + TEST_THAT(en != 0); + duplicatedID = en->GetObjectID(); + dir.AddEntry(*en); + } + // Adjust file size of first file + { + BackupStoreDirectory::Iterator i(dir); + BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); + TEST_THAT(en != 0); + notSpuriousFileSize = en->GetSizeInBlocks(); + en->SetSizeInBlocks(3473874); + TEST_THAT(en->GetSizeInBlocks() == 3473874); + } + SaveDirectory("Test1/cannes/ict/peep", dir); + } + // Delete a directory + DeleteObject("Test1/pass/cacted/ming"); + // Delete a file + DeleteObject("Test1/cannes/ict/scely"); + + // We don't know quite how good the checker is (or will become) at + // spotting errors! But asserting an exact number will help us catch + // changes in checker behaviour, so it's not a bad thing to test. + + // The 11 errors are: + // ERROR: Directory ID 0xb references object 0x3e which does not exist. + // ERROR: Removing directory entry 0x3e from directory 0xb + // ERROR: Directory ID 0xc had invalid entries, fixed + // ERROR: Directory ID 0xc has wrong size for object 0x40 + // ERROR: Directory ID 0x17 has wrong container ID. + // ERROR: Object 0x51 is unattached. + // ERROR: Object 0x52 is unattached. + // ERROR: BlocksUsed changed from 282 to 278 + // ERROR: BlocksInCurrentFiles changed from 226 to 220 + // ERROR: BlocksInDirectories changed from 56 to 54 + // ERROR: NumFiles changed from 113 to 110 + + RUN_CHECK_INTERNAL(11); + + // Check everything is as it should be + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 2") == 0); + { + BackupStoreDirectory dir; + LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + TEST_THAT(dir.GetContainerID() == getID("Test1/foreomizes/stemptinevidate")); + } + { + BackupStoreDirectory dir; + LoadDirectory("Test1/cannes/ict/peep", dir); + BackupStoreDirectory::Iterator i(dir); + // Count the number of entries with the ID which was duplicated + int count = 0; + BackupStoreDirectory::Entry *en = 0; + while((en = i.Next()) != 0) + { + if(en->GetObjectID() == duplicatedID) + { + ++count; + } + } + TEST_THAT(count == 1); + // Check file size has changed + { + BackupStoreDirectory::Iterator i(dir); + BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); + TEST_THAT(en != 0); + TEST_THAT(en->GetSizeInBlocks() == notSpuriousFileSize); + } + } + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Modify the obj ID of dir, delete dir with no members, " + "add extra reference to a file"); + // Set bad object ID + { + BackupStoreDirectory dir; + LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + dir.TESTONLY_SetObjectID(73773); + SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + } + // Delete dir with no members + DeleteObject("Test1/dir-no-members"); + // Add extra reference + { + BackupStoreDirectory dir; + LoadDirectory("Test1/divel", dir); + BackupStoreDirectory::Iterator i(dir); + BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); + TEST_THAT(en != 0); + BackupStoreDirectory dir2; + LoadDirectory("Test1/divel/torsines/cruishery", dir2); + dir2.AddEntry(*en); + SaveDirectory("Test1/divel/torsines/cruishery", dir2); + } + // Fix it + RUN_CHECK + // Check everything is as it should be + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 3") == 0); + { + BackupStoreDirectory dir; + LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); + TEST_THAT(dir.GetObjectID() == getID("Test1/foreomizes/stemptinevidate/ict")); + } + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Orphan files and dirs without being recoverable"); + DeleteObject("Test1/dir1"); + DeleteObject("Test1/dir1/dir2"); + // Fix it + RUN_CHECK + // Check everything is where it is predicted to be + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 4") == 0); + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Corrupt file and dir"); + // File + CorruptObject("Test1/foreomizes/stemptinevidate/algoughtnerge", + 33, "34i729834298349283479233472983sdfhasgs"); + // Dir + CorruptObject("Test1/cannes/imulatrougge/foreomizes",23, + "dsf32489sdnadf897fd2hjkesdfmnbsdfcsfoisufio2iofe2hdfkjhsf"); + // Fix it + RUN_CHECK + // Check everything is where it should be + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl check 5") == 0); + + // ------------------------------------------------------------------------------------------------ + BOX_INFO(" === Overwrite root with a file"); + { + std::auto_ptr<RaidFileRead> r(RaidFileRead::Open(discSetNum, getObjectName(getID("Test1/pass/shuted/brightinats/milamptimaskates")))); + RaidFileWrite w(discSetNum, getObjectName(1 /* root */)); + w.Open(true /* allow overwrite */); + r->CopyStreamTo(w); + w.Commit(true /* convert now */); + } + // Fix it + RUN_CHECK + // Check everything is where it should be + TEST_THAT(::system(PERL_EXECUTABLE + " testfiles/testbackupstorefix.pl reroot 6") == 0); + + + // --------------------------------------------------------- + // Stop server + TEST_THAT(KillServer(bbstored_pid)); + + #ifdef WIN32 + TEST_THAT(unlink("testfiles/bbstored.pid") == 0); + #else + TestRemoteProcessMemLeaks("bbstored.memleaks"); + #endif +>>>>>>> 0.12 return 0; } diff --git a/test/backupstorefix/testfiles/testbackupstorefix.pl.in b/test/backupstorefix/testfiles/testbackupstorefix.pl.in index d27c1106..b58414af 100755 --- a/test/backupstorefix/testfiles/testbackupstorefix.pl.in +++ b/test/backupstorefix/testfiles/testbackupstorefix.pl.in @@ -104,7 +104,11 @@ elsif($ARGV[0] eq 'check') { print LISTING_COPY; chomp; s/\r//; +<<<<<<< HEAD s/\[FILENAME NOT ENCRYPTED\]//; +======= + s/ \[FILENAME NOT ENCRYPTED\]//; +>>>>>>> 0.12 if(exists $expected{$_}) { delete $expected{$_} diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index 2510da30..fe0e0531 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -13,7 +13,11 @@ #include <string.h> #include <signal.h> +<<<<<<< HEAD #include "autogen_BackupProtocolClient.h" +======= +#include "autogen_BackupProtocol.h" +>>>>>>> 0.12 #include "BackupClientCryptoKeys.h" #include "BackupClientFileAttributes.h" #include "BackupStoreAccountDatabase.h" @@ -354,7 +358,11 @@ int test(int argc, const char *argv[]) // Login { // Check the version +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); +======= + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); +>>>>>>> 0.12 TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); // Login @@ -367,9 +375,15 @@ int test(int argc, const char *argv[]) // Upload the first file { std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/0.test", +<<<<<<< HEAD BackupProtocolClientListDirectory::RootDirectory, storeFilename)); std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( BackupProtocolClientListDirectory::RootDirectory, ModificationTime, +======= + BackupProtocolListDirectory::RootDirectory, storeFilename)); + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, ModificationTime, +>>>>>>> 0.12 ModificationTime, 0 /* no diff from file ID */, storeFilename, *upload)); test_files[0].IDOnServer = stored->GetObjectID(); test_files[0].IsCompletelyDifferent = true; @@ -380,8 +394,13 @@ int test(int argc, const char *argv[]) for(unsigned int f = 1; f < NUMBER_FILES; ++f) { // Get an index for the previous version +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getBlockIndex(protocol.QueryGetBlockIndexByName( BackupProtocolClientListDirectory::RootDirectory, storeFilename)); +======= + std::auto_ptr<BackupProtocolSuccess> getBlockIndex(protocol.QueryGetBlockIndexByName( + BackupProtocolListDirectory::RootDirectory, storeFilename)); +>>>>>>> 0.12 int64_t diffFromID = getBlockIndex->GetObjectID(); TEST_THAT(diffFromID != 0); @@ -397,7 +416,11 @@ int test(int argc, const char *argv[]) std::auto_ptr<IOStream> patchStream( BackupStoreFile::EncodeFileDiff( filename, +<<<<<<< HEAD BackupProtocolClientListDirectory::RootDirectory, /* containing directory */ +======= + BackupProtocolListDirectory::RootDirectory, /* containing directory */ +>>>>>>> 0.12 storeFilename, diffFromID, *blockIndexStream, @@ -407,8 +430,13 @@ int test(int argc, const char *argv[]) &isCompletelyDifferent)); // Upload the patch to the store +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( BackupProtocolClientListDirectory::RootDirectory, ModificationTime, +======= + std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( + BackupProtocolListDirectory::RootDirectory, ModificationTime, +>>>>>>> 0.12 ModificationTime, isCompletelyDifferent?(0):(diffFromID), storeFilename, *patchStream)); ModificationTime += MODIFICATION_TIME_INC; @@ -432,10 +460,17 @@ int test(int argc, const char *argv[]) // List the directory from the server, and check that no dependency info is sent -- waste of bytes { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory( BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +======= + std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory( + BackupProtocolListDirectory::RootDirectory, + BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */)); +>>>>>>> 0.12 // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); @@ -531,7 +566,11 @@ int test(int argc, const char *argv[]) BOX_PORT_BBSTORED_TEST); BackupProtocolClient protocol(conn); { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); +======= + std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); +>>>>>>> 0.12 TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); protocol.QueryLogin(0x01234567, 0); } @@ -555,8 +594,13 @@ int test(int argc, const char *argv[]) // Fetch the file { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetFile( BackupProtocolClientListDirectory::RootDirectory, +======= + std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile( + BackupProtocolListDirectory::RootDirectory, +>>>>>>> 0.12 test_files[f].IDOnServer)); TEST_THAT(getobj->GetObjectID() == test_files[f].IDOnServer); // BLOCK @@ -572,7 +616,11 @@ int test(int argc, const char *argv[]) // Download the index, and check it looks OK { +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByID(test_files[f].IDOnServer)); +======= + std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(test_files[f].IDOnServer)); +>>>>>>> 0.12 TEST_THAT(getblockindex->GetObjectID() == test_files[f].IDOnServer); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); TEST_THAT(BackupStoreFile::CompareFileContentsAgainstBlockIndex(filename, *blockIndexStream, IOStream::TimeOutInfinite)); diff --git a/test/basicserver/Makefile.extra b/test/basicserver/Makefile.extra index 50120136..cfafbdb2 100644 --- a/test/basicserver/Makefile.extra +++ b/test/basicserver/Makefile.extra @@ -1,6 +1,7 @@ MAKEPROTOCOL = ../../lib/server/makeprotocol.pl +<<<<<<< HEAD GEN_CMD_SRV = $(MAKEPROTOCOL) Server testprotocol.txt GEN_CMD_CLI = $(MAKEPROTOCOL) Client testprotocol.txt @@ -18,4 +19,14 @@ autogen_TestProtocolClient.cpp: $(MAKEPROTOCOL) testprotocol.txt autogen_TestProtocolClient.h: $(MAKEPROTOCOL) testprotocol.txt $(_PERL) $(GEN_CMD_CLI) +======= +GEN_CMD = $(MAKEPROTOCOL) testprotocol.txt + +# AUTOGEN SEEDING +autogen_TestProtocol.cpp: $(MAKEPROTOCOL) testprotocol.txt + $(_PERL) $(GEN_CMD) + +autogen_TestProtocolServer.h: $(MAKEPROTOCOL) testprotocol.txt + $(_PERL) $(GEN_CMD) +>>>>>>> 0.12 diff --git a/test/basicserver/TestCommands.cpp b/test/basicserver/TestCommands.cpp index 657e79ea..e193458e 100644 --- a/test/basicserver/TestCommands.cpp +++ b/test/basicserver/TestCommands.cpp @@ -5,12 +5,17 @@ #include <syslog.h> #endif +<<<<<<< HEAD #include "autogen_TestProtocolServer.h" +======= +#include "autogen_TestProtocol.h" +>>>>>>> 0.12 #include "CollectInBufferStream.h" #include "MemLeakFindOn.h" +<<<<<<< HEAD std::auto_ptr<ProtocolObject> TestProtocolServerHello::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) { if(mNumber32 != 41 || mNumber16 != 87 || mNumber8 != 11 || mText != "pingu") @@ -33,6 +38,30 @@ std::auto_ptr<ProtocolObject> TestProtocolServerQuit::DoCommand(TestProtocolServ std::auto_ptr<ProtocolObject> TestProtocolServerSimple::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) { return std::auto_ptr<ProtocolObject>(new TestProtocolServerSimpleReply(mValue+1)); +======= +std::auto_ptr<TestProtocolMessage> TestProtocolHello::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + if(mNumber32 != 41 || mNumber16 != 87 || mNumber8 != 11 || mText != "pingu") + { + return std::auto_ptr<TestProtocolMessage>(new TestProtocolError(0, 0)); + } + return std::auto_ptr<TestProtocolMessage>(new TestProtocolHello(12,89,22,std::string("Hello world!"))); +} + +std::auto_ptr<TestProtocolMessage> TestProtocolLists::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + return std::auto_ptr<TestProtocolMessage>(new TestProtocolListsReply(mLotsOfText.size())); +} + +std::auto_ptr<TestProtocolMessage> TestProtocolQuit::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + return std::auto_ptr<TestProtocolMessage>(new TestProtocolQuit); +} + +std::auto_ptr<TestProtocolMessage> TestProtocolSimple::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + return std::auto_ptr<TestProtocolMessage>(new TestProtocolSimpleReply(mValue+1)); +>>>>>>> 0.12 } class UncertainBufferStream : public CollectInBufferStream @@ -45,7 +74,11 @@ public: } }; +<<<<<<< HEAD std::auto_ptr<ProtocolObject> TestProtocolServerGetStream::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) +======= +std::auto_ptr<TestProtocolMessage> TestProtocolGetStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +>>>>>>> 0.12 { // make a new stream object CollectInBufferStream *pstream = mUncertainSize?(new UncertainBufferStream):(new CollectInBufferStream); @@ -68,6 +101,7 @@ std::auto_ptr<ProtocolObject> TestProtocolServerGetStream::DoCommand(TestProtoco // Get it to be sent rProtocol.SendStreamAfterCommand(pstream); +<<<<<<< HEAD return std::auto_ptr<ProtocolObject>(new TestProtocolServerGetStream(mStartingValue, mUncertainSize)); } @@ -76,6 +110,16 @@ std::auto_ptr<ProtocolObject> TestProtocolServerSendStream::DoCommand(TestProtoc if(mValue != 0x73654353298ffLL) { return std::auto_ptr<ProtocolObject>(new TestProtocolServerError(0, 0)); +======= + return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(mStartingValue, mUncertainSize)); +} + +std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + if(mValue != 0x73654353298ffLL) + { + return std::auto_ptr<TestProtocolMessage>(new TestProtocolError(0, 0)); +>>>>>>> 0.12 } // Get a stream @@ -91,11 +135,20 @@ std::auto_ptr<ProtocolObject> TestProtocolServerSendStream::DoCommand(TestProtoc } // tell the caller how many bytes there were +<<<<<<< HEAD return std::auto_ptr<ProtocolObject>(new TestProtocolServerGetStream(bytes, uncertain)); } std::auto_ptr<ProtocolObject> TestProtocolServerString::DoCommand(TestProtocolServer &rProtocol, TestContext &rContext) { return std::auto_ptr<ProtocolObject>(new TestProtocolServerString(mTest)); +======= + return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(bytes, uncertain)); +} + +std::auto_ptr<TestProtocolMessage> TestProtocolString::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const +{ + return std::auto_ptr<TestProtocolMessage>(new TestProtocolString(mTest)); +>>>>>>> 0.12 } diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 18bc0aa8..ebf77979 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -26,8 +26,12 @@ #include "CollectInBufferStream.h" #include "TestContext.h" +<<<<<<< HEAD #include "autogen_TestProtocolClient.h" #include "autogen_TestProtocolServer.h" +======= +#include "autogen_TestProtocol.h" +>>>>>>> 0.12 #include "ServerControl.h" #include "MemLeakFindOn.h" @@ -331,8 +335,13 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) bool hadTimeout = false; while(!getline[c]->GetLine(rep, false, COMMS_READ_TIMEOUT)) hadTimeout = true; +<<<<<<< HEAD TEST_THAT(rep == recieve[q]); TEST_THAT(hadTimeout) +======= + TEST_EQUAL_LINE(rep, recieve[q], "Line " << q); + TEST_LINE(hadTimeout, "Line " << q) +>>>>>>> 0.12 } } for(unsigned int c = 0; c < conns.size(); ++c) @@ -393,7 +402,11 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) void TestStreamReceive(TestProtocolClient &protocol, int value, bool uncertainstream) { +<<<<<<< HEAD std::auto_ptr<TestProtocolClientGetStream> reply(protocol.QueryGetStream(value, uncertainstream)); +======= + std::auto_ptr<TestProtocolGetStream> reply(protocol.QueryGetStream(value, uncertainstream)); +>>>>>>> 0.12 TEST_THAT(reply->GetStartingValue() == value); // Get a stream @@ -704,11 +717,19 @@ int test(int argc, const char *argv[]) // Simple query { +<<<<<<< HEAD std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(41)); TEST_THAT(reply->GetValuePlusOne() == 42); } { std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(809)); +======= + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(41)); + TEST_THAT(reply->GetValuePlusOne() == 42); + } + { + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(809)); +>>>>>>> 0.12 TEST_THAT(reply->GetValuePlusOne() == 810); } @@ -724,14 +745,22 @@ int test(int argc, const char *argv[]) char buf[1663]; s.Write(buf, sizeof(buf)); s.SetForReading(); +<<<<<<< HEAD std::auto_ptr<TestProtocolClientGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, s)); +======= + std::auto_ptr<TestProtocolGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, s)); +>>>>>>> 0.12 TEST_THAT(reply->GetStartingValue() == sizeof(buf)); } // Lots of simple queries for(int q = 0; q < 514; q++) { +<<<<<<< HEAD std::auto_ptr<TestProtocolClientSimpleReply> reply(protocol.QuerySimple(q)); +======= + std::auto_ptr<TestProtocolSimpleReply> reply(protocol.QuerySimple(q)); +>>>>>>> 0.12 TEST_THAT(reply->GetValuePlusOne() == (q+1)); } // Send a list of strings to it @@ -740,13 +769,21 @@ int test(int argc, const char *argv[]) strings.push_back(std::string("test1")); strings.push_back(std::string("test2")); strings.push_back(std::string("test3")); +<<<<<<< HEAD std::auto_ptr<TestProtocolClientListsReply> reply(protocol.QueryLists(strings)); +======= + std::auto_ptr<TestProtocolListsReply> reply(protocol.QueryLists(strings)); +>>>>>>> 0.12 TEST_THAT(reply->GetNumberOfStrings() == 3); } // And another { +<<<<<<< HEAD std::auto_ptr<TestProtocolClientHello> reply(protocol.QueryHello(41,87,11,std::string("pingu"))); +======= + std::auto_ptr<TestProtocolHello> reply(protocol.QueryHello(41,87,11,std::string("pingu"))); +>>>>>>> 0.12 TEST_THAT(reply->GetNumber32() == 12); TEST_THAT(reply->GetNumber16() == 89); TEST_THAT(reply->GetNumber8() == 22); diff --git a/test/bbackupd/Makefile.extra b/test/bbackupd/Makefile.extra index 0ae56bd1..1bd897bd 100644 --- a/test/bbackupd/Makefile.extra +++ b/test/bbackupd/Makefile.extra @@ -6,9 +6,20 @@ link-extra: ../../bin/bbackupd/autogen_ClientException.o \ ../../bin/bbackupd/BackupClientInodeToIDMap.o \ ../../bin/bbackupd/Win32ServiceFunctions.o \ ../../bin/bbackupd/BackupDaemon.o \ +<<<<<<< HEAD ../../bin/bbstored/BackupStoreContext.o \ ../../bin/bbstored/BBStoreDHousekeeping.o \ ../../bin/bbstored/HousekeepStoreAccount.o \ ../../bin/bbstored/autogen_BackupProtocolServer.o \ ../../bin/bbstored/BackupCommands.o \ ../../bin/bbstored/BackupStoreDaemon.o +======= + ../../bin/bbstored/BBStoreDHousekeeping.o \ + ../../lib/backupstore/HousekeepStoreAccount.o \ + ../../lib/backupstore/autogen_BackupProtocol.o \ + ../../lib/backupstore/BackupStoreContext.o \ + ../../lib/backupstore/BackupCommands.o \ + ../../bin/bbstored/BackupStoreDaemon.o \ + ../../bin/bbackupquery/BackupQueries.o \ + ../../bin/bbackupquery/autogen_Documentation.o +>>>>>>> 0.12 diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 77c463ba..71778ca6 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -42,18 +42,30 @@ #include <sys/syscall.h> #endif +<<<<<<< HEAD #include "autogen_BackupProtocolServer.h" +======= +#include "autogen_BackupProtocol.h" +>>>>>>> 0.12 #include "BackupClientCryptoKeys.h" #include "BackupClientFileAttributes.h" #include "BackupClientRestore.h" #include "BackupDaemon.h" #include "BackupDaemonConfigVerify.h" #include "BackupQueries.h" +<<<<<<< HEAD +======= +#include "BackupStoreAccounts.h" +>>>>>>> 0.12 #include "BackupStoreConstants.h" #include "BackupStoreContext.h" #include "BackupStoreDaemon.h" #include "BackupStoreDirectory.h" #include "BackupStoreException.h" +<<<<<<< HEAD +======= +#include "BackupStoreConfigVerify.h" +>>>>>>> 0.12 #include "BoxPortsAndFiles.h" #include "BoxTime.h" #include "BoxTimeToUnix.h" @@ -62,8 +74,15 @@ #include "Configuration.h" #include "FileModificationTime.h" #include "FileStream.h" +<<<<<<< HEAD #include "IOStreamGetLine.h" #include "LocalProcessStream.h" +======= +#include "intercept.h" +#include "IOStreamGetLine.h" +#include "LocalProcessStream.h" +#include "RaidFileController.h" +>>>>>>> 0.12 #include "SSLLib.h" #include "ServerControl.h" #include "Socket.h" @@ -73,10 +92,13 @@ #include "Timer.h" #include "Utils.h" +<<<<<<< HEAD #include "autogen_BackupProtocolClient.h" #include "intercept.h" #include "ServerControl.h" +======= +>>>>>>> 0.12 #include "MemLeakFindOn.h" // ENOATTR may be defined in a separate header file which we may not have @@ -475,8 +497,13 @@ int64_t GetDirID(BackupProtocolClient &protocol, const char *name, int64_t InDir { protocol.QueryListDirectory( InDirectory, +<<<<<<< HEAD BackupProtocolClientListDirectory::Flags_Dir, BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, +======= + BackupProtocolListDirectory::Flags_Dir, + BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, +>>>>>>> 0.12 true /* want attributes */); // Retrieve the directory from the stream following @@ -518,6 +545,7 @@ void do_interrupted_restore(const TLSContext &context, int64_t restoredirid) 22011); BackupProtocolClient protocol(conn); protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly)); // Test the restoration @@ -525,6 +553,21 @@ void do_interrupted_restore(const TLSContext &context, int64_t restoredirid) "Test1", "testfiles/restore-interrupt", true /* print progress dots */) == Restore_Complete); +======= + std::auto_ptr<BackupProtocolLoginConfirmed> + loginConf(protocol.QueryLogin(0x01234567, + BackupProtocolLogin::Flags_ReadOnly)); + + // Test the restoration + TEST_THAT(BackupClientRestore(protocol, restoredirid, + "testfiles/restore-interrupt", /* remote */ + "testfiles/restore-interrupt", /* local */ + true /* print progress dots */, + false /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) == Restore_Complete); +>>>>>>> 0.12 // Log out protocol.QueryFinished(); @@ -602,7 +645,11 @@ int64_t SearchDir(BackupStoreDirectory& rDir, if (en == 0) return 0; int64_t id = en->GetObjectID(); TEST_THAT(id > 0); +<<<<<<< HEAD TEST_THAT(id != BackupProtocolClientListDirectory::RootDirectory); +======= + TEST_THAT(id != BackupProtocolListDirectory::RootDirectory); +>>>>>>> 0.12 return id; } @@ -615,7 +662,11 @@ std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext) std::auto_ptr<BackupProtocolClient> connection; connection.reset(new BackupProtocolClient(sSocket)); connection->Handshake(); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientVersion> +======= + std::auto_ptr<BackupProtocolVersion> +>>>>>>> 0.12 serverVersion(connection->QueryVersion( BACKUP_STORE_SERVER_VERSION)); if(serverVersion->GetVersion() != @@ -638,10 +689,17 @@ std::auto_ptr<BackupProtocolClient> ConnectAndLogin(TLSContext& rContext, std::auto_ptr<BackupStoreDirectory> ReadDirectory ( BackupProtocolClient& rClient, +<<<<<<< HEAD int64_t id ) { std::auto_ptr<BackupProtocolClientSuccess> dirreply( +======= + int64_t id = BackupProtocolListDirectory::RootDirectory +) +{ + std::auto_ptr<BackupProtocolSuccess> dirreply( +>>>>>>> 0.12 rClient.QueryListDirectory(id, false, 0, false)); std::auto_ptr<IOStream> dirstream(rClient.ReceiveStream()); std::auto_ptr<BackupStoreDirectory> apDir(new BackupStoreDirectory()); @@ -649,6 +707,11 @@ std::auto_ptr<BackupStoreDirectory> ReadDirectory return apDir; } +<<<<<<< HEAD +======= +Daemon* spDaemon = NULL; + +>>>>>>> 0.12 int start_internal_daemon() { // ensure that no child processes end up running tests! @@ -662,6 +725,10 @@ int start_internal_daemon() }; BackupDaemon daemon; +<<<<<<< HEAD +======= + spDaemon = &daemon; // to propagate into child +>>>>>>> 0.12 int result; if (bbackupd_args.size() > 0) @@ -672,6 +739,11 @@ int start_internal_daemon() { result = daemon.Main("testfiles/bbackupd.conf", 1, argv); } +<<<<<<< HEAD +======= + + spDaemon = NULL; // to ensure not used by parent +>>>>>>> 0.12 TEST_EQUAL_LINE(0, result, "Daemon exit code"); @@ -709,6 +781,10 @@ int start_internal_daemon() fflush(stdout); TEST_THAT(pid > 0); +<<<<<<< HEAD +======= + spDaemon = &daemon; +>>>>>>> 0.12 return pid; } @@ -749,6 +825,7 @@ extern "C" struct dirent *readdir_test_hook_1(DIR *dir) extern "C" struct dirent *readdir_test_hook_2(DIR *dir) { +<<<<<<< HEAD if (time(NULL) >= readdir_stop_time) { #ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE @@ -757,6 +834,32 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) // we will not be called again. #endif } +======= + if (spDaemon->IsTerminateWanted()) + { + // force daemon to crash, right now + return NULL; + } + + time_t time_now = time(NULL); + + if (time_now >= readdir_stop_time) + { +#ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE + BOX_NOTICE("Cancelling readdir hook at " << time_now); + intercept_setup_readdir_hook(NULL, NULL); + intercept_setup_lstat_hook (NULL, NULL); + // we will not be called again. +#else + BOX_NOTICE("Failed to cancel readdir hook at " << time_now); +#endif + } + else + { + BOX_TRACE("readdir hook still active at " << time_now << ", " + "waiting for " << readdir_stop_time); + } +>>>>>>> 0.12 // fill in the struct dirent appropriately memset(&readdir_test_dirent, 0, sizeof(readdir_test_dirent)); @@ -768,6 +871,10 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) snprintf(readdir_test_dirent.d_name, sizeof(readdir_test_dirent.d_name), "test.%d", readdir_test_counter); +<<<<<<< HEAD +======= + BOX_TRACE("readdir hook returning " << readdir_test_dirent.d_name); +>>>>>>> 0.12 // ensure that when bbackupd stats the file, it gets the // right answer @@ -779,6 +886,12 @@ extern "C" struct dirent *readdir_test_hook_2(DIR *dir) intercept_setup_lstat_hook(stat_hook_filename, lstat_test_hook); #endif +<<<<<<< HEAD +======= + // sleep a bit to reduce the number of dirents returned + ::safe_sleep(1); + +>>>>>>> 0.12 return &readdir_test_dirent; } @@ -822,6 +935,36 @@ bool test_entry_deleted(BackupStoreDirectory& rDir, return flags && BackupStoreDirectory::Entry::Flags_Deleted; } +<<<<<<< HEAD +======= +bool compare_all(BackupQueries::ReturnCode::Type expected_status, + std::string config_file = "testfiles/bbackupd.conf") +{ + std::string cmd = BBACKUPQUERY; + cmd += " "; + cmd += (expected_status == BackupQueries::ReturnCode::Compare_Same) + ? "-Werror" : "-Wwarning"; + cmd += " -c "; + cmd += config_file; + cmd += " \"compare -acQ\" quit"; + + int returnValue = ::system(cmd.c_str()); + + int expected_system_result = (int) expected_status; + + #ifndef WIN32 + expected_system_result <<= 8; + #endif + + TEST_EQUAL_LINE(expected_system_result, returnValue, "compare return value"); + TestRemoteProcessMemLeaks("bbackupquery.memleaks"); + return (returnValue == expected_system_result); +} + +#define TEST_COMPARE(...) \ + TEST_THAT(compare_all(BackupQueries::ReturnCode::__VA_ARGS__)); + +>>>>>>> 0.12 int test_bbackupd() { // First, wait for a normal period to make sure the last changes @@ -964,6 +1107,7 @@ int test_bbackupd() comp2.size() + 1, comp2.size()); TEST_LINE(comp2 != sub, line); } +<<<<<<< HEAD if (failures > 0) { @@ -971,6 +1115,13 @@ int test_bbackupd() Timers::Init(); return 1; } +======= + + Timers::Init(); + + // stop early to make debugging easier + if (failures) return 1; +>>>>>>> 0.12 // four-second delay on first read() of f1 // should mean that no keepalives were sent, @@ -978,6 +1129,7 @@ int test_bbackupd() // before any matching blocks could be found. intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 0, 4000, SYS_read, 1); +<<<<<<< HEAD pid = start_internal_daemon(); intercept_clear_setup(); @@ -995,6 +1147,29 @@ int test_bbackupd() // it's in a different process. // TEST_THAT(intercept_triggered()); TEST_THAT(stop_internal_daemon(pid)); +======= + + { + BackupDaemon bbackupd; + bbackupd.Configure("testfiles/bbackupd.conf"); + bbackupd.InitCrypto(); + + fd = open("testfiles/TestDir1/spacetest/f1", O_WRONLY); + TEST_THAT(fd > 0); + // write again, to update the file's timestamp + TEST_EQUAL_LINE(1, write(fd, "z", 1), "Buffer write"); + TEST_THAT(close(fd) == 0); + + // wait long enough to put file into sync window + wait_for_operation(5, "locally modified file to " + "mature for sync"); + + bbackupd.RunSyncNow(); + TEST_THAT(intercept_triggered()); + intercept_clear_setup(); + Timers::Cleanup(); + } +>>>>>>> 0.12 // check that the diff was aborted, i.e. upload was not a diff found1 = false; @@ -1118,6 +1293,12 @@ int test_bbackupd() TEST_LINE(comp2 != sub, line); } +<<<<<<< HEAD +======= + // Check that no read error has been reported yet + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); + +>>>>>>> 0.12 if (failures > 0) { // stop early to make debugging easier @@ -1137,7 +1318,11 @@ int test_bbackupd() std::string touchfile = "testfiles/TestDir1/spacetest/d1/touch-me"; +<<<<<<< HEAD fd = open(touchfile.c_str(), O_CREAT | O_WRONLY); +======= + fd = open(touchfile.c_str(), O_CREAT | O_WRONLY, 0700); +>>>>>>> 0.12 TEST_THAT(fd > 0); // write again, to update the file's timestamp TEST_EQUAL_LINE(sizeof(buffer), @@ -1229,6 +1414,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if(bbackupd_pid > 0) { @@ -1297,6 +1486,7 @@ int test_bbackupd() BOX_TRACE("Sync finished."); BOX_TRACE("Compare to check that there are differences"); +<<<<<<< HEAD int compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query0a.log " @@ -1304,6 +1494,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 BOX_TRACE("Compare finished."); // Check that the notify script was run @@ -1325,7 +1518,11 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, 0 /* read-write */); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientAccountUsage> usage( +======= + std::auto_ptr<BackupProtocolAccountUsage> usage( +>>>>>>> 0.12 client->QueryGetAccountUsage()); TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), "blocks used"); @@ -1338,11 +1535,15 @@ int test_bbackupd() sSocket.Close(); } +<<<<<<< HEAD if (failures > 0) { // stop early to make debugging easier return 1; } +======= + if (failures) return 1; +>>>>>>> 0.12 // ensure time is different to refresh the cache ::safe_sleep(1); @@ -1365,6 +1566,17 @@ int test_bbackupd() */ BackupDaemon bbackupd; +<<<<<<< HEAD +======= + + { + const char* argv[] = { "bbackupd", + bbackupd_args.c_str() }; + TEST_EQUAL_LINE(0, bbackupd.ProcessOptions(2, argv), + "processing command-line options"); + } + +>>>>>>> 0.12 bbackupd.Configure("testfiles/bbackupd-exclude.conf"); bbackupd.InitCrypto(); BOX_TRACE("done."); @@ -1408,8 +1620,12 @@ int test_bbackupd() ConnectAndLogin(context, 0 /* read-write */); std::auto_ptr<BackupStoreDirectory> rootDir = +<<<<<<< HEAD ReadDirectory(*client, BackupProtocolClientListDirectory::RootDirectory); +======= + ReadDirectory(*client); +>>>>>>> 0.12 int64_t testDirId = SearchDir(*rootDir, "Test1"); TEST_THAT(testDirId != 0); @@ -1451,7 +1667,11 @@ int test_bbackupd() ReadDirectory(*client, d4_id); TEST_THAT(test_entry_deleted(*d4_dir, "f5")); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientAccountUsage> usage( +======= + std::auto_ptr<BackupProtocolAccountUsage> usage( +>>>>>>> 0.12 client->QueryGetAccountUsage()); TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), "blocks used"); @@ -1470,11 +1690,15 @@ int test_bbackupd() } BOX_TRACE("done."); +<<<<<<< HEAD if (failures > 0) { // stop early to make debugging easier return 1; } +======= + if (failures) return 1; +>>>>>>> 0.12 wait_for_operation(5, "housekeeping to remove the " "deleted files"); @@ -1485,8 +1709,12 @@ int test_bbackupd() ConnectAndLogin(context, 0 /* read-write */); std::auto_ptr<BackupStoreDirectory> rootDir = +<<<<<<< HEAD ReadDirectory(*client, BackupProtocolClientListDirectory::RootDirectory); +======= + ReadDirectory(*client); +>>>>>>> 0.12 int64_t testDirId = SearchDir(*rootDir, "Test1"); TEST_THAT(testDirId != 0); @@ -1506,7 +1734,11 @@ int test_bbackupd() TEST_THAT(SearchDir(*spacetest_dir, "d3") == 0); TEST_THAT(SearchDir(*spacetest_dir, "d7") == 0); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientAccountUsage> usage( +======= + std::auto_ptr<BackupProtocolAccountUsage> usage( +>>>>>>> 0.12 client->QueryGetAccountUsage()); TEST_EQUAL_LINE(16, usage->GetBlocksUsed(), "blocks used"); @@ -1523,11 +1755,15 @@ int test_bbackupd() sSocket.Close(); } +<<<<<<< HEAD if (failures > 0) { // stop early to make debugging easier return 1; } +======= + if (failures) return 1; +>>>>>>> 0.12 // Need 22 blocks free to upload everything TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS " -c " @@ -1537,14 +1773,19 @@ int test_bbackupd() // Run another backup, now there should be enough space // for everything we want to upload. +<<<<<<< HEAD { Logging::Guard guard(Log::ERROR); bbackupd.RunSyncNow(); } +======= + bbackupd.RunSyncNow(); +>>>>>>> 0.12 TEST_THAT(!bbackupd.StorageLimitExceeded()); // Check that the contents of the store are the same // as the contents of the disc +<<<<<<< HEAD // (-a = all, -c = give result in return code) BOX_TRACE("Check that all files were uploaded successfully"); compareReturnValue = ::system(BBACKUPQUERY " " @@ -1554,6 +1795,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same, "testfiles/bbackupd-exclude.conf"); +>>>>>>> 0.12 BOX_TRACE("done."); // BLOCK @@ -1561,7 +1805,11 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, 0 /* read-write */); +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientAccountUsage> usage( +======= + std::auto_ptr<BackupProtocolAccountUsage> usage( +>>>>>>> 0.12 client->QueryGetAccountUsage()); TEST_EQUAL_LINE(22, usage->GetBlocksUsed(), "blocks used"); @@ -1576,11 +1824,15 @@ int test_bbackupd() sSocket.Close(); } +<<<<<<< HEAD if (failures > 0) { // stop early to make debugging easier return 1; } +======= + if (failures) return 1; +>>>>>>> 0.12 // Put the limit back TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS " -c " @@ -1600,6 +1852,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 BOX_TRACE("done."); // unpack the initial files again @@ -1617,6 +1873,7 @@ int test_bbackupd() // as the contents of the disc // (-a = all, -c = give result in return code) BOX_TRACE("Check that all files were uploaded successfully"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query1.log " @@ -1624,18 +1881,25 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 BOX_TRACE("done."); TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD if (failures > 0) { // stop early to make debugging easier return 1; } +======= + if (failures) return 1; +>>>>>>> 0.12 } // Check that no read error has been reported yet @@ -1672,17 +1936,29 @@ int test_bbackupd() class MyHook : public BackupStoreContext::TestHook { +<<<<<<< HEAD virtual std::auto_ptr<ProtocolObject> StartCommand( BackupProtocolObject& rCommand) { if (rCommand.GetType() == BackupProtocolServerStoreFile::TypeID) +======= + virtual std::auto_ptr<BackupProtocolMessage> StartCommand( + const BackupProtocolMessage& rCommand) + { + if (rCommand.GetType() == + BackupProtocolStoreFile::TypeID) +>>>>>>> 0.12 { // terminate badly THROW_EXCEPTION(CommonException, Internal); } +<<<<<<< HEAD return std::auto_ptr<ProtocolObject>(); +======= + return std::auto_ptr<BackupProtocolMessage>(); +>>>>>>> 0.12 } }; MyHook hook; @@ -1769,6 +2045,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 } #endif // !WIN32 @@ -1810,6 +2090,7 @@ int test_bbackupd() sync_and_wait(); // Check that the backup was successful, i.e. no differences +<<<<<<< HEAD int compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query1.log " @@ -1817,6 +2098,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // now stop bbackupd and update the test file, // make the original directory unreadable @@ -1832,12 +2116,23 @@ int test_bbackupd() TEST_THAT(chmod(SYM_DIR, 0) == 0); // check that we can restore it +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-Wwarning \"restore Test1 testfiles/restore-symlink\" " "quit"); TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Command_OK); +======= + { + int returnValue = ::system(BBACKUPQUERY " " + "-c testfiles/bbackupd.conf " + "-Wwarning \"restore Test1 testfiles/restore-symlink\" " + "quit"); + TEST_RETURN(returnValue, + BackupQueries::ReturnCode::Command_OK); + } +>>>>>>> 0.12 // make it accessible again TEST_THAT(chmod(SYM_DIR, 0755) == 0); @@ -1902,6 +2197,7 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD } #endif // !WIN32 @@ -1921,25 +2217,48 @@ int test_bbackupd() TEST_THAT(::system("gzip -d < testfiles/spacetest1.tgz " "| ( cd testfiles/TestDir2 && tar xf - )") == 0); #endif +======= + if (failures) return 1; + } + #endif // !WIN32 + + printf("\n==== Testing that nonexistent locations are backed up " + "if they are created later\n"); + + // ensure that the directory does not exist at the start + TEST_THAT(::system("rm -rf testfiles/TestDir2") == 0); +>>>>>>> 0.12 // BLOCK { // Kill the daemon terminate_bbackupd(bbackupd_pid); +<<<<<<< HEAD // Start it with a config that has a temporary location // that will be created on the server +======= + // Delete any old result marker files + TEST_RETURN(0, system("rm -f testfiles/notifyran.*")); + + // Start it with a config that has a temporary location + // whose path does not exist yet +>>>>>>> 0.12 std::string cmd = BBACKUPD " " + bbackupd_args + " testfiles/bbackupd-temploc.conf"; bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); +<<<<<<< HEAD ::safe_sleep(1); +======= +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD sync_and_wait(); @@ -1958,12 +2277,96 @@ int test_bbackupd() sSocket.Close(); } +======= + if (failures) return 1; + + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-start.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-start.2")); + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.2")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-ok.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2")); + + sync_and_wait(); + TEST_COMPARE(Compare_Same); + + TEST_THAT( TestFileExists("testfiles/notifyran.backup-start.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-start.2")); + TEST_THAT( TestFileExists("testfiles/notifyran.read-error.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.2")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-ok.1")); + TEST_THAT( TestFileExists("testfiles/notifyran.backup-finish.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2")); + + // Did it actually get created? Should not have been! + std::auto_ptr<BackupProtocolClient> client = + ConnectAndLogin(context, + BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> dir = + ReadDirectory(*client); + int64_t testDirId = SearchDir(*dir, "Test2"); + TEST_THAT(testDirId == 0); + client->QueryFinished(); + sSocket.Close(); + } + + // create the location directory and unpack some files into it + TEST_THAT(::mkdir("testfiles/TestDir2", 0777) == 0); + + #ifdef WIN32 + TEST_THAT(::system("tar xzvf testfiles/spacetest1.tgz " + "-C testfiles/TestDir2") == 0); + #else + TEST_THAT(::system("gzip -d < testfiles/spacetest1.tgz " + "| ( cd testfiles/TestDir2 && tar xf - )") == 0); + #endif + + // check that the files are backed up now + sync_and_wait(); + TEST_COMPARE(Compare_Same); + + TEST_THAT( TestFileExists("testfiles/notifyran.backup-start.2")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-start.3")); + TEST_THAT( TestFileExists("testfiles/notifyran.read-error.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.2")); + TEST_THAT( TestFileExists("testfiles/notifyran.backup-ok.1")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-ok.2")); + TEST_THAT( TestFileExists("testfiles/notifyran.backup-finish.2")); + TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.3")); + + // BLOCK + { + std::auto_ptr<BackupProtocolClient> client = + ConnectAndLogin(context, + BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> dir = + ReadDirectory(*client, + BackupProtocolListDirectory::RootDirectory); + int64_t testDirId = SearchDir(*dir, "Test2"); + TEST_THAT(testDirId != 0); + + client->QueryFinished(); + sSocket.Close(); + } + + printf("\n==== Testing that redundant locations are deleted on time\n"); + + // BLOCK + { +>>>>>>> 0.12 // Kill the daemon terminate_bbackupd(bbackupd_pid); // Start it again with the normal config (no Test2) +<<<<<<< HEAD cmd = BBACKUPD " " + bbackupd_args + " testfiles/bbackupd.conf"; +======= + cmd = BBACKUPD " " + bbackupd_args + " testfiles/bbackupd.conf"; +>>>>>>> 0.12 bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); @@ -1974,6 +2377,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Test2 should be deleted after 10 seconds (4 runs) wait_for_sync_end(); @@ -1985,11 +2392,18 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, +<<<<<<< HEAD BackupProtocolClientLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(*client, BackupProtocolClientListDirectory::RootDirectory); +======= + BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> dir = + ReadDirectory(*client); +>>>>>>> 0.12 int64_t testDirId = SearchDir(*dir, "Test2"); TEST_THAT(testDirId != 0); @@ -2004,11 +2418,18 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, +<<<<<<< HEAD BackupProtocolClientLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> root_dir = ReadDirectory(*client, BackupProtocolClientListDirectory::RootDirectory); +======= + BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> root_dir = + ReadDirectory(*client); +>>>>>>> 0.12 TEST_THAT(test_entry_deleted(*root_dir, "Test2")); @@ -2021,11 +2442,20 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD if(bbackupd_pid > 0) { // Check that no read error has been reported yet TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); +======= + if (failures) return 1; + + if(bbackupd_pid > 0) + { + // Delete any old result marker files + TEST_RETURN(0, system("rm -f testfiles/notifyran.*")); +>>>>>>> 0.12 printf("\n==== Check that read-only directories and " "their contents can be restored.\n"); @@ -2073,6 +2503,35 @@ int test_bbackupd() BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +<<<<<<< HEAD +======= + // Try a restore with just the remote directory name, + // check that it uses the same name in the local + // directory. + TEST_THAT(::mkdir("testfiles/restore-test", 0700) == 0); + + compareReturnValue = ::system(BBACKUPQUERY " " + "-Wwarning " + "-c testfiles/bbackupd.conf " + "\"lcd testfiles/restore-test\" " + "\"restore Test1\" " + "quit"); + TEST_RETURN(compareReturnValue, + BackupQueries::ReturnCode::Command_OK); + TestRemoteProcessMemLeaks("testfiles/restore-test/" + "bbackupquery.memleaks"); + + // check that it restored properly + compareReturnValue = ::system(BBACKUPQUERY " " + "-Wwarning " + "-c testfiles/bbackupd.conf " + "\"compare -cEQ Test1 testfiles/restore-test/Test1\" " + "quit"); + TEST_RETURN(compareReturnValue, + BackupQueries::ReturnCode::Compare_Same); + TestRemoteProcessMemLeaks("bbackupquery.memleaks"); + +>>>>>>> 0.12 // put the permissions back to sensible values #ifdef WIN32 TEST_THAT(::system("chmod 0755 testfiles/" @@ -2085,7 +2544,10 @@ int test_bbackupd() TEST_THAT(chmod("testfiles/restore1/x1", 0755) == 0); #endif +<<<<<<< HEAD +======= +>>>>>>> 0.12 } #ifdef WIN32 @@ -2213,11 +2675,15 @@ int test_bbackupd() wait_for_backup_operation("upload of file with unicode name"); // Compare to check that the file was uploaded +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " -Wwarning " "-c testfiles/bbackupd.conf \"compare -acQ\" quit"); TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // Check that we can find it in directory listing { @@ -2225,8 +2691,12 @@ int test_bbackupd() ConnectAndLogin(context, 0); std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory( +<<<<<<< HEAD *client, BackupProtocolClientListDirectory::RootDirectory); +======= + *client); +>>>>>>> 0.12 int64_t baseDirId = SearchDir(*dir, "Test1"); TEST_THAT(baseDirId != 0); @@ -2400,6 +2870,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Check that SyncAllowScript is executed and can " "pause backup\n"); @@ -2470,6 +2944,7 @@ int test_bbackupd() long start_time = time(NULL); // check that no backup has run (compare fails) +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-Werror " "-c testfiles/bbackupd.conf " @@ -2478,6 +2953,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 TEST_THAT(unlink(sync_control_file) == 0); wait_for_sync_start(); @@ -2496,6 +2974,7 @@ int test_bbackupd() TEST_THAT(wait_time <= 12); wait_for_sync_end(); +<<<<<<< HEAD // check that backup has run (compare succeeds) compareReturnValue = ::system(BBACKUPQUERY " " "-Wwarning " @@ -2511,6 +2990,13 @@ int test_bbackupd() // stop early to make debugging easier return 1; } +======= + + // check that backup has run (compare succeeds) + TEST_COMPARE(Compare_Same); + + if (failures) return 1; +>>>>>>> 0.12 } // Check that no read error has been reported yet @@ -2520,6 +3006,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Delete file and update another, " "create symlink.\n"); @@ -2556,6 +3046,7 @@ int test_bbackupd() sync_and_wait(); // compare to make sure that it worked +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " -Wwarning " "-c testfiles/bbackupd.conf " "-l testfiles/query2.log " @@ -2563,6 +3054,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // Try a quick compare, just for fun compareReturnValue = ::system(BBACKUPQUERY " " @@ -2577,12 +3071,17 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Check that store errors are reported neatly printf("\n==== Create store error\n"); TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*") == 0); +<<<<<<< HEAD // break the store TEST_THAT(::rename("testfiles/0_0/backup/01234567/info.rf", "testfiles/0_0/backup/01234567/info.rf.bak") == 0); @@ -2590,6 +3089,40 @@ int test_bbackupd() "testfiles/0_1/backup/01234567/info.rf.bak") == 0); TEST_THAT(::rename("testfiles/0_2/backup/01234567/info.rf", "testfiles/0_2/backup/01234567/info.rf.bak") == 0); +======= + // Break the store. We need a write lock on the account + // while we do this, otherwise housekeeping might be running + // and might rewrite the info files when it finishes, + // undoing our breakage. + std::string errs; + std::auto_ptr<Configuration> config( + Configuration::LoadAndVerify + ("testfiles/bbstored.conf", &BackupConfigFileVerify, errs)); + TEST_EQUAL_LINE(0, errs.size(), "Loading configuration file " + "reported errors: " << errs); + TEST_THAT(config.get() != 0); + // Initialise the raid file controller + RaidFileController &rcontroller(RaidFileController::GetController()); + rcontroller.Initialise(config->GetKeyValue("RaidFileConf").c_str()); + std::auto_ptr<BackupStoreAccountDatabase> db( + BackupStoreAccountDatabase::Read( + config->GetKeyValue("AccountDatabase"))); + + BackupStoreAccounts acc(*db); + + // Lock scope + { + NamedLock writeLock; + acc.LockAccount(0x01234567, writeLock); + + TEST_THAT(::rename("testfiles/0_0/backup/01234567/info.rf", + "testfiles/0_0/backup/01234567/info.rf.bak") == 0); + TEST_THAT(::rename("testfiles/0_1/backup/01234567/info.rf", + "testfiles/0_1/backup/01234567/info.rf.bak") == 0); + TEST_THAT(::rename("testfiles/0_2/backup/01234567/info.rf", + "testfiles/0_2/backup/01234567/info.rf.bak") == 0); + } +>>>>>>> 0.12 // Create a file to trigger an upload { @@ -2618,6 +3151,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 sync_and_wait(); @@ -2637,6 +3174,7 @@ int test_bbackupd() // Check that we DO get errors on compare (cannot do this // until after we fix the store, which creates a race) +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2644,6 +3182,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // Test initial state TEST_THAT(!TestFileExists("testfiles/" @@ -2668,6 +3209,7 @@ int test_bbackupd() "notifyran.backup-start.wait-snapshot.1")); // Should not have backed up, should still get errors +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2675,6 +3217,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // wait another 10 seconds, bbackup should have run wait_for_operation(10, "bbackupd to recover"); @@ -2682,6 +3227,7 @@ int test_bbackupd() "notifyran.backup-start.wait-snapshot.1")); // Check that it did get uploaded, and we have no more errors +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2689,6 +3235,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(::unlink("testfiles/notifyscript.tag") == 0); @@ -2722,6 +3271,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 sync_and_wait(); @@ -2737,6 +3290,7 @@ int test_bbackupd() // Check that we DO get errors on compare (cannot do this // until after we fix the store, which creates a race) +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2744,12 +3298,19 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // Test initial state TEST_THAT(!TestFileExists("testfiles/" "notifyran.backup-start.wait-automatic.1")); +<<<<<<< HEAD // Set a tag for the notify script to distinguist from +======= + // Set a tag for the notify script to distinguish from +>>>>>>> 0.12 // previous runs. { int fd1 = open("testfiles/notifyscript.tag", @@ -2768,6 +3329,7 @@ int test_bbackupd() "notifyran.backup-start.wait-automatic.1")); // Should not have backed up, should still get errors +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2775,6 +3337,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // wait another 10 seconds, bbackup should have run wait_for_operation(10, "bbackupd to recover"); @@ -2782,6 +3347,7 @@ int test_bbackupd() "notifyran.backup-start.wait-automatic.1")); // Check that it did get uploaded, and we have no more errors +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3b.log " @@ -2789,6 +3355,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(::unlink("testfiles/notifyscript.tag") == 0); @@ -2796,6 +3365,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Bad case: delete a file/symlink, replace it with a directory printf("\n==== Replace symlink with directory, " @@ -2821,6 +3394,7 @@ int test_bbackupd() #endif wait_for_backup_operation("bbackupd to sync the changes"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3c.log " @@ -2828,11 +3402,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // And the inverse, replace a directory with a file/symlink printf("\n==== Replace directory with symlink\n"); @@ -2851,6 +3432,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the changes"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3d.log " @@ -2858,11 +3440,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // And then, put it back to how it was before. printf("\n==== Replace symlink with directory " @@ -2884,6 +3473,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the changes"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3e.log " @@ -2891,11 +3481,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // And finally, put it back to how it was before // it was put back to how it was before @@ -2917,6 +3514,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the changes"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3f.log " @@ -2924,11 +3522,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // rename an untracked file over an // existing untracked file @@ -2952,6 +3557,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the " "untracked files"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3g.log " @@ -2959,6 +3565,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 #ifdef WIN32 TEST_THAT(::unlink("testfiles/TestDir1/untracked-2") @@ -2973,6 +3582,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the untracked " "files again"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3g.log " @@ -2980,11 +3590,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // case which went wrong: rename a tracked file over an // existing tracked file @@ -3013,6 +3630,7 @@ int test_bbackupd() sync_and_wait(); // compare to make sure that it worked +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3h.log " @@ -3020,6 +3638,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 #ifdef WIN32 TEST_THAT(::unlink("testfiles/TestDir1/tracked-2") @@ -3034,6 +3655,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync the tracked " "files again"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3i.log " @@ -3041,11 +3663,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // case which went wrong: rename a tracked file // over a deleted file @@ -3056,6 +3685,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3j.log " @@ -3063,6 +3693,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // Check that no read error has been reported yet TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); @@ -3071,6 +3704,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Add files with old times, update " "attributes of one to latest time\n"); @@ -3095,6 +3732,7 @@ int test_bbackupd() // Wait and test wait_for_backup_operation("bbackupd to sync old files"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3k.log " @@ -3102,11 +3740,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Check that no read error has been reported yet TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); @@ -3157,6 +3802,7 @@ int test_bbackupd() wait_for_sync_end(); // files too new wait_for_sync_end(); // should (not) be backed up this time +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3l.log " @@ -3164,11 +3810,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Check that no read error has been reported yet TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1")); @@ -3189,6 +3842,7 @@ int test_bbackupd() wait_for_sync_end(); // compare with exclusions, should not find differences +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3m.log " @@ -3196,6 +3850,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // compare without exclusions, should find differences compareReturnValue = ::system(BBACKUPQUERY " " @@ -3210,6 +3867,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // check that the excluded files did not make it // into the store, and the included files did @@ -3219,11 +3880,18 @@ int test_bbackupd() { std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, +<<<<<<< HEAD BackupProtocolClientLogin::Flags_ReadOnly); std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory( *client, BackupProtocolClientListDirectory::RootDirectory); +======= + BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> dir = + ReadDirectory(*client); +>>>>>>> 0.12 int64_t testDirId = SearchDir(*dir, "Test1"); TEST_THAT(testDirId != 0); @@ -3254,6 +3922,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 #ifndef WIN32 // These tests only work as non-root users. @@ -3279,6 +3951,7 @@ int test_bbackupd() // Wait and test... wait_for_backup_operation("bbackupd to try to sync " "unreadable file"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3o.log " @@ -3288,6 +3961,11 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Error); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + + // should fail with an error due to unreadable file + TEST_COMPARE(Compare_Error); +>>>>>>> 0.12 // Check that it was reported correctly TEST_THAT(TestFileExists("testfiles/notifyran.read-error.1")); @@ -3308,6 +3986,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Continuously update file, " "check isn't uploaded\n"); @@ -3373,6 +4055,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Delete directory, change attributes\n"); @@ -3385,6 +4071,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync deletion " "of directory"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query4.log " @@ -3392,6 +4079,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 printf("\n==== Restore files and directories\n"); int64_t deldirid = 0; @@ -3400,17 +4090,35 @@ int test_bbackupd() // connect and log in std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, +<<<<<<< HEAD BackupProtocolClientLogin::Flags_ReadOnly); // Find the ID of the Test1 directory restoredirid = GetDirID(*client, "Test1", BackupProtocolClientListDirectory::RootDirectory); +======= + BackupProtocolLogin::Flags_ReadOnly); + + // Find the ID of the Test1 directory + restoredirid = GetDirID(*client, "Test1", + BackupProtocolListDirectory::RootDirectory); +>>>>>>> 0.12 TEST_THAT(restoredirid != 0); // Test the restoration TEST_THAT(BackupClientRestore(*client, restoredirid, +<<<<<<< HEAD "Test1", "testfiles/restore-Test1", true /* print progress dots */) +======= + "Test1" /* remote */, + "testfiles/restore-Test1" /* local */, + true /* print progress dots */, + false /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_Complete); // On Win32 we can't open another connection @@ -3419,7 +4127,15 @@ int test_bbackupd() // Make sure you can't restore a restored directory TEST_THAT(BackupClientRestore(*client, restoredirid, "Test1", "testfiles/restore-Test1", +<<<<<<< HEAD true /* print progress dots */) +======= + true /* print progress dots */, + false /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_TargetExists); // Find ID of the deleted directory @@ -3429,9 +4145,18 @@ int test_bbackupd() // Just check it doesn't bomb out -- will check this // properly later (when bbackupd is stopped) TEST_THAT(BackupClientRestore(*client, deldirid, +<<<<<<< HEAD "Test1", "testfiles/restore-Test1-x1", true /* print progress dots */, true /* deleted files */) +======= + "Test1", "testfiles/restore-Test1-x1", + true /* print progress dots */, + true /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_Complete); // Make sure you can't restore to a nonexistant path @@ -3444,7 +4169,15 @@ int test_bbackupd() TEST_THAT(BackupClientRestore(*client, restoredirid, "Test1", "testfiles/no-such-path/subdir", +<<<<<<< HEAD true /* print progress dots */) +======= + true /* print progress dots */, + true /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_TargetPathNotFound); } @@ -3454,6 +4187,7 @@ int test_bbackupd() } // Compare the restored files +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10.log " @@ -3463,11 +4197,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 #ifdef WIN32 // make one of the files read-only, expect a compare failure @@ -3475,6 +4216,7 @@ int test_bbackupd() "testfiles\\restore-Test1\\f1.dat"); TEST_RETURN(compareReturnValue, 0); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10a.log " @@ -3484,12 +4226,16 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // set it back, expect no failures compareReturnValue = ::system("attrib -r " "testfiles\\restore-Test1\\f1.dat"); TEST_RETURN(compareReturnValue, 0); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf -l testfiles/query10a.log " "-Wwarning " @@ -3498,6 +4244,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // change the timestamp on a file, expect a compare failure char* testfile = "testfiles\\restore-Test1\\f1.dat"; @@ -3516,6 +4265,7 @@ int test_bbackupd() // a compare failure TEST_THAT(set_file_time(testfile, dummyTime, lastModTime, lastAccessTime)); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10a.log " @@ -3525,10 +4275,15 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // last access time is not backed up, so it cannot be compared TEST_THAT(set_file_time(testfile, creationTime, lastModTime, dummyTime)); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10a.log " @@ -3538,11 +4293,15 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // last write time is backed up, so changing it should cause // a compare failure TEST_THAT(set_file_time(testfile, creationTime, dummyTime, lastAccessTime)); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10a.log " @@ -3552,10 +4311,14 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 // set back to original values, check that compare succeeds TEST_THAT(set_file_time(testfile, creationTime, lastModTime, lastAccessTime)); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query10a.log " @@ -3565,12 +4328,19 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 #endif // WIN32 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Add files with current time\n"); @@ -3587,6 +4357,7 @@ int test_bbackupd() // Wait and test wait_for_backup_operation("bbackupd to sync new files"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query5.log " @@ -3594,11 +4365,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Rename directory printf("\n==== Rename directory\n"); @@ -3607,6 +4385,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync renamed directory"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query6.log " @@ -3614,6 +4393,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // and again, but with quick flag compareReturnValue = ::system(BBACKUPQUERY " " @@ -3635,6 +4417,7 @@ int test_bbackupd() wait_for_backup_operation("bbackupd to sync renamed files"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query6.log " @@ -3642,11 +4425,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 // Check that modifying files with madly in the future // timestamps still get added @@ -3678,6 +4468,7 @@ int test_bbackupd() // Wait and test wait_for_backup_operation("bbackup to sync future file"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query3e.log " @@ -3685,11 +4476,18 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Change client store marker\n"); @@ -3707,7 +4505,11 @@ int test_bbackupd() // Make sure the marker isn't zero, // because that's the default, and // it should have changed +<<<<<<< HEAD std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol->QueryLogin(0x01234567, 0)); +======= + std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol->QueryLogin(0x01234567, 0)); +>>>>>>> 0.12 TEST_THAT(loginConf->GetClientStoreMarker() != 0); // Change it to something else @@ -3732,6 +4534,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Check change of store marker pauses daemon\n"); @@ -3749,6 +4555,7 @@ int test_bbackupd() 3) / 2, "bbackupd to detect changed store marker"); // Test that there *are* differences +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query6.log " @@ -3756,19 +4563,35 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Different); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Different); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD // 100 seconds - (12*3/2) wait_for_operation(82, "bbackupd to recover"); +======= + if (failures) return 1; + + wait_for_operation(100, "bbackupd to recover"); + + // Then check it has backed up successfully. + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 #ifndef WIN32 printf("\n==== Interrupted restore\n"); @@ -3785,28 +4608,48 @@ int test_bbackupd() std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(context, +<<<<<<< HEAD BackupProtocolClientLogin::Flags_ReadOnly); +======= + BackupProtocolLogin::Flags_ReadOnly); +>>>>>>> 0.12 // Check that the restore fn returns resume possible, // rather than doing anything TEST_THAT(BackupClientRestore(*client, restoredirid, "Test1", "testfiles/restore-interrupt", +<<<<<<< HEAD true /* print progress dots */) +======= + true /* print progress dots */, + false /* restore deleted */, + false /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_ResumePossible); // Then resume it TEST_THAT(BackupClientRestore(*client, restoredirid, "Test1", "testfiles/restore-interrupt", true /* print progress dots */, +<<<<<<< HEAD false /* deleted files */, false /* undelete server */, true /* resume */) +======= + false /* restore deleted */, + false /* undelete after */, + true /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_Complete); client->QueryFinished(); sSocket.Close(); // Then check it has restored the correct stuff +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query14.log " @@ -3815,6 +4658,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 } #endif // !WIN32 @@ -3822,6 +4668,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 printf("\n==== Check restore deleted files\n"); @@ -3834,7 +4684,13 @@ int test_bbackupd() "Test1", "testfiles/restore-Test1-x1-2", true /* print progress dots */, true /* deleted files */, +<<<<<<< HEAD true /* undelete on server */) +======= + true /* undelete after */, + false /* resume */, + false /* keep going */) +>>>>>>> 0.12 == Restore_Complete); client->QueryFinished(); @@ -3860,6 +4716,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 #ifdef WIN32 printf("\n==== Testing locked file behaviour:\n"); @@ -3886,6 +4746,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if (handle != 0) { @@ -3902,6 +4766,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if (handle != 0) { @@ -3919,11 +4787,16 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if (handle != 0) { // compare, and check that it works // reports the correct error message (and finishes) +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query15a.log " @@ -3931,12 +4804,19 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_THAT(compare_all(false)); +>>>>>>> 0.12 } TEST_THAT(ServerIsAlive(bbackupd_pid)); TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if (handle != 0) { @@ -3946,6 +4826,7 @@ int test_bbackupd() O_LOCK, 0); TEST_THAT(handle != INVALID_HANDLE_VALUE); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query15.log " @@ -3953,6 +4834,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Error); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Error); +>>>>>>> 0.12 // close the file again, check that compare // works again @@ -3963,6 +4847,7 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD if (handle != 0) { @@ -3973,6 +4858,13 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + if (failures) return 1; + + if (handle != 0) + { + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 } #endif @@ -3990,6 +4882,10 @@ int test_bbackupd() TEST_THAT(ServerIsAlive(bbstored_pid)); if (!ServerIsAlive(bbackupd_pid)) return 1; if (!ServerIsAlive(bbstored_pid)) return 1; +<<<<<<< HEAD +======= + if (failures) return 1; +>>>>>>> 0.12 if(bbackupd_pid != -1 && bbackupd_pid != 0) { @@ -3997,6 +4893,7 @@ int test_bbackupd() wait_for_operation( (TIME_TO_WAIT_FOR_BACKUP_OPERATION*3) / 2, "bbackupd to sync everything"); +<<<<<<< HEAD compareReturnValue = ::system(BBACKUPQUERY " " "-c testfiles/bbackupd.conf " "-l testfiles/query4a.log " @@ -4004,6 +4901,9 @@ int test_bbackupd() TEST_RETURN(compareReturnValue, BackupQueries::ReturnCode::Compare_Same); TestRemoteProcessMemLeaks("bbackupquery.memleaks"); +======= + TEST_COMPARE(Compare_Same); +>>>>>>> 0.12 // Kill it again terminate_bbackupd(bbackupd_pid); @@ -4030,6 +4930,22 @@ int test_bbackupd() int test(int argc, const char *argv[]) { +<<<<<<< HEAD +======= + { + BackupDaemon daemon; + + TEST_EQUAL(1234, daemon.ParseSyncAllowScriptOutput("test", "1234")); + TEST_EQUAL(0, daemon.GetMaxBandwidthFromSyncAllowScript()); + + TEST_EQUAL(1234, daemon.ParseSyncAllowScriptOutput("test", "1234 5")); + TEST_EQUAL(5, daemon.GetMaxBandwidthFromSyncAllowScript()); + + TEST_EQUAL(-1, daemon.ParseSyncAllowScriptOutput("test", "now")); + TEST_EQUAL(0, daemon.GetMaxBandwidthFromSyncAllowScript()); + } + +>>>>>>> 0.12 // SSL library SSLLib::Initialise(); diff --git a/test/bbackupd/testfiles/bbackupd-temploc.conf.in b/test/bbackupd/testfiles/bbackupd-temploc.conf.in new file mode 100644 index 00000000..d4e0d1b3 --- /dev/null +++ b/test/bbackupd/testfiles/bbackupd-temploc.conf.in @@ -0,0 +1,58 @@ + +CertificateFile = testfiles/clientCerts.pem +PrivateKeyFile = testfiles/clientPrivKey.pem +TrustedCAsFile = testfiles/clientTrustedCAs.pem + +KeysFile = testfiles/bbackupd.keys + +DataDirectory = testfiles/bbackupd-data + +StoreHostname = localhost +StorePort = 22011 +AccountNumber = 0x01234567 + +AutomaticBackup = no +UpdateStoreInterval = 3 +MinimumFileAge = 4 +MaxUploadWait = 24 + +FileTrackingSizeThreshold = 1024 +DiffingUploadSizeThreshold = 1024 + +MaximumDiffingTime = 3 +KeepAliveTime = 1 + +ExtendedLogging = no +ExtendedLogFile = testfiles/bbackupd.log + +CommandSocket = testfiles/bbackupd.sock + +NotifyScript = @TARGET_PERL@ testfiles/notifyscript.pl + +Server +{ + PidFile = testfiles/bbackupd.pid +} + +BackupLocations +{ + Test1 + { + Path = testfiles/TestDir1 + + ExcludeFile = testfiles/TestDir1/excluded_1 + ExcludeFile = testfiles/TestDir1/excluded_2 + ExcludeFilesRegex = \.excludethis$ + ExcludeFilesRegex = EXCLUDE + AlwaysIncludeFile = testfiles/TestDir1/dont.excludethis + ExcludeDir = testfiles/TestDir1/exclude_dir + ExcludeDir = testfiles/TestDir1/exclude_dir_2 + ExcludeDirsRegex = not_this_dir + AlwaysIncludeDirsRegex = ALWAYSINCLUDE + } + Test2 + { + Path = testfiles/TestDir2 + } +} + diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp index e633969b..2d4b7431 100644 --- a/test/common/testcommon.cpp +++ b/test/common/testcommon.cpp @@ -332,9 +332,15 @@ int test(int argc, const char *argv[]) Timers::Init(); Timer t0(0, "t0"); // should never expire +<<<<<<< HEAD Timer t1(1, "t1"); Timer t2(2, "t2"); Timer t3(3, "t3"); +======= + Timer t1(1000, "t1"); + Timer t2(2000, "t2"); + Timer t3(3000, "t3"); +>>>>>>> 0.12 TEST_THAT(!t0.HasExpired()); TEST_THAT(!t1.HasExpired()); @@ -352,12 +358,23 @@ int test(int argc, const char *argv[]) TEST_THAT(t1.HasExpired()); TEST_THAT(t2.HasExpired()); TEST_THAT(!t3.HasExpired()); +<<<<<<< HEAD t1 = Timer(1, "t1a"); t2 = Timer(2, "t2a"); TEST_THAT(!t0.HasExpired()); TEST_THAT(!t1.HasExpired()); TEST_THAT(!t2.HasExpired()); +======= + + // Try both ways of resetting an existing timer. + t1 = Timer(1000, "t1a"); + t2.Reset(2000); + TEST_THAT(!t0.HasExpired()); + TEST_THAT(!t1.HasExpired()); + TEST_THAT(!t2.HasExpired()); + TEST_THAT(!t3.HasExpired()); +>>>>>>> 0.12 safe_sleep(1); TEST_THAT(!t0.HasExpired()); @@ -365,6 +382,15 @@ int test(int argc, const char *argv[]) TEST_THAT(!t2.HasExpired()); TEST_THAT(t3.HasExpired()); +<<<<<<< HEAD +======= + safe_sleep(1); + TEST_THAT(!t0.HasExpired()); + TEST_THAT(t1.HasExpired()); + TEST_THAT(t2.HasExpired()); + TEST_THAT(t3.HasExpired()); + +>>>>>>> 0.12 // Leave timers initialised for rest of test. // Test main() will cleanup after test finishes. @@ -404,8 +430,15 @@ int test(int argc, const char *argv[]) { TEST_THAT(!getline.IsEOF()); std::string line = getline.GetLine(true); +<<<<<<< HEAD //printf("expected |%s| got |%s|\n", lines[l], line.c_str()); TEST_THAT(strcmp(testfilelines[l], line.c_str()) == 0); +======= + printf("expected |%s| got |%s|\n", testfilelines[l], + line.c_str()); + TEST_LINE(strcmp(testfilelines[l], line.c_str()) == 0, + line); +>>>>>>> 0.12 l++; } TEST_THAT(getline.IsEOF()); @@ -455,8 +488,15 @@ int test(int argc, const char *argv[]) std::string line; while(!getline.GetLine(line, true)) ; +<<<<<<< HEAD //printf("expected |%s| got |%s|\n", lines[l], line.c_str()); TEST_THAT(strcmp(testfilelines[l], line.c_str()) == 0); +======= + printf("expected |%s| got |%s|\n", testfilelines[l], + line.c_str()); + TEST_LINE(strcmp(testfilelines[l], line.c_str()) == 0, + line); +>>>>>>> 0.12 l++; } TEST_THAT(getline.IsEOF()); |