From fcc389466763ce5e83f1b20e2ff46abfd7fffb51 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 4 Dec 2015 22:38:43 +0100 Subject: [PATCH] Add regression test for UUID change --- Makefile.am | 3 +++ cmdline/snapraid.c | 7 +++++++ cmdline/state.c | 5 +++++ cmdline/state.h | 1 + 4 files changed, 16 insertions(+) diff --git a/Makefile.am b/Makefile.am index 78a968ec..20666a56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -305,6 +305,9 @@ endif rm bench/disk1/EXTRA1 touch bench/disk1/EXTRA2 $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -E sync +# Change UUID + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-fake-uuid sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync #### NOT EMPTY #### echo --- Create some files $(TESTENV) ./mktest$(EXEEXT) generate 1 6 $(CHECKCOUNT) $(CHECKSIZE) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 7c2bcceb..5b911dc8 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -246,6 +246,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_FAKE_DEVICE 284 #define OPT_TEST_EXPECT_NEED_SYNC 285 #define OPT_NO_WARNINGS 286 +#define OPT_TEST_FAKE_UUID 287 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -364,6 +365,9 @@ struct option long_options[] = { /* Disable annoying warnings */ { "test-no-warnings", 0, 0, OPT_NO_WARNINGS }, + /* Fake UUID */ + { "test-fake-uuid", 0, 0, OPT_TEST_FAKE_UUID }, + { 0, 0, 0, 0 } }; #endif @@ -733,6 +737,9 @@ int main(int argc, char* argv[]) case OPT_NO_WARNINGS : opt.no_warnings = 1; break; + case OPT_TEST_FAKE_UUID : + opt.fake_uuid = 2; + break; default : /* LCOV_EXCL_START */ log_fatal("Unknown option '%c'\n", (char)c); diff --git a/cmdline/state.c b/cmdline/state.c index cfb6a888..586e75e7 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -1271,6 +1271,11 @@ static void state_map(struct snapraid_state* state) continue; } + if (state->opt.fake_uuid) { + snprintf(uuid, sizeof(uuid), "fake-uuid-%d", state->opt.fake_uuid); + --state->opt.fake_uuid; + } + /* if the uuid is changed */ if (strcmp(uuid, map->uuid) != 0) { /* mark the disk as with an UUID change */ diff --git a/cmdline/state.h b/cmdline/state.h index b073e0e7..f36227b8 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -105,6 +105,7 @@ struct snapraid_option { int fake_device; /**< Fake device data. */ int no_warnings; /**< Remove some warning messages. */ int expected_missing; /**< If missing files are expected and should not be reported. */ + int fake_uuid; /**< Set fakes UUID for testing. */ }; /**