Add debug and size options to memtest
authorteodor <teodor>
Thu, 10 Feb 2005 18:24:51 +0000 (18:24 +0000)
committerteodor <teodor>
Thu, 10 Feb 2005 18:24:51 +0000 (18:24 +0000)
expected/mem
memtest.c
tests/mem

index 594df35..c3578c6 100644 (file)
@@ -7,3 +7,12 @@ mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048320
 mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048320 freenew:0
 mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048320 freechild:1048508
 Child: 0
+lc:abcdefghijklmnopqrstuvwxyz uc:ABCDEFGHIJKLMNOPQRSTUVWXYZ free:1048500
+lc:abcdefghijklmnopqrstuvwxyz free:1048536
+uc:ABCDEFGHIJKLMNOPQRSTUVWXYZ free:1048500
+mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048396
+mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048396
+mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048336
+mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048336 freenew:0
+mixed:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz free:1048336 freechild:1048512
+Child: 0
index 223b49b..6f1aa09 100644 (file)
--- a/memtest.c
+++ b/memtest.c
@@ -41,12 +41,11 @@ static void
 usage() {
        puts(
        "Usage:\n"
-       "memtest [-c COUNT [-t]]\n"
+       "memtest [-c COUNT [-t [-D]] [-s MAXSIZE]]\n"
        );
        exit(1);
 }
 
-#define SZ     32
 
 extern char *optarg;
 extern int opterr;
@@ -54,17 +53,23 @@ extern int opterr;
 int
 main(int argn, char *argv[]) {
        MemoryContext   *base, *child;
-       int i;
-       int count=0, iscntx=0;
+       int i, SZ=32;
+       int count=0, iscntx=0, flags=0;
 
        opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
        opterr=0;
 
-       while((i=getopt(argn,argv,"c:ht")) != EOF) {
+       while((i=getopt(argn,argv,"s:Dc:ht")) != EOF) {
                switch(i) {
+                       case 's':
+                               SZ=atoi(optarg);
+                               break;
                        case 'c':
                                count=atoi(optarg);
                                break;
+                       case 'D':
+                               flags=MC_DEBUG;
+                               break;
                        case 't':
                                iscntx=1;
                                break;
@@ -79,8 +84,8 @@ main(int argn, char *argv[]) {
                char *ptr, *ptr1;
 
                /* test correctness */
-               base = allocMemoryContext(NULL, MC_DEBUG);
-               child = allocMemoryContext(base, MC_DEBUG);
+               base = allocMemoryContext(NULL, flags);
+               child = allocMemoryContext(base, flags);
 
                ptr = mcalloc(base, 30);
                for(i=0;i<26;i++)
@@ -123,7 +128,7 @@ main(int argn, char *argv[]) {
                freeMemoryContext(child);
                printf("Child: %d\n", (int)(base->child));
 
-               child = allocMemoryContext(base, MC_DEBUG);
+               child = allocMemoryContext(base, flags);
                freeMemoryContext(base);
        } else {
                struct timeval begin;   
@@ -132,7 +137,7 @@ main(int argn, char *argv[]) {
                srandom(1);
                if ( iscntx ) {
                        gettimeofday(&begin, NULL);
-                       base = allocMemoryContext(NULL, MC_DEBUG);
+                       base = allocMemoryContext(NULL, flags);
                        for(i=0;i<count;i++) {
                                ptr = mcalloc(base, 1+random()%SZ );
                                ptr1 = mcalloc(base, 1+random()%SZ );
index 4dafb25..70c2792 100644 (file)
--- a/tests/mem
+++ b/tests/mem
@@ -1 +1,2 @@
+./memtest -D
 ./memtest