From 48bb47642a2a39339f04012e3551b616ce8f0bc4 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Tue, 4 May 2010 10:36:26 +0200 Subject: Expanded the functional test I'd say this test is now finished. I should add some tests to make sure that the internal functions within compll.c do what they should in every situation, but as those tests are hard to write and the functional test would likely have found a bug if something was wrong with them, I'd save the more detailled tests for later. --- test/func.c | 49 ++++++++++++++++++++++++++++++++----------------- test/provelist | 2 +- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/test/func.c b/test/func.c index c057ea6..70d1c6c 100644 --- a/test/func.c +++ b/test/func.c @@ -56,8 +56,19 @@ int main(int argc, char **argv) { compll_t *allocs; int i, s, msize; void *p; - char *ndata; + unsigned char *ndata; compll_t m; + int freenodes[] = { + /* three adjacent nodes (causing two forward merges) */ + 5, 6, 7, + /* same, but causing a backward and forward merge */ + 10, 9, 11, + /* same, but causing a double merge */ + 15, 13, 14, + /* and free some nodes that are guaranteed to fill up an entire block */ + NODENUM, NODENUM-2, NODENUM-4 + }; + int fnlength = sizeof(freenodes)/sizeof(int); /* the provided arguments are assumed to be within the specified bounds of the library */ if(argc != 4) { @@ -70,7 +81,7 @@ int main(int argc, char **argv) { printf("# b/a/u %d/%d/%d\n", blocksize, align, uncomp); msize = blocksize-36; - printf("1..%d\n", 1 + NODENUM*4 + NODENUM*2 + 10*3); + printf("1..%d\n", 1 + NODENUM*4 + NODENUM*2 + 10*3 + (NODENUM-fnlength)*2); i = compll_init(blocksize, align, uncomp, dbg_compress, dbg_decompress); isok(!i, "Initialization"); @@ -112,32 +123,36 @@ int main(int argc, char **argv) { } /* free some nodes */ - int freenodes[] = { - /* three adjacent nodes (causing two forward merges) */ - 5, 6, 7, - /* same, but causing a backward and forward merge */ - 10, 9, 11, - /* same, but causing a double merge */ - 15, 13, 14, - /* and free some nodes that are guaranteed to fill up an entire block */ - NODENUM, NODENUM-2, NODENUM-4 - }; - for(i=0; i<(int)(sizeof(freenodes)/sizeof(int)); i++) { + for(i=0; i 0 - * 2. compll_read(x) != NULL - * 3. node data contains zeroes */ + * 2. compll_write(x) != NULL + * 3. node data contains zeroes + * and overwrite the node with random data again */ for(i=0; i<10; i++) { s = rand() % (blocksize/16); m = compll_alloc(s); isok(m, "compll_alloc(%d)", s); - p = (void *) compll_read(m); - isok(p != NULL, "compll_read()"); + p = compll_write(m); + isok(p != NULL, "compll_write()"); isok(!memcmp(ndata, p, s), "node data contains zeros"); + randdata(p, s, i*5+38213); + } + + /* now loop (in reverse order) through all the nodes we allocated first and + * check that their contents have not been changed (= 2 checks) */ + for(i=NODENUM; i>=1; i--) { + if(!allocs[i]) + continue; + s = (msize * i) / NODENUM; + p = (void *) compll_read(allocs[i]); + isok(p != NULL, "compll_read()"); + randdata(ndata, s, i); + isok(!memcmp(ndata, p, s), "node data has not been modified"); } return 0; diff --git a/test/provelist b/test/provelist index 042f451..2c4c012 100644 --- a/test/provelist +++ b/test/provelist @@ -10,4 +10,4 @@ ./func-lib 2048 4 100 ./func-lib 262144 4 1 ./func-lib 524288 4 1 -./func-nolib 2048 4 1 +./func-nolib 2048 1 1 -- cgit v1.2.3