Extends the sync regression test to cover error conditions.

This commit is contained in:
Andrea Mazzoleni 2014-04-07 23:12:40 +02:00
parent 3c8b659c8a
commit 0d231038ff
3 changed files with 59 additions and 6 deletions

View file

@ -230,6 +230,7 @@ void config(char* conf, size_t conf_size, const char* argv0)
#define OPT_TEST_SKIP_CONTENT_CHECK 275
#define OPT_TEST_SKIP_PARITY_ACCESS 276
#define OPT_TEST_EXPECT_FAILURE 277
#define OPT_TEST_RUN 278
#if HAVE_GETOPT_LONG
struct option long_options[] = {
@ -321,6 +322,9 @@ struct option long_options[] = {
/* Exit generic failure */
{ "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE },
/* Run some command after loading the state and before the command */
{ "test-run", 1, 0, OPT_TEST_RUN },
{ 0, 0, 0, 0 }
};
#endif
@ -375,6 +379,7 @@ int main(int argc, char* argv[])
const char* log;
int lock;
const char* gen_conf;
const char* run;
int period;
os_init();
@ -397,6 +402,7 @@ int main(int argc, char* argv[])
log = 0;
lock = 0;
gen_conf = 0;
run = 0;
opterr = 0;
while ((c =
@ -603,6 +609,9 @@ int main(int argc, char* argv[])
exit_success = 1;
exit_failure = 0;
break;
case OPT_TEST_RUN :
run = optarg;
break;
default:
/* LCOV_EXCL_START */
fprintf(stderr, "Unknown option '%c'\n", (char)c);
@ -819,6 +828,17 @@ int main(int argc, char* argv[])
if (state.need_write)
state_write(&state);
/* run a test command if required */
if (run != 0) {
ret = system(run); /* ignore error */
if (ret != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Error in running command '%s'.\n", run);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
/* waits some time to ensure that any concurrent modification done at the files, */
/* using the same mtime read by the scan process, will be read by sync. */
/* Note that any later modification done, potentially not read by sync, will have */

View file

@ -147,7 +147,8 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
/* if the file is missing, it means that it was removed during sync */
/* this isn't a serious error, so we skip this block, and continue with others */
continue;
} else if (errno == EACCES) {
}
if (errno == EACCES) {
fprintf(stdlog, "error:%u:%s:%s: Open access error\n", i, disk->name, file->sub);
fprintf(stderr, "No access at file '%s'.\n", handle[j].path);
fprintf(stderr, "WARNING! Please fix the access permission in the data disk.\n");
@ -157,14 +158,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
/* this isn't a serious error, so we skip this block, and continue with others */
continue;
} else {
fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno));
fprintf(stderr, "DANGER! Unexpected open error in a data disk, it isn't possible to sync.\n");
fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
}
/* LCOV_EXCL_START */
fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno));
fprintf(stderr, "DANGER! Unexpected open error in a data disk, it isn't possible to sync.\n");
fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path);
printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub);
++error;
goto bail;
/* LCOV_EXCL_STOP */