From 757dbd557378d596b30a89de6e398da84c8fb8ad Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 22 Mar 2011 23:21:19 +0100 Subject: [PATCH] More extensive unit test. --- Makefile.am | 41 +++++++++++++++++++++++++------- mktest.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 92 insertions(+), 16 deletions(-) diff --git a/Makefile.am b/Makefile.am index c2645362..09207729 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,7 @@ EXTRA_DIST = \ autogen.sh \ noautomake.sh \ README AUTHORS HISTORY INSTALL COPYING TODO \ - snapraid.d snapraid.1 snapraid.txt snapraid.html \ + snapraid.d snapraid.1 snapraid.txt \ test.conf \ snapraid.conf.example \ acinclude.m4 @@ -50,16 +50,14 @@ EXTRA_DIST = \ man_MANS = snapraid.1 clean-local: - rm -f valgrind.log callgrind.log + rm -f valgrind.log callgrind.log cachegrind.log rm -rf test maintainer-clean-local: - rm -f snapraid.1 snapraid.txt snapraid.html + rm -f snapraid.1 snapraid.txt # Automatic testing -CHECK = ./snapraid -v -c test.conf fix - check-local: rm -rf test mkdir test @@ -76,9 +74,28 @@ check-local: echo --- Create some more files, sync and check $(TESTENV) ./mktest$(EXEEXT) generate 2 3 1000 4000 $(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 - 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 fix 2>/dev/null $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check @@ -99,7 +116,9 @@ check-local: $(TESTENV) ./snapraid$(EXEEXT) -c $(srcdir)/test.conf check echo Success! -# Valgrind testing +# Manual testing + +CHECK = ./snapraid -v -c test.conf sync valgrind: valgrind \ @@ -142,7 +161,6 @@ cachegrind: DISTWIN = \ snapraid.txt \ - snapraid.html \ snapraid.exe \ snapraid.conf.example @@ -150,6 +168,11 @@ distwindows: $(DISTWIN) rm -f $(PACKAGE)-$(VERSION)-windows-x86.zip mkdir 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 * rm -r tmp diff --git a/mktest.c b/mktest.c index c1e76968..2897279c 100644 --- a/mktest.c +++ b/mktest.c @@ -29,23 +29,77 @@ unsigned rnd(unsigned max) return (seed >> 32) % max; } +char CHARSET[] = "qwertyuiopasdfghjklzxcvbnm1234567890 .-+"; +#define CHARSET_LEN (sizeof(CHARSET)-1) + void generate(int disk, int size) { char path[PATH_MAX]; - char name[PATH_MAX]; FILE* f; + char* file; int count; int i; int l; - l = 1 + rnd(32); + snprintf(path, sizeof(path), "test/disk%d/", disk); + i = strlen(path); - for(i=0;i