mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-25 18:40:19 -04:00
Increase a bit the test coverage.
This commit is contained in:
parent
a8bdaf65b4
commit
ff6b4ff760
6 changed files with 114 additions and 29 deletions
13
Makefile.am
13
Makefile.am
|
|
@ -112,7 +112,9 @@ maintainer-clean-local:
|
|||
|
||||
# Automatic testing
|
||||
|
||||
CHECKFLAGS = --test-skip-device --test-skip-self --test-force-order-alpha -q
|
||||
CHECKFLAGS_BASE = --test-skip-device --test-skip-self --test-force-order-alpha
|
||||
CHECKFLAGS_VERBOSE = $(CHECKFLAGS_BASE) -v
|
||||
CHECKFLAGS = $(CHECKFLAGS_BASE) -q
|
||||
CHECKCOUNT = 1000
|
||||
CHECKSIZE = 4000
|
||||
CONF = $(srcdir)/test-par6.conf
|
||||
|
|
@ -137,6 +139,7 @@ check-local:
|
|||
mkdir test/pool
|
||||
echo --- Help
|
||||
$(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -h
|
||||
$(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
|
||||
|
|
@ -372,11 +375,10 @@ endif
|
|||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-scrub-even scrub
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check
|
||||
echo --- Delete files from three disks and fix with import in PAR2
|
||||
echo --- Delete files from three disks and check/fix with import in PAR2
|
||||
rm -r test/disk1/a
|
||||
rm -r test/disk2/a
|
||||
mv test/disk3/a test/a
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-unrecoverable -c $(PAR2) fix -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -i test/a -c $(PAR2) fix -l test.log
|
||||
rm -r test/a
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync
|
||||
|
|
@ -521,11 +523,12 @@ endif
|
|||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-recoverable -c $(PAR1) check -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR1) fix -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check
|
||||
echo --- Corrupt some files, fix and check with PAR2
|
||||
echo --- Corrupt some files, fix and check with PAR2 in verbose mode
|
||||
$(TESTENV) ./mktest$(EXEEXT) change 4 500 test/disk2/b/*
|
||||
$(TESTENV) ./mktest$(EXEEXT) change 4 500 test/disk3/b/*
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) --test-expect-unrecoverable -c $(PAR1) check -l test.log > /dev/null
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) --test-expect-unrecoverable -c $(PAR1) fix -l test.log > /dev/null
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-recoverable -c $(PAR2) -a check -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-unrecoverable -c $(PAR1) check -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-expect-recoverable -c $(PAR2) check -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR2) fix -l test.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
make distclean
|
||||
|
||||
rm -rf cov_release
|
||||
|
||||
if ! ./configure --enable-coverage; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -13,6 +11,7 @@ if ! make lcov_reset check lcov_capture lcov_html; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf cov_release
|
||||
mv cov cov_release
|
||||
|
||||
if ! make distclean; then
|
||||
|
|
|
|||
16
mktest.c
16
mktest.c
|
|
@ -222,18 +222,6 @@ void fallback(int f, struct stat* st)
|
|||
}
|
||||
}
|
||||
|
||||
void duplicate_name(const char* path, char* newpath)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
strcpy(newpath, path);
|
||||
|
||||
len = strlen(newpath);
|
||||
|
||||
newpath[len] = 'a' + rnd('z' - 'a');
|
||||
newpath[len+1] = 0;
|
||||
}
|
||||
|
||||
void writ(const char* path, int size, int silent_error)
|
||||
{
|
||||
struct stat st;
|
||||
|
|
@ -472,10 +460,8 @@ int main(int argc, char* argv[])
|
|||
int i, j, b;
|
||||
|
||||
if (argc < 2) {
|
||||
/* LCOV_EXCL_START */
|
||||
help();
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "generate") == 0) {
|
||||
|
|
|
|||
4
scrub.c
4
scrub.c
|
|
@ -263,6 +263,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
/* report that the block and the file are not synched */
|
||||
block_is_unsynched = 1;
|
||||
file_is_unsynched = 1;
|
||||
|
||||
/* follow */
|
||||
}
|
||||
|
||||
/* note that we intentionally don't abort if the file has different attributes */
|
||||
|
|
@ -330,6 +332,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
fprintf(stdlog, "parity_error:%u:%s: Read error\n", i, lev_config_name(l));
|
||||
++error;
|
||||
error_on_this_block = 1;
|
||||
|
||||
/* follow */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
92
selftest.c
92
selftest.c
|
|
@ -27,6 +27,10 @@
|
|||
#include "elem.h"
|
||||
#include "state.h"
|
||||
#include "tommyhash.h"
|
||||
#include "tommyarray.h"
|
||||
#include "tommyarrayblk.h"
|
||||
#include "tommyarrayblkof.h"
|
||||
#include "tommyhashdyn.h"
|
||||
|
||||
struct hash32_test_vector {
|
||||
const char* data;
|
||||
|
|
@ -68,6 +72,7 @@ static struct hash32_test_vector TEST_HASH32[] = {
|
|||
{ "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8 },
|
||||
{ "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d },
|
||||
{ "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f },
|
||||
{ "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382 },
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
|
@ -93,6 +98,7 @@ static struct hash64_test_vector TEST_HASH64[] = {
|
|||
{ "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL },
|
||||
{ "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL },
|
||||
{ "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL },
|
||||
{ "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL },
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
|
@ -246,6 +252,91 @@ static void test_crc32c(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of tommy data structures.
|
||||
*/
|
||||
#define TOMMY_SIZE 256
|
||||
|
||||
static int tommy_test_search(const void* arg, const void* obj)
|
||||
{
|
||||
return arg != obj;
|
||||
}
|
||||
|
||||
static void test_tommy(void)
|
||||
{
|
||||
tommy_array array;
|
||||
tommy_arrayblk arrayblk;
|
||||
tommy_arrayblkof arrayblkof;
|
||||
tommy_hashdyn hashdyn;
|
||||
tommy_hashdyn_node node[TOMMY_SIZE];
|
||||
unsigned i;
|
||||
|
||||
tommy_array_init(&array);
|
||||
tommy_arrayblk_init(&arrayblk);
|
||||
tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));
|
||||
|
||||
for(i=0;i<TOMMY_SIZE;++i) {
|
||||
tommy_array_insert(&array, &node[i]);
|
||||
tommy_arrayblk_insert(&arrayblk, &node[i]);
|
||||
tommy_arrayblkof_grow(&arrayblkof, i + 1);
|
||||
*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
|
||||
}
|
||||
|
||||
if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*))
|
||||
goto bail;
|
||||
if (tommy_arrayblk_memory_usage(&arrayblk) < TOMMY_SIZE * sizeof(void*))
|
||||
goto bail;
|
||||
if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned))
|
||||
goto bail;
|
||||
|
||||
for(i=0;i<TOMMY_SIZE;++i) {
|
||||
if (tommy_array_get(&array, i) != &node[i])
|
||||
goto bail;
|
||||
if (tommy_arrayblk_get(&arrayblk, i) != &node[i])
|
||||
goto bail;
|
||||
if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
tommy_arrayblkof_done(&arrayblkof);
|
||||
tommy_arrayblk_done(&arrayblk);
|
||||
tommy_array_done(&array);
|
||||
|
||||
tommy_hashdyn_init(&hashdyn);
|
||||
|
||||
for(i=0;i<TOMMY_SIZE;++i)
|
||||
tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);
|
||||
|
||||
if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE)
|
||||
goto bail;
|
||||
|
||||
if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(void*))
|
||||
goto bail;
|
||||
|
||||
for(i=0;i<TOMMY_SIZE/2;++i)
|
||||
tommy_hashdyn_remove_existing(&hashdyn, &node[i]);
|
||||
|
||||
for(i=0;i<TOMMY_SIZE/2;++i)
|
||||
if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0)
|
||||
goto bail;
|
||||
|
||||
for(i=TOMMY_SIZE/2;i<TOMMY_SIZE;++i)
|
||||
if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0)
|
||||
goto bail;
|
||||
|
||||
if (tommy_hashdyn_count(&hashdyn) != 0)
|
||||
goto bail;
|
||||
|
||||
tommy_hashdyn_done(&hashdyn);
|
||||
|
||||
return;
|
||||
bail:
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Failed tommy test\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
void selftest(void)
|
||||
{
|
||||
fprintf(stdlog, "selftest:\n");
|
||||
|
|
@ -263,6 +354,7 @@ void selftest(void)
|
|||
|
||||
test_hash();
|
||||
test_crc32c();
|
||||
test_tommy();
|
||||
if (raid_selftest() != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Failed SELF test\n");
|
||||
|
|
|
|||
15
sync.c
15
sync.c
|
|
@ -555,7 +555,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
/* this isn't a serious error, so we skip this block, and continue with others */
|
||||
error_on_this_block = 1;
|
||||
continue;
|
||||
} else if (errno == EACCES) {
|
||||
}
|
||||
if (errno == EACCES) {
|
||||
fprintf(stdlog, "error:%u:%s:%s: Open access error\n", i, handle[j].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");
|
||||
|
|
@ -566,14 +567,14 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
/* this isn't a serious error, so we skip this block, and continue with others */
|
||||
error_on_this_block = 1;
|
||||
continue;
|
||||
} else {
|
||||
fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, handle[j].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", handle[j].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, handle[j].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", handle[j].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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue