summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-07-01 19:40:41 +0000
committerChris Wilson <chris+github@qwirx.com>2015-07-01 19:40:41 +0000
commita834d2e9ff08343d3df5a466f41d0c3e7072a984 (patch)
treed88f16f40a76fd2d75818d6993df58851b240bc0
parentfb9042ed02544a1a783b2ffa6b5ea7e85a16a703 (diff)
Major test refactor to support test suites.
Refactor all common code from testbbackupd and testbackupstore to allow other test suites to contain multiple tests and execute selected tests more easily. Report all test results within a suite in a standard, easy to read summary.
-rw-r--r--infrastructure/buildenv-testmain-template.cpp13
-rw-r--r--lib/backupstore/StoreTestUtils.cpp111
-rw-r--r--lib/common/Test.cpp124
-rw-r--r--lib/common/Test.h47
-rw-r--r--test/backupstore/testbackupstore.cpp137
-rw-r--r--test/backupstorefix/testbackupstorefix.cpp2
-rw-r--r--test/bbackupd/testbbackupd.cpp170
7 files changed, 301 insertions, 303 deletions
diff --git a/infrastructure/buildenv-testmain-template.cpp b/infrastructure/buildenv-testmain-template.cpp
index 09be9f70..6855e990 100644
--- a/infrastructure/buildenv-testmain-template.cpp
+++ b/infrastructure/buildenv-testmain-template.cpp
@@ -61,11 +61,6 @@ int test(int argc, const char *argv[]);
#define MODE_TEXT "debug"
#endif
-int failures = 0;
-int first_fail_line;
-std::string first_fail_file;
-std::list<std::string> run_only_named_tests;
-
#ifdef WIN32
#define QUIET_PROCESS "-Q"
#else
@@ -386,7 +381,7 @@ int main(int argc, char * const * argv)
#ifdef BOX_MEMORY_LEAK_TESTING
if(memleakfinder_numleaks() != 0)
{
- failures++;
+ num_failures++;
printf("FAILURE: Memory leaks detected in test code\n");
printf("==== MEMORY LEAKS =================================\n");
memleakfinder_reportleaks();
@@ -405,13 +400,13 @@ int main(int argc, char * const * argv)
if(filesleftopen)
{
- failures++;
+ num_failures++;
printf("IMPLICIT TEST FAILED: Something left files open\n");
}
- if(failures > 0)
+ if(num_failures > 0)
{
printf("FAILED: %d tests failed (first at "
- "%s:%d)\n", failures,
+ "%s:%d)\n", num_failures,
first_fail_file.c_str(),
first_fail_line);
}
diff --git a/lib/backupstore/StoreTestUtils.cpp b/lib/backupstore/StoreTestUtils.cpp
index e0709876..1c98ef98 100644
--- a/lib/backupstore/StoreTestUtils.cpp
+++ b/lib/backupstore/StoreTestUtils.cpp
@@ -55,96 +55,6 @@ bool delete_account()
std::vector<uint32_t> ExpectedRefCounts;
int bbstored_pid = 0, bbackupd_pid = 0;
-std::string OriginalWorkingDir;
-
-bool setUp(const char* function_name)
-{
- if (!run_only_named_tests.empty())
- {
- bool run_this_test = false;
-
- for (std::list<std::string>::iterator
- i = run_only_named_tests.begin();
- i != run_only_named_tests.end(); i++)
- {
- if (*i == function_name)
- {
- run_this_test = true;
- break;
- }
- }
-
- if (!run_this_test)
- {
- // not in the list, so don't run it.
- return false;
- }
- }
-
- printf("\n\n== %s ==\n", function_name);
-
- if (ServerIsAlive(bbstored_pid))
- {
- StopServer();
- }
-
- if (OriginalWorkingDir == "")
- {
- char buf[1024];
- if (getcwd(buf, sizeof(buf)) == NULL)
- {
- BOX_LOG_SYS_ERROR("getcwd");
- }
- OriginalWorkingDir = buf;
- }
- else
- {
- if (chdir(OriginalWorkingDir.c_str()) != 0)
- {
- BOX_LOG_SYS_ERROR("chdir");
- }
- }
-
- TEST_THAT_THROWONFAIL(system(
- "rm -rf testfiles/TestDir* testfiles/0_0 testfiles/0_1 "
- "testfiles/0_2 testfiles/accounts.txt " // testfiles/test* .tgz!
- "testfiles/file* testfiles/notifyran testfiles/notifyran.* "
- "testfiles/notifyscript.tag* "
- "testfiles/restore* testfiles/bbackupd-data "
- "testfiles/syncallowscript.control "
- "testfiles/syncallowscript.notifyran.* "
- "testfiles/test2.downloaded"
- ) == 0);
- TEST_THAT_THROWONFAIL(mkdir("testfiles/0_0", 0755) == 0);
- TEST_THAT_THROWONFAIL(mkdir("testfiles/0_1", 0755) == 0);
- TEST_THAT_THROWONFAIL(mkdir("testfiles/0_2", 0755) == 0);
- TEST_THAT_THROWONFAIL(mkdir("testfiles/bbackupd-data", 0755) == 0);
- TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0);
- TEST_THAT_THROWONFAIL(create_account(10000, 20000));
-
- ExpectedRefCounts.resize(BACKUPSTORE_ROOT_DIRECTORY_ID + 1);
- set_refcount(BACKUPSTORE_ROOT_DIRECTORY_ID, 1);
-
- return true;
-}
-
-bool tearDown()
-{
- bool status = true;
-
- if (ServerIsAlive(bbstored_pid))
- {
- TEST_THAT_OR(StopServer(), status = false);
- }
-
- return status;
-}
-
-bool fail()
-{
- TEST_THAT(tearDown());
- return false;
-}
void set_refcount(int64_t ObjectID, uint32_t RefCount)
{
@@ -367,18 +277,21 @@ bool StartServer()
TEST_THAT_OR(bbstored_pid != -1 && bbstored_pid != 0, return false);
::sleep(1);
- TEST_THAT_OR(ServerIsAlive(bbstored_pid), return false);
+ TEST_THAT_OR(ServerIsAlive(bbstored_pid), bbstored_pid = 0; return false);
return true;
}
bool StopServer(bool wait_for_process)
{
TEST_THAT_OR(bbstored_pid != 0, return false);
- TEST_THAT_OR(ServerIsAlive(bbstored_pid), return false);
- TEST_THAT_OR(KillServer(bbstored_pid, wait_for_process), return false);
+ TEST_THAT_OR(ServerIsAlive(bbstored_pid),
+ bbstored_pid = 0; return false);
+ TEST_THAT_OR(KillServer(bbstored_pid, wait_for_process),
+ bbstored_pid = 0; return false);
::sleep(1);
- TEST_THAT_OR(!ServerIsAlive(bbstored_pid), return false);
+ TEST_THAT_OR(!ServerIsAlive(bbstored_pid),
+ bbstored_pid = 0; return false);
bbstored_pid = 0;
#ifdef WIN32
@@ -395,16 +308,6 @@ bool StopServer(bool wait_for_process)
return true;
}
-#define FAIL { \
- /* \
- std::ostringstream os; \
- os << "failed at " << __FUNCTION__ << ":" << __LINE__; \
- s_test_status[current_test_name] = os.str(); \
- return fail(); \
- */ \
- return false; \
-}
-
bool StartClient(const std::string& bbackupd_conf_file)
{
TEST_THAT_OR(bbackupd_pid == 0, FAIL);
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index e3ead614..ba99d496 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -24,6 +24,122 @@
#include "BoxTime.h"
#include "Test.h"
+int num_tests_selected = 0;
+int num_failures = 0;
+int old_failure_count = 0;
+int first_fail_line;
+std::string original_working_dir;
+std::string first_fail_file;
+std::string current_test_name;
+std::list<std::string> run_only_named_tests;
+std::map<std::string, std::string> s_test_status;
+
+bool setUp(const char* function_name)
+{
+ current_test_name = function_name;
+
+ if (!run_only_named_tests.empty())
+ {
+ bool run_this_test = false;
+
+ for (std::list<std::string>::iterator
+ i = run_only_named_tests.begin();
+ i != run_only_named_tests.end(); i++)
+ {
+ if (*i == current_test_name)
+ {
+ run_this_test = true;
+ break;
+ }
+ }
+
+ if (!run_this_test)
+ {
+ // not in the list, so don't run it.
+ return false;
+ }
+ }
+
+ printf("\n\n== %s ==\n", function_name);
+ num_tests_selected++;
+ old_failure_count = num_failures;
+
+ if (original_working_dir == "")
+ {
+ char buf[1024];
+ if (getcwd(buf, sizeof(buf)) == NULL)
+ {
+ BOX_LOG_SYS_ERROR("getcwd");
+ }
+ original_working_dir = buf;
+ }
+ else
+ {
+ if (chdir(original_working_dir.c_str()) != 0)
+ {
+ BOX_LOG_SYS_ERROR("chdir");
+ }
+ }
+
+ TEST_THAT_THROWONFAIL(system(
+ "rm -rf testfiles/TestDir* testfiles/0_0 testfiles/0_1 "
+ "testfiles/0_2 testfiles/accounts.txt " // testfiles/test* .tgz!
+ "testfiles/file* testfiles/notifyran testfiles/notifyran.* "
+ "testfiles/notifyscript.tag* "
+ "testfiles/restore* testfiles/bbackupd-data "
+ "testfiles/syncallowscript.control "
+ "testfiles/syncallowscript.notifyran.* "
+ "testfiles/test2.downloaded"
+ ) == 0);
+ TEST_THAT_THROWONFAIL(mkdir("testfiles/0_0", 0755) == 0);
+ TEST_THAT_THROWONFAIL(mkdir("testfiles/0_1", 0755) == 0);
+ TEST_THAT_THROWONFAIL(mkdir("testfiles/0_2", 0755) == 0);
+ TEST_THAT_THROWONFAIL(mkdir("testfiles/bbackupd-data", 0755) == 0);
+ TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0);
+
+ return true;
+}
+
+bool tearDown()
+{
+ if (num_failures == old_failure_count)
+ {
+ BOX_NOTICE(current_test_name << " passed");
+ s_test_status[current_test_name] = "passed";
+ return true;
+ }
+ else
+ {
+ BOX_NOTICE(current_test_name << " failed"); \
+ s_test_status[current_test_name] = "FAILED";
+ return false;
+ }
+}
+
+bool fail()
+{
+ num_failures++;
+ return tearDown();
+}
+
+int finish_test_suite()
+{
+ printf("\n");
+ printf("Test results:\n");
+
+ typedef std::map<std::string, std::string>::iterator s_test_status_iterator;
+ for(s_test_status_iterator i = s_test_status.begin();
+ i != s_test_status.end(); i++)
+ {
+ BOX_NOTICE("test result: " << i->second << ": " << i->first);
+ }
+
+ TEST_LINE(num_tests_selected > 0, "No tests matched the patterns "
+ "specified on the command line");
+
+ return (num_failures == 0 && num_tests_selected > 0) ? 0 : 1;
+}
+
bool TestFileExists(const char *Filename)
{
EMU_STRUCT_STAT st;
@@ -287,12 +403,12 @@ void TestRemoteProcessMemLeaksFunc(const char *filename,
// Does the file exist?
if(!TestFileExists(filename))
{
- if (failures == 0)
+ if (num_failures == 0)
{
first_fail_file = file;
first_fail_line = line;
}
- ++failures;
+ ++num_failures;
printf("FAILURE: MemLeak report not available (file %s) "
"at %s:%d\n", filename, file, line);
}
@@ -301,12 +417,12 @@ void TestRemoteProcessMemLeaksFunc(const char *filename,
// Is it empty?
if(TestGetFileSize(filename) > 0)
{
- if (failures == 0)
+ if (num_failures == 0)
{
first_fail_file = file;
first_fail_line = line;
}
- ++failures;
+ ++num_failures;
printf("FAILURE: Memory leaks found in other process "
"(file %s) at %s:%d\n==========\n",
filename, file, line);
diff --git a/lib/common/Test.h b/lib/common/Test.h
index c529332b..a69fdae8 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -12,6 +12,7 @@
#include <cstring>
#include <list>
+#include <map>
#ifdef WIN32
#define BBACKUPCTL "..\\..\\bin\\bbackupctl\\bbackupctl.exe"
@@ -29,20 +30,48 @@
#define TEST_RETURN(actual, expected) TEST_EQUAL((expected << 8), actual);
#endif
-extern int failures;
+extern int num_failures;
extern int first_fail_line;
extern std::string first_fail_file;
extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
extern std::list<std::string> run_only_named_tests;
+extern std::string current_test_name;
+extern std::map<std::string, std::string> s_test_status;
+
+//! Simplifies calling setUp() with the current function name in each test.
+#define SETUP() \
+ if (!setUp(__FUNCTION__)) return true; \
+ try \
+ { // left open for TEARDOWN()
+
+#define TEARDOWN() \
+ return tearDown(); \
+ } \
+ catch (BoxException &e) \
+ { \
+ BOX_NOTICE(__FUNCTION__ << " errored: " << e.what()); \
+ num_failures++; \
+ tearDown(); \
+ s_test_status[__FUNCTION__] = "ERRORED"; \
+ return false; \
+ }
+
+//! End the current test. Only use within a test function, because it just returns false!
+#define FAIL { \
+ std::ostringstream os; \
+ os << "failed at " << __FUNCTION__ << ":" << __LINE__; \
+ s_test_status[current_test_name] = os.str(); \
+ return fail(); \
+}
#define TEST_FAIL_WITH_MESSAGE(msg) \
{ \
- if (failures == 0) \
+ if (num_failures == 0) \
{ \
first_fail_file = __FILE__; \
first_fail_line = __LINE__; \
} \
- failures++; \
+ num_failures++; \
BOX_ERROR("**** TEST FAILURE: " << msg << " at " << __FILE__ << \
":" << __LINE__); \
}
@@ -168,6 +197,18 @@ extern std::list<std::string> run_only_named_tests;
#define TEST_STARTSWITH(expected, actual) \
TEST_EQUAL_LINE(expected, actual.substr(0, std::string(expected).size()), actual);
+//! Sets up (cleans up) test environment at the start of every test.
+bool setUp(const char* function_name);
+
+//! Checks account for errors and shuts down daemons at end of every test.
+bool tearDown();
+
+//! Like tearDown() but returns false, because a test failure was detected.
+bool fail();
+
+//! Report final status of all tests, and return the correct value to test main().
+int finish_test_suite();
+
bool TestFileExists(const char *Filename);
bool TestDirExists(const char *Filename);
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp
index 35e4ae6f..fadbc7ad 100644
--- a/test/backupstore/testbackupstore.cpp
+++ b/test/backupstore/testbackupstore.cpp
@@ -140,6 +140,35 @@ static const char *uploads_filenames[] = {"49587fds", "cvhjhj324", "sdfcscs324",
#define UNLINK_IF_EXISTS(filename) \
if (FileExists(filename)) { TEST_THAT(unlink(filename) == 0); }
+//! Simplifies calling setUp() with the current function name in each test.
+#define SETUP_TEST_BACKUPSTORE() \
+ SETUP(); \
+ if (ServerIsAlive(bbstored_pid)) \
+ TEST_THAT_OR(StopServer(), FAIL); \
+ ExpectedRefCounts.resize(BACKUPSTORE_ROOT_DIRECTORY_ID + 1); \
+ set_refcount(BACKUPSTORE_ROOT_DIRECTORY_ID, 1); \
+ TEST_THAT_OR(create_account(10000, 20000), FAIL);
+
+//! Checks account for errors and shuts down daemons at end of every test.
+bool teardown_test_backupstore()
+{
+ bool status = true;
+
+ if (FileExists("testfiles/0_0/backup/01234567/info.rf"))
+ {
+ TEST_THAT_OR(check_reference_counts(), status = false);
+ TEST_THAT_OR(check_account(), status = false);
+ }
+
+ return status;
+}
+
+#define TEARDOWN_TEST_BACKUPSTORE() \
+ if (ServerIsAlive(bbstored_pid)) \
+ StopServer(); \
+ TEST_THAT(teardown_test_backupstore()); \
+ TEARDOWN();
+
// Nice random data for testing written files
class R250 {
public:
@@ -239,36 +268,9 @@ void CheckEntries(BackupStoreDirectory &rDir, int16_t FlagsMustBeSet, int16_t Fl
TEST_THAT(DIR_NUM == SkipEntries(e, FlagsMustBeSet, FlagsNotToBeSet));
}
-int num_tests_selected = 0;
-
-//! Simplifies calling setUp() with the current function name in each test.
-#define SETUP() \
- if (!setUp(__FUNCTION__)) return true; \
- num_tests_selected++;
-
-//! Checks account for errors and shuts down daemons at end of every test.
-bool teardown_test_backupstore()
-{
- bool status = tearDown();
-
- if (FileExists("testfiles/0_0/backup/01234567/info.rf"))
- {
- TEST_THAT_OR(check_reference_counts(), status = false);
- TEST_THAT_OR(check_account(), status = false);
- }
-
- return status;
-}
-
-#define FAIL { \
- std::ostringstream os; \
- os << "failed at " << __FUNCTION__ << ":" << __LINE__; \
- return fail(); \
-}
-
bool test_filename_encoding()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// test some basics -- encoding and decoding filenames
{
@@ -349,12 +351,12 @@ bool test_filename_encoding()
}
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_backupstore_directory()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
{
// Now play with directories
@@ -435,7 +437,7 @@ bool test_backupstore_directory()
}
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
void write_test_file(int t)
@@ -798,7 +800,7 @@ bool run_housekeeping_and_check_account(BackupProtocolLocal2& protocol)
bool test_temporary_refcount_db_is_independent()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
BackupStoreAccountDatabase::Read("testfiles/accounts.txt"));
@@ -826,12 +828,12 @@ bool test_temporary_refcount_db_is_independent()
// test failure.
perm.reset();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_server_housekeeping()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
int encfile[ENCFILE_SIZE];
{
@@ -1161,7 +1163,7 @@ bool test_server_housekeeping()
TEST_THAT(run_housekeeping_and_check_account());
ExpectedRefCounts.resize(3); // stop test failure in teardown_test_backupstore()
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
int64_t create_directory(BackupProtocolCallable& protocol, int64_t parent_dir_id)
@@ -1239,7 +1241,7 @@ int64_t assert_readonly_connection_succeeds(BackupProtocolCallable& protocol)
bool test_multiple_uploads()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
TEST_THAT_OR(StartServer(), FAIL);
std::auto_ptr<BackupProtocolCallable> apProtocol =
@@ -1512,12 +1514,12 @@ bool test_multiple_uploads()
apProtocol->QueryFinished();
protocolReadOnly.QueryFinished();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_server_commands()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
std::auto_ptr<BackupProtocolLocal2> apProtocol(
new BackupProtocolLocal2(0x01234567, "test",
@@ -1971,7 +1973,7 @@ bool test_server_commands()
TEST_THAT(check_reference_counts());
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
int get_object_size(BackupProtocolCallable& protocol, int64_t ObjectID,
@@ -2004,7 +2006,7 @@ bool write_dir(BackupStoreDirectory& dir)
bool test_directory_parent_entry_tracks_directory_size()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
BackupProtocolLocal2 protocol(0x01234567, "test", "backup/01234567/",
0, false);
@@ -2163,12 +2165,12 @@ bool test_directory_parent_entry_tracks_directory_size()
BACKUPSTORE_ROOT_DIRECTORY_ID));
protocolReadOnly.QueryFinished();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_cannot_open_multiple_writable_connections()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// First try a local protocol. This works even on Windows.
BackupProtocolLocal2 protocolWritable(0x01234567, "test",
@@ -2207,7 +2209,7 @@ bool test_cannot_open_multiple_writable_connections()
}
protocolWritable.QueryFinished();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_encoding()
@@ -2216,7 +2218,7 @@ bool test_encoding()
// TODO: This test needs to check failure situations as well as everything working,
// but this will be saved for the full implementation.
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
int encfile[ENCFILE_SIZE];
{
@@ -2367,13 +2369,13 @@ bool test_encoding()
}
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_symlinks()
{
#ifndef WIN32 // no symlinks on Win32
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// TODO FIXME indentation
@@ -2397,12 +2399,12 @@ bool test_symlinks()
teardown_test_backupstore();
#endif
- return true;
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_store_info()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
{
RaidFileWrite::CreateDirectory(0, "test-info");
@@ -2451,14 +2453,14 @@ bool test_store_info()
TEST_THAT(delfiles[1] == 4);
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_login_without_account()
{
// First, try logging in without an account having been created... just make sure login fails.
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
delete_account();
TEST_THAT_OR(StartServer(), FAIL);
@@ -2482,12 +2484,12 @@ bool test_login_without_account()
// Recreate the account so that teardown_test_backupstore() doesn't freak out
// TEST_THAT_THROWONFAIL(create_account(10000, 20000));
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_bbstoreaccounts_create()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// Delete the account, and create it again using bbstoreaccounts
delete_account();
@@ -2497,12 +2499,12 @@ bool test_bbstoreaccounts_create()
"10000B 20000B") == 0, FAIL);
TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_bbstoreaccounts_delete()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
TEST_THAT_OR(::system(BBSTOREACCOUNTS
" -c testfiles/bbstored.conf -Wwarning delete 01234567 yes") == 0, FAIL);
TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
@@ -2510,13 +2512,13 @@ bool test_bbstoreaccounts_delete()
// Recreate the account so that teardown_test_backupstore() doesn't freak out
TEST_THAT(create_account(10000, 20000));
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
// Test that login fails on a disabled account
bool test_login_with_disabled_account()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
TEST_THAT_OR(StartServer(), FAIL);
TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567"));
@@ -2557,12 +2559,12 @@ bool test_login_with_disabled_account()
protocol.QueryFinished();
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_login_with_no_refcount_db()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// The account is already enabled, but doing it again shouldn't hurt
TEST_THAT_OR(::system(BBSTOREACCOUNTS
@@ -2612,14 +2614,14 @@ bool test_login_with_no_refcount_db()
// And that we can log in afterwards
connect_and_login(context)->QueryFinished();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_housekeeping_deletes_files()
{
// Test the deletion of objects by the housekeeping system
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
BackupProtocolLocal2 protocolLocal(0x01234567, "test",
"backup/01234567/", 0, false); // Not read-only
@@ -2669,12 +2671,12 @@ bool test_housekeeping_deletes_files()
// catches if we don't delete the account.
delete_account();
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
bool test_account_limits_respected()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
TEST_THAT_OR(StartServer(), FAIL);
// Set a really small hard limit
@@ -2717,7 +2719,7 @@ bool test_account_limits_respected()
apProtocol->QueryFinished();
}
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
int multi_server()
@@ -2858,7 +2860,7 @@ void compare_backupstoreinfo_values_to_expected
bool test_read_old_backupstoreinfo_files()
{
- SETUP();
+ SETUP_TEST_BACKUPSTORE();
// Create an account for the test client
std::auto_ptr<BackupStoreInfo> apInfo = BackupStoreInfo::Load(0x1234567,
@@ -3060,7 +3062,7 @@ bool test_read_old_backupstoreinfo_files()
apInfo.reset();
TEST_THAT(delete_account());
- return teardown_test_backupstore();
+ TEARDOWN_TEST_BACKUPSTORE();
}
int test(int argc, const char *argv[])
@@ -3130,9 +3132,6 @@ int test(int argc, const char *argv[])
TEST_THAT(test_multiple_uploads());
TEST_THAT(test_housekeeping_deletes_files());
- TEST_LINE(num_tests_selected > 0, "No tests matched the patterns "
- "specified on the command line");
-
- return (failures == 0 && num_tests_selected > 0) ? 0 : 1;
+ return finish_test_suite();
}
diff --git a/test/backupstorefix/testbackupstorefix.cpp b/test/backupstorefix/testbackupstorefix.cpp
index d13563d9..a39ca60a 100644
--- a/test/backupstorefix/testbackupstorefix.cpp
+++ b/test/backupstorefix/testbackupstorefix.cpp
@@ -582,8 +582,6 @@ int test(int argc, const char *argv[])
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 "
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index 496c84f7..69046f0f 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -93,16 +93,6 @@
#define SHORT_TIMEOUT 5000
#define BACKUP_ERROR_DELAY_SHORTENED 10
-std::string current_test_name;
-std::map<std::string, std::string> s_test_status;
-
-#define FAIL { \
- std::ostringstream os; \
- os << "failed at " << __FUNCTION__ << ":" << __LINE__; \
- s_test_status[current_test_name] = os.str(); \
- return fail(); \
-}
-
void wait_for_backup_operation(const char* message)
{
wait_for_operation(TIME_TO_WAIT_FOR_BACKUP_OPERATION, message);
@@ -465,66 +455,32 @@ bool setup_test_bbackupd(BackupDaemon& bbackupd, bool do_unpack_files = true,
return true;
}
-int num_tests_selected = 0;
-
//! Simplifies calling setUp() with the current function name in each test.
-#define SETUP() \
- if (!setUp(__FUNCTION__)) return true; \
- num_tests_selected++; \
- int old_failure_count = failures; \
+#define SETUP_TEST_BBACKUPD() \
+ SETUP(); \
TEST_THAT(kill_running_daemons()); \
- try \
- { // left open
+ TEST_THAT(create_account(10000, 20000));
#define SETUP_WITHOUT_FILES() \
- SETUP() \
+ SETUP_TEST_BBACKUPD() \
BackupDaemon bbackupd; \
TEST_THAT_OR(setup_test_bbackupd(bbackupd, false), FAIL); \
TEST_THAT_OR(::mkdir("testfiles/TestDir1", 0755) == 0, FAIL);
#define SETUP_WITH_BBSTORED() \
- SETUP() \
+ SETUP_TEST_BBACKUPD() \
BackupDaemon bbackupd; \
TEST_THAT_OR(setup_test_bbackupd(bbackupd), FAIL);
-//! Checks account for errors and shuts down daemons at end of every test.
-bool teardown_test_bbackupd(std::string test_name, int old_failure_count)
-{
- if (failures == old_failure_count)
- {
- BOX_NOTICE(test_name << " passed");
- s_test_status[test_name] = "passed";
- }
- else
- {
- BOX_NOTICE(test_name << " failed"); \
- s_test_status[test_name] = "FAILED";
- }
-
- if(bbackupd_pid != 0)
- {
- TEST_THAT(StopClient());
- }
-
- return tearDown();
-}
-
-#define TEARDOWN() \
- return teardown_test_bbackupd(__FUNCTION__, old_failure_count); \
- } \
- catch (BoxException &e) \
- { \
- BOX_NOTICE(__FUNCTION__ << " errored: " << e.what()); \
- failures++; \
- bool status = teardown_test_bbackupd(__FUNCTION__, old_failure_count); \
- s_test_status[__FUNCTION__] = "ERRORED"; \
- return status; \
- }
-
+#define TEARDOWN_TEST_BBACKUPD() \
+ TEST_THAT(bbackupd_pid == 0 || StopClient()); \
+ TEST_THAT(bbstored_pid == 0 || StopServer()); \
+ TEST_THAT(kill_running_daemons()); \
+ TEARDOWN();
bool test_basics()
{
- SETUP();
+ SETUP_TEST_BBACKUPD();
TEST_THAT_OR(unpack_files("test_base"), FAIL);
// Read attributes from files
@@ -644,7 +600,7 @@ bool test_basics()
finish_with_write_xattr_test();
#endif // HAVE_SYS_XATTR_H
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
int64_t GetDirID(BackupProtocolCallable &protocol, const char *name, int64_t InDirectory)
@@ -1206,7 +1162,7 @@ bool test_readdirectory_on_nonexistent_dir()
client->QueryFinished();
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_bbackupquery_parser_escape_slashes()
@@ -1246,7 +1202,7 @@ bool test_bbackupquery_parser_escape_slashes()
TEST_EQUAL(bar_id, query.FindDirectoryObjectID("\\/bar"));
connection.QueryFinished();
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_getobject_on_nonexistent_file()
@@ -1278,7 +1234,7 @@ bool test_getobject_on_nonexistent_file()
}
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// ASSERT((mpBlockIndex == 0) || (NumBlocksInIndex != 0)) in
@@ -1288,7 +1244,7 @@ bool test_getobject_on_nonexistent_file()
bool test_replace_zero_byte_file_with_nonzero_byte_file()
{
- SETUP();
+ SETUP_TEST_BBACKUPD();
TEST_THAT_OR(mkdir("testfiles/TestDir1", 0755) == 0, FAIL);
FileStream emptyFile("testfiles/TestDir1/f2",
@@ -1310,7 +1266,7 @@ bool test_replace_zero_byte_file_with_nonzero_byte_file()
bbackupd.RunSyncNow();
TEST_COMPARE_LOCAL(Compare_Same, client);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// This caused the issue reported by Brendon Baumgartner and described in my
@@ -1429,7 +1385,7 @@ bool test_backup_disappearing_directory()
clientContext.CloseAnyOpenConnection();
TEST_COMPARE(Compare_Same);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// TODO FIXME check that directory modtimes are backed up by BackupClientDirectoryRecord.
@@ -1441,7 +1397,7 @@ bool test_ssl_keepalives()
#ifdef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
BOX_NOTICE("Skipping intercept-based KeepAlive tests on this platform");
#else
- // Delete the test_base files unpacked by SETUP()
+ // Delete the test_base files unpacked by SETUP_TEST_BBACKUPD()
TEST_THAT(::system("rm -r testfiles/TestDir1") == 0);
// Unpack spacetest files instead
TEST_THAT(::mkdir("testfiles/TestDir1", 0755) == 0);
@@ -1749,7 +1705,7 @@ bool test_ssl_keepalives()
}
#endif // PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_backup_hardlinked_files()
@@ -1782,7 +1738,7 @@ bool test_backup_hardlinked_files()
bbackupd.RunSyncNow();
TEST_COMPARE(Compare_Same);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_backup_pauses_when_store_is_full()
@@ -1912,7 +1868,7 @@ bool test_backup_pauses_when_store_is_full()
wait_for_sync_end();
TEST_COMPARE(Compare_Same);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_bbackupd_exclusions()
@@ -2145,7 +2101,7 @@ bool test_bbackupd_exclusions()
}
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_bbackupd_uploads_files()
@@ -2164,12 +2120,12 @@ bool test_bbackupd_uploads_files()
// Check that no read error has been reported yet
TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_bbackupd_responds_to_connection_failure()
{
- SETUP();
+ SETUP_TEST_BBACKUPD();
TEST_THAT_OR(unpack_files("test_base"), FAIL);
#ifdef WIN32
@@ -2262,7 +2218,7 @@ bool test_bbackupd_responds_to_connection_failure()
}
#endif // !WIN32
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_absolute_symlinks_not_followed_during_restore()
@@ -2345,7 +2301,7 @@ bool test_absolute_symlinks_not_followed_during_restore()
}
#endif
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Testing that nonexistent locations are backed up if they are created later
@@ -2401,7 +2357,7 @@ bool test_initially_missing_locations_are_not_forgotten()
// BLOCK
TEST_THAT_OR(search_for_file("Test2"), FAIL);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_redundant_locations_deleted_on_time()
@@ -2447,7 +2403,7 @@ bool test_redundant_locations_deleted_on_time()
TEST_THAT(test_entry_deleted(*root_dir, "Test2"));
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Check that read-only directories and their contents can be restored.
@@ -2502,7 +2458,7 @@ bool test_read_only_dirs_can_be_restored()
}
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Check that filenames in UTF-8 can be backed up
@@ -2739,7 +2695,7 @@ bool test_unicode_filenames_can_be_backed_up()
}
#endif // WIN32
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_sync_allow_script_can_pause_backup()
@@ -2841,7 +2797,7 @@ bool test_sync_allow_script_can_pause_backup()
TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Delete file and update another, create symlink.
@@ -2890,7 +2846,7 @@ bool test_delete_update_and_symlink_files()
TEST_COMPARE(Compare_Same, "", "-acqQ");
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Check that store errors are reported neatly. This test uses an independent
@@ -3090,7 +3046,7 @@ bool test_store_error_reporting()
TEST_THAT(::unlink("testfiles/notifyscript.tag") == 0);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_change_file_to_symlink_and_back()
@@ -3194,7 +3150,7 @@ bool test_change_file_to_symlink_and_back()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_file_rename_tracking()
@@ -3290,7 +3246,7 @@ bool test_file_rename_tracking()
TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Files that suddenly appear, with timestamps before the last sync window,
@@ -3368,14 +3324,13 @@ bool test_upload_very_old_files()
TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_excluded_files_are_not_backed_up()
{
// SETUP_WITH_BBSTORED();
-
- SETUP()
+ SETUP_TEST_BBACKUPD();
BackupProtocolLocal2 client(0x01234567, "test", "backup/01234567/",
0, false);
@@ -3439,7 +3394,7 @@ bool test_excluded_files_are_not_backed_up()
}
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_read_error_reporting()
@@ -3499,7 +3454,7 @@ bool test_read_error_reporting()
}
#endif
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_continuously_updated_file()
@@ -3558,7 +3513,7 @@ bool test_continuously_updated_file()
}
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_delete_dir_change_attribute()
@@ -3584,7 +3539,7 @@ bool test_delete_dir_change_attribute()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_restore_files_and_directories()
@@ -3673,7 +3628,7 @@ bool test_restore_files_and_directories()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_compare_detects_attribute_changes()
@@ -3741,7 +3696,7 @@ bool test_compare_detects_attribute_changes()
}
#endif // WIN32
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_sync_new_files()
@@ -3770,7 +3725,7 @@ bool test_sync_new_files()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_rename_operations()
@@ -3804,7 +3759,7 @@ bool test_rename_operations()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Check that modifying files with madly in the future timestamps still get added
@@ -3839,7 +3794,7 @@ bool test_sync_files_with_timestamps_in_future()
TEST_COMPARE(Compare_Same);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
// Check change of store marker pauses daemon
@@ -3959,7 +3914,7 @@ bool test_changing_client_store_marker_pauses_daemon()
BOX_TRACE("Compare finished, expected no differences");
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_interrupted_restore_can_be_recovered()
@@ -4021,7 +3976,7 @@ bool test_interrupted_restore_can_be_recovered()
}
#endif // !WIN32
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool assert_x1_deleted_or_not(bool expected_deleted)
@@ -4099,7 +4054,7 @@ bool test_restore_deleted_files()
// should have been undeleted by restore
TEST_THAT(assert_x1_deleted_or_not(false));
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_locked_file_behaviour()
@@ -4158,7 +4113,7 @@ bool test_locked_file_behaviour()
}
#endif // WIN32
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_backup_many_files()
@@ -4174,12 +4129,12 @@ bool test_backup_many_files()
bbackupd.RunSyncNow();
TEST_COMPARE(Compare_Same);
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_parse_incomplete_command()
{
- SETUP();
+ SETUP_TEST_BBACKUPD();
{
// This is not a complete command, it should not parse!
@@ -4189,12 +4144,12 @@ bool test_parse_incomplete_command()
TEST_EQUAL(0, cmd.mCompleteArgCount);
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
bool test_parse_syncallowscript_output()
{
- SETUP();
+ SETUP_TEST_BBACKUPD();
{
BackupDaemon daemon;
@@ -4209,7 +4164,7 @@ bool test_parse_syncallowscript_output()
TEST_EQUAL(0, daemon.GetMaxBandwidthFromSyncAllowScript());
}
- TEARDOWN();
+ TEARDOWN_TEST_BBACKUPD();
}
int test(int argc, const char *argv[])
@@ -4278,12 +4233,7 @@ int test(int argc, const char *argv[])
TEST_THAT(test_parse_incomplete_command());
TEST_THAT(test_parse_syncallowscript_output());
- typedef std::map<std::string, std::string>::iterator s_test_status_iterator;
- for(s_test_status_iterator i = s_test_status.begin();
- i != s_test_status.end(); i++)
- {
- BOX_NOTICE("test result: " << i->second << ": " << i->first);
- }
+ TEST_THAT(kill_running_daemons());
#ifndef WIN32
if(::getuid() == 0)
@@ -4292,9 +4242,5 @@ int test(int argc, const char *argv[])
}
#endif
- TEST_LINE(num_tests_selected > 0, "No tests matched the patterns "
- "specified on the command line");
- TEST_THAT(kill_running_daemons());
-
- return (failures == 0 && num_tests_selected > 0) ? 0 : 1;
+ return finish_test_suite();
}