Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 55241 invoked by uid 500); 30 Apr 2001 20:34:06 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 55169 invoked by uid 1103); 30 Apr 2001 20:33:58 -0000 Date: 30 Apr 2001 20:33:58 -0000 Message-ID: <20010430203358.55168.qmail@apache.org> From: dreid@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/test testshmem.c dreid 01/04/30 13:33:58 Modified: test testshmem.c Log: Add some testing to testshmem. This needs more work, but at least we now try to stress it a little... Revision Changes Path 1.18 +140 -12 apr/test/testshmem.c Index: testshmem.c =================================================================== RCS file: /home/cvs/apr/test/testshmem.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- testshmem.c 2001/04/05 16:14:59 1.17 +++ testshmem.c 2001/04/30 20:33:55 1.18 @@ -73,6 +73,11 @@ apr_pool_t *context; mbox *boxes; +#define SIZE 256 +#define CYCLES 40 +#define TESTSIZE 4096 * SIZE +#define TEST2SIZE CYCLES * SIZE + static void msgwait(int boxnum) { volatile int test = 0; @@ -96,25 +101,36 @@ #if APR_HAS_SHARED_MEMORY apr_shmem_t *shm; pid_t pid; - int size; - + int size, cntr; + char *ptrs[CYCLES]; + apr_size_t psize[CYCLES]; + apr_status_t rv; + apr_size_t cksize; apr_initialize(); + - fprintf(stdout, "Initializing the context......."); + for (size = 0;size < CYCLES;size++){ + ptrs[size] = NULL; + psize[size] = sizeof(mbox) * (size + 1); + } + + printf("APR Shared Memory Test\n"); + printf("======================\n\n"); + printf("Initializing the context............................"); if (apr_pool_create(&context, NULL) != APR_SUCCESS) { - fprintf(stderr, "could not initialize\n"); + printf("could not initialize\n"); exit(-1); } - fprintf(stdout, "OK\n"); + printf("OK\n"); - fprintf(stdout, "Creating shared memory block......."); - if (apr_shm_init(&shm, 1048576, NULL, context) != APR_SUCCESS) { + printf("Creating shared memory block (%ld bytes)........", TESTSIZE); + if (apr_shm_init(&shm, TESTSIZE, NULL, context) != APR_SUCCESS) { fprintf(stderr, "Error allocating shared memory block\n"); exit(-1); } fprintf(stdout, "OK\n"); - fprintf(stdout, "Allocating shared memory......."); + printf("Allocating shared mbox memory......................."); size = sizeof(mbox) * 2; boxes = apr_shm_calloc(shm, size); if (boxes == NULL) { @@ -122,8 +138,120 @@ exit(-1); } fprintf(stdout, "OK\n"); + + printf("\nAbout to stress the alloc/free cycle.\n"); + printf("Smallest allocation will be %ld bytes\n", psize[0]); + printf("Largest allocation will be %ld bytes\n", psize[CYCLES -1]); + printf("I will be doing it in %d steps\n", CYCLES); + + printf("\tAllocating via apr_shm_malloc..............."); + for (cntr = 0;cntr < CYCLES;cntr++){ + ptrs[cntr] = apr_shm_malloc(shm, psize[cntr]); + if (ptrs[cntr] == NULL){ + printf("Failed at step %d, %ld bytes\n", cntr, psize[cntr]); + exit (-1); + } + } + printf("OK\n\tFreeing....................................."); + for (cntr = 0;cntr < CYCLES;cntr++){ + if (apr_shm_free(shm, ptrs[cntr]) != APR_SUCCESS){ + printf("Failed at step %d, %ld bytes\n", cntr, psize[cntr]); + exit (-1); + } + } + printf("OK\n"); + + printf("\tAllocating via apr_shm_calloc..............."); + for (cntr = CYCLES-1;cntr > -1;cntr--){ + ptrs[cntr] = apr_shm_malloc(shm, psize[cntr]); + if (ptrs[cntr] == NULL){ + printf("Failed at %ld bytes\n", psize[cntr]); + exit (-1); + } + } + printf("OK\n\tFreeing....................................."); + for (cntr = 0;cntr < CYCLES;cntr++){ + if (apr_shm_free(shm, ptrs[cntr]) != APR_SUCCESS){ + printf("Failed at step %d, %ld bytes\n", cntr, psize[cntr]); + exit (-1); + } + } + printf("OK\n"); + + printf("Checking we have all we should have remaining......."); + rv = apr_shm_avail(shm, &cksize); + if (rv == APR_ENOTIMPL){ + printf("Not Impl.\n"); + } else { + if (rv != APR_SUCCESS){ + printf("Failed!\n"); + exit (-1); + } + if (cksize == (TESTSIZE - size)){ + printf ("OK\n"); + } else { + printf ("Failed.\nShould have had %ld bytes, instead there are %ld bytes :(\n", + TESTSIZE - size, cksize); + exit(-1); + } + } + printf("%d cycles of malloc and calloc passed.\n\n", CYCLES); + + printf("Block test.\n"); + printf("\tI am about to allocate %ld bytes..........", TEST2SIZE); + if ((ptrs[0] = apr_shm_malloc(shm, TEST2SIZE)) == NULL){ + printf("Failed.\n"); + exit (-1); + } + printf ("OK\n"); + printf("\tFreeing the block of %ld bytes............", TEST2SIZE); + if ((rv = apr_shm_free(shm, ptrs[0])) != APR_SUCCESS){ + printf("Failed!\n"); + exit(-1); + } + printf ("OK\n"); + + printf ("\tAbout to allocate %d blocks of %d bytes....", CYCLES, SIZE); + for (cntr = 0;cntr < CYCLES;cntr++){ + if ((ptrs[cntr] = apr_shm_malloc(shm, SIZE)) == NULL){ + printf("Failed.\n"); + printf("Couldn't allocate block %d\n", cntr + 1); + exit (-1); + } + } + printf("Complete.\n"); + + printf ("\tAbout to free %d blocks of %d bytes........", CYCLES, SIZE); + for (cntr = 0;cntr < CYCLES;cntr++){ + if ((rv = apr_shm_free(shm, ptrs[cntr])) != APR_SUCCESS){ + printf("Failed\n"); + printf("Counldn't free block %d\n", cntr + 1); + exit (-1); + } + } + printf("Complete.\n"); + + printf("Checking we have all we should have remaining......."); + rv = apr_shm_avail(shm, &cksize); + if (rv == APR_ENOTIMPL){ + printf("Not Impl.\n"); + } else { + if (rv != APR_SUCCESS){ + printf("Failed!\n"); + exit (-1); + } + if (cksize == (TESTSIZE - size)){ + printf ("OK\n"); + } else { + printf ("Failed.\nShould have had %ld bytes, instead there are %ld bytes :(\n", + TESTSIZE - size, cksize); + exit(-1); + } + } - fprintf(stdout, "Creating a child process\n"); + printf("Block test complete.\n\n"); + + printf("Creating a child process\n"); pid = fork(); if (pid == 0) { apr_sleep(1); @@ -142,12 +270,12 @@ exit(1); } else { - fprintf(stderr, "Error creating a child process\n"); + printf("Error creating a child process\n"); exit(1); } #else - fprintf(stdout, "APR SHMEM test failed!\n"); - fprintf(stdout, "shmem is not supported on this platform\n"); + printf("APR SHMEM test not run!\n"); + printf("shmem is not supported on this platform\n"); return (-1); #endif }