From ba0c979c117d2b38f961368fa54ba07eb04f7594 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 20 Mar 2014 22:10:19 +0100 Subject: [PATCH] More coverage test. --- Makefile.am | 37 ++++++++++++++++++++++++++----------- check.c | 4 +++- elem.c | 4 ++++ mingw.c | 6 ++++++ portable.h | 10 ++++++++++ snapraid.c | 30 +++++++++++++++++++++++++++--- state.c | 6 ++++-- test-par1.conf | 2 ++ unix.c | 6 ++++++ 9 files changed, 88 insertions(+), 17 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9cc7c76e..ed00bf00 100644 --- a/Makefile.am +++ b/Makefile.am @@ -113,7 +113,7 @@ maintainer-clean-local: # Automatic testing CHECKFLAGS_BASE = --test-skip-device --test-skip-self --test-force-order-alpha -CHECKFLAGS_VERBOSE = $(CHECKFLAGS_BASE) -v +CHECKFLAGS_VERBOSE = $(CHECKFLAGS_BASE) -v -G CHECKFLAGS = $(CHECKFLAGS_BASE) -q CHECKCOUNT = 1000 CHECKSIZE = 4000 @@ -139,15 +139,16 @@ check-local: mkdir test/pool echo --- Help $(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -H + $(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -V $(TESTENV) ./mktest$(EXEEXT) echo --- Run the self test only this time $(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -c $(CONF) status echo --- Run the speed test $(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -T echo --- Some commands with empty array - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) list > output.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) dup + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) list > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-murmur3 sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status -l ">&1" @@ -163,12 +164,11 @@ endif $(TESTENV) ./mktest$(EXEEXT) generate 1 6 $(CHECKCOUNT) $(CHECKSIZE) echo DUP > test/disk1/DUP1 echo DUP > test/disk1/DUP2 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff > output.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff -G > output.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-order-physical sync echo --- Some commands with a not empty array - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup -l test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) list -l test.log > output.log + $(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 if HAVE_SYMLINK $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR1) pool @@ -178,10 +178,21 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -a check echo --- Check the --gen-conf command $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --gen-conf test/content + echo --- Filter + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) -d disk1 check + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) -f "*a" -f "a/" -f "/b/a*" check echo --- Delete some files and sync rm test/disk4/a/9* rm test/disk5/a/9* rm test/disk6/a/9* + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff > output.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check + echo --- Move some files, sync and check + mv test/disk1/a/9* test/disk4/a + mv test/disk2/a/9* test/disk5/a + mv test/disk3/a/9* test/disk6/a + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check echo --- Create some more files, hardlinks and empty directories, delete others, sync PAR1 and check @@ -203,13 +214,13 @@ endif echo 3 > test/disk3/file_hardlink1 ln test/disk3/file_hardlink1 test/disk3/file_hardlink2 ln test/disk3/file_hardlink1 test/disk3/file_hardlink3 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(PAR1) diff > output.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-fallocate -c $(PAR1) --test-force-order-inode sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-sequential -c $(PAR1) check echo --- Some commands with a not empty array - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(PAR1) dup - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(PAR1) list > output.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) dup + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) list > output.log if HAVE_SYMLINK $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR1) pool endif @@ -261,6 +272,10 @@ endif mv test/disk2.old test/disk2 $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check + echo --- Corrupt the content file + $(TESTENV) ./mktest$(EXEEXT) write 1 100 100 test/content + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-failure -c $(CONF) sync + rm test/content echo --- Delete some files, create some new, sync and check rm test/disk1/a/1* rm test/disk2/a/2* diff --git a/check.c b/check.c index ee330e95..ffb82c62 100644 --- a/check.c +++ b/check.c @@ -164,11 +164,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u int id[LEV_MAX]; int ip[LEV_MAX]; - /* no fix required */ + /* no fix required, already checked at higher level, but just to be sure */ if (failed_count == 0) { + /* LCOV_EXCL_START */ /* recompute only the parity */ raid_gen(diskmax, state->level, state->block_size, buffer); return 0; + /* LCOV_EXCL_STOP */ } n = state->level; diff --git a/elem.c b/elem.c index 8cb32d71..9c5bec48 100644 --- a/elem.c +++ b/elem.c @@ -85,8 +85,10 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* pattern) /* a slash must be the first char, as we reject PATH/DIR/FILE */ if (filter->pattern[0] != '/') { + /* LCOV_EXCL_START */ free(filter); return 0; + /* LCOV_EXCL_STOP */ } } @@ -108,8 +110,10 @@ struct snapraid_filter* filter_alloc_disk(int direction, const char* pattern) /* no slash allowed in disk names */ if (strchr(filter->pattern, '/') != 0) { + /* LCOV_EXCL_START */ free(filter); return 0; + /* LCOV_EXCL_STOP */ } return filter; diff --git a/mingw.c b/mingw.c index 897ea6ff..33f85c23 100644 --- a/mingw.c +++ b/mingw.c @@ -21,6 +21,12 @@ #ifdef __MINGW32__ /* Only for MingW */ +/** + * Standard exit codes. + */ +int exit_success = 0; +int exit_failure = 1; + /* Adds missing Windows declaration */ typedef struct _FILE_ATTRIBUTE_TAG_INFO { DWORD FileAttributes; diff --git a/portable.h b/portable.h index c5905ccf..6bb2a385 100644 --- a/portable.h +++ b/portable.h @@ -251,5 +251,15 @@ void os_done(void); */ FILE* stdlog; +/** + * Exit codes for testing. + */ +int exit_success; +int exit_failure; +#undef EXIT_SUCCESS +#undef EXIT_FAILURE +#define EXIT_SUCCESS exit_success +#define EXIT_FAILURE exit_failure + #endif diff --git a/snapraid.c b/snapraid.c index 4b5a8536..559053a1 100644 --- a/snapraid.c +++ b/snapraid.c @@ -104,8 +104,10 @@ void log_open(const char* log) strftime(text_T, sizeof(text_T), "%H%M%S", tm); strftime(text_D, sizeof(text_T), "%Y%m%d", tm); } else { + /* LCOV_EXCL_START */ strcpy(text_T, "invalid"); strcpy(text_D, "invalid"); + /* LCOV_EXCL_STOP */ } /* file mode */ @@ -227,6 +229,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_FORCE_CONTENT_TEXT 274 #define OPT_TEST_SKIP_CONTENT_CHECK 275 #define OPT_TEST_SKIP_PARITY_ACCESS 276 +#define OPT_TEST_EXPECT_FAILURE 277 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -315,6 +318,9 @@ struct option long_options[] = { /* Skip the parity access */ { "test-skip-parity-access", 0, 0, OPT_TEST_SKIP_PARITY_ACCESS }, + /* Exit generic failure */ + { "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE }, + { 0, 0, 0, 0 } }; #endif @@ -497,8 +503,10 @@ int main(int argc, char* argv[]) opt.force_device = 1; break; case 'N' : + /* LCOV_EXCL_START */ fprintf(stderr, "WARNING! Option --find-by-name, -N is deprecated and does nothing!\n"); break; + /* LCOV_EXCL_STOP */ case 'a' : opt.auditonly = 1; break; @@ -590,6 +598,11 @@ int main(int argc, char* argv[]) case OPT_TEST_FORCE_CONTENT_TEXT : opt.force_content_text = 1; break; + case OPT_TEST_EXPECT_FAILURE : + /* invert the exit code */ + exit_success = 1; + exit_failure = 0; + break; default: /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); @@ -605,8 +618,10 @@ int main(int argc, char* argv[]) } if (optind + 1 != argc) { + /* LCOV_EXCL_START */ usage(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } command = argv[optind]; @@ -821,8 +836,11 @@ int main(int argc, char* argv[]) state_write(&state); /* abort if required */ - if (ret != 0) + if (ret != 0) { + /* LCOV_EXCL_START */ exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } } else if (operation == OPERATION_DRY) { state_read(&state); @@ -861,8 +879,11 @@ int main(int argc, char* argv[]) state_write(&state); /* abort if required */ - if (ret != 0) + if (ret != 0) { + /* LCOV_EXCL_START */ exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } } else if (operation == OPERATION_REWRITE) { state_read(&state); @@ -908,8 +929,11 @@ int main(int argc, char* argv[]) } /* abort if required */ - if (ret != 0) + if (ret != 0) { + /* LCOV_EXCL_START */ exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } } /* close log file */ diff --git a/state.c b/state.c index c6d8378c..280af8a8 100644 --- a/state.c +++ b/state.c @@ -2558,11 +2558,9 @@ static void decoding_error(const char* path, STREAM* f) crc_stored = crc32c(crc_stored, buf, 4); if (crc_computed != crc_stored) { - /* LCOV_EXCL_START */ fprintf(stderr, "Mismatching CRC in '%s'\n", path); fprintf(stderr, "This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); - /* LCOV_EXCL_STOP */ } else { fprintf(stderr, "The file CRC is correct!\n"); } @@ -4164,10 +4162,12 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b /* stop if requested */ if (global_interrupt) { + /* LCOV_EXCL_START */ if (!state->opt.gui) { printf("Not starting for interruption\n"); } return 0; + /* LCOV_EXCL_STOP */ } return 1; @@ -4260,11 +4260,13 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off /* stop if requested */ if (global_interrupt) { + /* LCOV_EXCL_START */ if (!state->opt.gui) { printf("\n"); printf("Stopping for interruption at block %u\n", blockpos); } return 1; + /* LCOV_EXCL_STOP */ } return 0; diff --git a/test-par1.conf b/test-par1.conf index c34b745a..dca7f6fa 100644 --- a/test-par1.conf +++ b/test-par1.conf @@ -1,3 +1,4 @@ +# Test configuration file blocksize 1 parity test/parity content test/content @@ -12,4 +13,5 @@ include *.hidden exclude *.unrecoverable pool test/pool share \\server\jbod +autosave 1 diff --git a/unix.c b/unix.c index fd3b123f..a2dc8f6f 100644 --- a/unix.c +++ b/unix.c @@ -19,6 +19,12 @@ #ifndef __MINGW32__ /* Only for Unix */ +/** + * Standard exit codes. + */ +int exit_success = 0; +int exit_failure = 1; + int open_noatime(const char* file, int flags) { #ifdef O_NOATIME