summaryrefslogtreecommitdiff
path: root/test/func.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/func.c')
-rw-r--r--test/func.c49
1 files changed, 32 insertions, 17 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<fnlength; i++) {
compll_free(allocs[freenodes[i]]);
allocs[freenodes[i]] = 0;
}
/* and allocate a few nodes of random size again, and check that:
* 1. compll_alloc() > 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;