From c647e75885c664ceb5973a60f72eeaf93cd00322 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 10 Nov 2014 23:06:14 +0100 Subject: [PATCH] Adds regression test for autosave. --- Makefile.am | 10 +++++----- cmdline/scrub.c | 4 ++-- cmdline/snapraid.c | 15 +++++++++++---- cmdline/state.h | 3 ++- cmdline/sync.c | 6 ++++-- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index 8b39e983..8ed9d7c4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -213,7 +213,7 @@ endif rm bench/content bench/?-content # Now rebuild the array with alpha order and do some commands $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff > output.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-autosave-at 100 sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) dup -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) list -l test.log > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status -l test.log @@ -294,11 +294,11 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR1) check $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check echo --- Scrub some times - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub 100 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub-at 100 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub 1000 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub-at 1000 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub 100000 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub-at 100000 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status echo --- Modify files during a sync echo RUN > bench/disk1/RUN-RM @@ -341,7 +341,7 @@ endif echo --- Silently corrupt some files, scrub and fix filtering for error $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./mktest$(EXEEXT) damage 1 10 1 bench/disk1/a/* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-expect-recoverable --test-force-scrub 100000 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-expect-recoverable --test-force-scrub-at 100000 scrub $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) fix -e $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -p 0 scrub diff --git a/cmdline/scrub.c b/cmdline/scrub.c index ed4c242f..19b1825b 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -527,9 +527,9 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* no limit */ countlimit = blockmax; recentlimit = now; - } else if (state->opt.force_scrub) { + } else if (state->opt.force_scrub_at) { /* scrub the specified amount of blocks */ - countlimit = state->opt.force_scrub; + countlimit = state->opt.force_scrub_at; recentlimit = now; } else { /* by default scrub 1/12 of the array */ diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 5346fb3b..f54912c1 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -226,7 +226,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_FORCE_ORDER_INODE 268 #define OPT_TEST_FORCE_ORDER_ALPHA 269 #define OPT_TEST_FORCE_ORDER_DIR 270 -#define OPT_TEST_FORCE_SCRUB 271 +#define OPT_TEST_FORCE_SCRUB_AT 271 #define OPT_TEST_FORCE_SCRUB_EVEN 272 #define OPT_TEST_FORCE_CONTENT_WRITE 273 #define OPT_TEST_FORCE_CONTENT_TEXT 274 @@ -238,6 +238,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_IMPORT_CONTENT 280 #define OPT_TEST_FORCE_PROGRESS 281 #define OPT_TEST_SKIP_DISK_ACCESS 282 +#define OPT_TEST_FORCE_AUTOSAVE_AT 283 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -310,7 +311,7 @@ struct option long_options[] = { { "test-force-order-dir", 0, 0, OPT_TEST_FORCE_ORDER_DIR }, /* Force scrub of the specified number of blocks */ - { "test-force-scrub", 1, 0, OPT_TEST_FORCE_SCRUB }, + { "test-force-scrub-at", 1, 0, OPT_TEST_FORCE_SCRUB_AT }, /* Force scrub of all the even blocks. This is really for testing, don't try it */ { "test-force-scrub-even", 0, 0, OPT_TEST_FORCE_SCRUB_EVEN }, @@ -345,6 +346,9 @@ struct option long_options[] = { /* Skip the disk access */ { "test-skip-disk-access", 0, 0, OPT_TEST_SKIP_DISK_ACCESS }, + /* Force autosave at the specified block */ + { "test-force-autosave-at", 1, 0, OPT_TEST_FORCE_AUTOSAVE_AT }, + { 0, 0, 0, 0 } }; #endif @@ -632,8 +636,8 @@ int main(int argc, char* argv[]) case OPT_TEST_FORCE_ORDER_DIR : opt.force_order = SORT_DIR; break; - case OPT_TEST_FORCE_SCRUB : - opt.force_scrub = atoi(optarg); + case OPT_TEST_FORCE_SCRUB_AT : + opt.force_scrub_at = atoi(optarg); break; case OPT_TEST_FORCE_SCRUB_EVEN : opt.force_scrub_even = 1; @@ -658,6 +662,9 @@ int main(int argc, char* argv[]) case OPT_TEST_FORCE_PROGRESS : opt.force_progress = 1; break; + case OPT_TEST_FORCE_AUTOSAVE_AT : + opt.force_autosave_at = atoi(optarg); + break; default : /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); diff --git a/cmdline/state.h b/cmdline/state.h index 8e19512f..52e83aa2 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -87,12 +87,13 @@ struct snapraid_option { int force_murmur3; /**< Force Murmur3 choice. */ int force_spooky2; /**< Force Spooky2 choice. */ int force_order; /**< Force sorting order. One of the SORT_* defines. */ - unsigned force_scrub; /**< Force scrub for the specified number of blocks. */ + unsigned force_scrub_at; /**< Force scrub for the specified number of blocks. */ int force_scrub_even; /**< Force scrub of all the even blocks. */ int force_content_write; /**< Force the update of the content file. */ int force_content_text; /**< Force the use of text version of content file. */ int force_scan_winfind; /**< Force the use of FindFirst/Next in Windows to list directories. */ int force_progress; /**< Force the use of the progress status. */ + unsigned force_autosave_at; /**< Force autosave at the specified block. */ }; /** diff --git a/cmdline/sync.c b/cmdline/sync.c index 330027ab..c9607734 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -947,9 +947,11 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } /* autosave */ - if (state->autosave != 0 + if ((state->autosave != 0 && autosavedone >= autosavelimit /* if we have reached the limit */ - && autosavemissing >= autosavelimit /* if we have at least a full step to do */ + && autosavemissing >= autosavelimit) /* if we have at least a full step to do */ + /* or if we have a forced autosave at the specified block */ + || (state->opt.force_autosave_at != 0 && state->opt.force_autosave_at == i) ) { autosavedone = 0; /* restart the counter */