More extensive unit test.

This commit is contained in:
Andrea Mazzoleni 2011-03-22 23:21:19 +01:00
parent 0d70e7cd6a
commit 757dbd5573
2 changed files with 92 additions and 16 deletions

View file

@ -42,7 +42,7 @@ EXTRA_DIST = \
autogen.sh \ autogen.sh \
noautomake.sh \ noautomake.sh \
README AUTHORS HISTORY INSTALL COPYING TODO \ README AUTHORS HISTORY INSTALL COPYING TODO \
snapraid.d snapraid.1 snapraid.txt snapraid.html \ snapraid.d snapraid.1 snapraid.txt \
test.conf \ test.conf \
snapraid.conf.example \ snapraid.conf.example \
acinclude.m4 acinclude.m4
@ -50,16 +50,14 @@ EXTRA_DIST = \
man_MANS = snapraid.1 man_MANS = snapraid.1
clean-local: clean-local:
rm -f valgrind.log callgrind.log rm -f valgrind.log callgrind.log cachegrind.log
rm -rf test rm -rf test
maintainer-clean-local: maintainer-clean-local:
rm -f snapraid.1 snapraid.txt snapraid.html rm -f snapraid.1 snapraid.txt
# Automatic testing # Automatic testing
CHECK = ./snapraid -v -c test.conf fix
check-local: check-local:
rm -rf test rm -rf test
mkdir test mkdir test
@ -77,8 +75,27 @@ check-local:
$(TESTENV) ./mktest$(EXEEXT) generate 2 3 1000 4000 $(TESTENV) ./mktest$(EXEEXT) generate 2 3 1000 4000
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf sync $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf sync
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
echo --- Delete some files and create some new, sync and check
rm test/disk1/1*
rm test/disk2/2*
rm test/disk2/3*
$(TESTENV) ./mktest$(EXEEXT) generate 3 3 100 4000
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf sync
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
echo --- Delete some files, fix and check echo --- Delete some files, fix and check
rm test/disk1/a* rm test/disk1/1*
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf fix 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
echo --- Delete some dirs, fix and check
rm -r test/disk2/_a
rm -r test/disk2/_b
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf fix 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
echo --- Delete a whole disk, fix and check
rm -r test/disk3
mkdir test/disk3
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check 2>/dev/null $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf fix 2>/dev/null $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf fix 2>/dev/null
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
@ -99,7 +116,9 @@ check-local:
$(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check
echo Success! echo Success!
# Valgrind testing # Manual testing
CHECK = ./snapraid -v -c test.conf sync
valgrind: valgrind:
valgrind \ valgrind \
@ -142,7 +161,6 @@ cachegrind:
DISTWIN = \ DISTWIN = \
snapraid.txt \ snapraid.txt \
snapraid.html \
snapraid.exe \ snapraid.exe \
snapraid.conf.example snapraid.conf.example
@ -150,6 +168,11 @@ distwindows: $(DISTWIN)
rm -f $(PACKAGE)-$(VERSION)-windows-x86.zip rm -f $(PACKAGE)-$(VERSION)-windows-x86.zip
mkdir tmp mkdir tmp
cp $(DISTWIN) tmp cp $(DISTWIN) tmp
cp README tmp/readme.txt
cp AUTHORS tmp/authors.txt
cp HISTORY tmp/history.txt
cp COPYING tmp/copying.txt
cp TODO tmp/todo.txt
cd tmp && zip -r ../$(PACKAGE)-$(VERSION)-windows-x86.zip * cd tmp && zip -r ../$(PACKAGE)-$(VERSION)-windows-x86.zip *
rm -r tmp rm -r tmp

View file

@ -29,23 +29,77 @@ unsigned rnd(unsigned max)
return (seed >> 32) % max; return (seed >> 32) % max;
} }
char CHARSET[] = "qwertyuiopasdfghjklzxcvbnm1234567890 .-+";
#define CHARSET_LEN (sizeof(CHARSET)-1)
void generate(int disk, int size) void generate(int disk, int size)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
char name[PATH_MAX];
FILE* f; FILE* f;
char* file;
int count; int count;
int i; int i;
int l; int l;
l = 1 + rnd(32); snprintf(path, sizeof(path), "test/disk%d/", disk);
i = strlen(path);
for(i=0;i<l;++i) { /* add a directory */
name[i] = 'a' + rnd(22); if (rnd(2) == 0) {
path[i++] = '_';
path[i++] = 'a' + rnd(2);
path[i] = 0;
/* create it */
if (mkdir(path, 0777) != 0) {
if (errno != EEXIST) {
fprintf(stderr, "Error creating directory %s\n", path);
exit(EXIT_FAILURE);
}
}
path[i++] = '/';
} }
name[i] = 0;
snprintf(path, sizeof(path), "test/disk%d/%s", disk, name); /* add another directory */
if (rnd(2) == 0) {
path[i++] = '_';
path[i++] = 'a' + rnd(2);
path[i] = 0;
/* create it */
if (mkdir(path, 0777) != 0) {
if (errno != EEXIST) {
fprintf(stderr, "Error creating directory %s\n", path);
exit(EXIT_FAILURE);
}
}
path[i++] = '/';
}
/* add a file */
l = 1 + rnd(20);
file = path + i;
while (l) {
path[i++] = CHARSET[rnd(CHARSET_LEN)];
--l;
}
path[i] = 0;
/* skip some invalid file name, see http://en.wikipedia.org/wiki/Filename */
if (strcmp(file, ".") == 0
|| strcmp(file, "..") == 0
|| strcmp(file, "prn") == 0
|| strcmp(file, "con") == 0
|| strcmp(file, "nul") == 0
|| strcmp(file, "aux") == 0
|| file[0] == ' '
|| file[strlen(file)-1] == ' '
|| file[strlen(file)-1] == '.'
) {
return;
}
f = fopen(path, "wb"); f = fopen(path, "wb");
if (!f) { if (!f) {
@ -139,7 +193,6 @@ int main(int argc, char* argv[])
} }
} else if (strcmp(argv[1], "damage") == 0) { } else if (strcmp(argv[1], "damage") == 0) {
int fail, size; int fail, size;
const char* file;
if (argc < 6) { if (argc < 6) {
help(); help();