dreid 01/05/30 04:03:39
Modified: include apr_sms.h
memory/unix apr_sms_std.c apr_sms_tracking.c
test testmem.c
Log:
Add an identity string to the memory modules. Justin pointed out that
there was no way of checking which module we were using, so now there
is :)
Updated the memory test to use the new test header and to check the
identity returned.
Submitted by: Concept from Justin Erenkrantz
Refined by Sander Striker
Reviewed by: David Reid
Revision Changes Path
1.6 +1 -0 apr/include/apr_sms.h
Index: apr_sms.h
===================================================================
RCS file: /home/cvs/apr/include/apr_sms.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apr_sms.h 2001/05/20 12:45:51 1.5
+++ apr_sms.h 2001/05/30 11:03:32 1.6
@@ -93,6 +93,7 @@
apr_sms_t *sibling_mem_sys;
apr_sms_t **ref_mem_sys;
apr_sms_t *accounting_mem_sys;
+ const char *identity; /* a string identifying the module */
struct apr_sms_cleanup *cleanups;
1.4 +3 -0 apr/memory/unix/apr_sms_std.c
Index: apr_sms_std.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms_std.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apr_sms_std.c 2001/05/20 22:34:53 1.3
+++ apr_sms_std.c 2001/05/30 11:03:34 1.4
@@ -66,6 +66,8 @@
#include <stdlib.h>
#include <assert.h>
+static const char *module_identity = "STANDARD";
+
/*
* standard memory system
*/
@@ -121,6 +123,7 @@
new_mem_sys->calloc_fn = apr_sms_std_calloc;
new_mem_sys->realloc_fn = apr_sms_std_realloc;
new_mem_sys->free_fn = apr_sms_std_free;
+ new_mem_sys->identity = module_identity;
/* as we're not a tracking memory module, i.e. we don't keep
* track of our allocations, we don't have apr_sms_reset or
* apr_sms_destroy functions.
1.4 +3 -0 apr/memory/unix/apr_sms_tracking.c
Index: apr_sms_tracking.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms_tracking.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apr_sms_tracking.c 2001/05/20 22:34:54 1.3
+++ apr_sms_tracking.c 2001/05/30 11:03:34 1.4
@@ -68,6 +68,8 @@
#include <stdlib.h>
#include <assert.h>
+static const char *module_identity = "TRACKING";
+
/*
* Simple tracking memory system
*/
@@ -253,6 +255,7 @@
new_mem_sys->free_fn = apr_sms_tracking_free;
new_mem_sys->reset_fn = apr_sms_tracking_reset;
new_mem_sys->destroy_fn = apr_sms_tracking_destroy;
+ new_mem_sys->identity = module_identity;
tms = (apr_sms_tracking_t *)new_mem_sys;
tms->nodes = NULL;
1.6 +37 -42 apr/test/testmem.c
Index: testmem.c
===================================================================
RCS file: /home/cvs/apr/test/testmem.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- testmem.c 2001/05/14 23:19:54 1.5
+++ testmem.c 2001/05/30 11:03:37 1.6
@@ -59,6 +59,7 @@
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_time.h"
+#include "test_apr.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -75,12 +76,13 @@
{
int cntr;
- printf("\tMalloc'ing %d lumps of memory, each %d bytes......",
+ printf(" Malloc'ing %d lumps of memory, each %d bytes ",
LUMPS, LUMP_SIZE);
for (cntr = 0;cntr < LUMPS;cntr ++){
ptrs[cntr] = apr_sms_malloc(ams, LUMP_SIZE);
if (!ptrs[cntr]){
- printf("Failed @ lump %d of %d\n", cntr + 1, LUMPS);
+ printf("Failed\n");
+ fprintf(stderr,"Failed @ lump %d of %d\n", cntr + 1, LUMPS);
exit (-1);
}
}
@@ -91,21 +93,23 @@
{
int cntr, cntr2;
- printf("\tCalloc'ing %d lumps of memory, each %d bytes......",
+ printf(" Calloc'ing %d lumps of memory, each %d bytes ",
LUMPS, LUMP_SIZE);
for (cntr = 0;cntr < LUMPS;cntr ++){
ptrs[cntr] = apr_sms_calloc(ams, LUMP_SIZE);
if (!ptrs[cntr]){
- printf("Failed @ lump %d of %d\n", cntr + 1, LUMPS);
+ printf("Failed\n");
+ fprintf(stderr, "Failed @ lump %d of %d\n", cntr + 1, LUMPS);
exit (-1);
}
}
printf ("OK\n");
- printf("\t (checking that memory is zeroed..................");
+ printf(" (checking that memory is zeroed ");
for (cntr = 0;cntr < LUMPS;cntr++){
for (cntr2 = 0;cntr2 < LUMP_SIZE; cntr2 ++){
if (*(ptrs[cntr] + cntr2) != 0){
- printf("Failed!\nGot %d instead of 0 at byte %d\n",
+ printf("Failed\n");
+ fprintf(stderr, "Failed!\nGot %d instead of 0 at byte %d\n",
*(ptrs[cntr] + cntr2), cntr2 + 1);
exit (-1);
}
@@ -118,20 +122,22 @@
{
int cntr,cntr2;
- printf("\tWriting to the lumps of memory......................");
+ printf(" Writing to the lumps of memory ");
for (cntr = 0;cntr < LUMPS;cntr ++){
if (memset(ptrs[cntr], cntr, LUMP_SIZE) != ptrs[cntr]){
- printf("Failed to write into lump %d\n", cntr + 1);
+ printf("Failed\n");
+ fprintf(stderr,"Failed to write into lump %d\n", cntr + 1);
exit(-1);
}
}
printf("OK\n");
- printf("\tCheck what we wrote.................................");
+ printf(" Check what we wrote ");
for (cntr = 0;cntr < LUMPS;cntr++){
for (cntr2 = 0;cntr2 < LUMP_SIZE; cntr2 ++){
if (*(ptrs[cntr] + cntr2) != cntr){
- printf("Got %d instead of %d at byte %d\n",
+ printf("Failed\n");
+ fprintf(stderr,"Got %d instead of %d at byte %d\n",
*(ptrs[cntr] + cntr2), cntr, cntr2 + 1);
exit (-1);
}
@@ -144,10 +150,11 @@
{
int cntr;
- printf("\tFreeing the memory we created.......................");
+ printf(" Freeing the memory we created ");
for (cntr = 0;cntr < LUMPS;cntr ++){
if (apr_sms_free(ams, ptrs[cntr]) != APR_SUCCESS){
- printf("Failed to free block %d\n", cntr + 1);
+ printf("Failed\n");
+ fprintf(stderr,"Failed to free block %d\n", cntr + 1);
exit (-1);
}
}
@@ -163,12 +170,11 @@
printf("===============\n\n");
printf("Standard Memory\n");
- printf("\tCreating the memory area............................");
- if (apr_sms_std_create(&ams) != APR_SUCCESS){
- printf("Failed.\n");
- exit(-1);
- }
- printf("OK\n");
+ STD_TEST_NEQ(" Creating the memory system",
+ apr_sms_std_create(&ams))
+ TEST_NEQ(" Checking identity of memory system",
+ strcmp(ams->identity, "STANDARD"), 0,
+ "OK","Not STANDARD")
malloc_mem(ams);
do_test(ams);
@@ -178,38 +184,27 @@
do_free(ams);
printf("Tracking Memory\n");
- printf("\tCreating the memory area............................");
- if (apr_sms_tracking_create(&tms, ams) != APR_SUCCESS){
- printf("Failed.\n");
- exit(-1);
- }
- printf("OK\n");
+ STD_TEST_NEQ(" Creating the memory system",
+ apr_sms_tracking_create(&tms, ams))
+
+ TEST_NEQ(" Checking the identity of the memory system",
+ strcmp(tms->identity, "TRACKING"), 0,
+ "OK", "Not TRACKING")
malloc_mem(tms);
do_test(tms);
- printf("\tAbout to reset the tracking memory..................");
- if (apr_sms_reset(tms) != APR_SUCCESS){
- printf("Failed.\n");
- exit(-1);
- }
- printf("OK\n");
+ STD_TEST_NEQ(" About to reset the tracking system",
apr_sms_reset(tms))
+
calloc_mem(tms);
do_test(tms);
do_free(tms);
- printf("Trying to destroy the tracking memory segment...............");
- if (apr_sms_destroy(tms) != APR_SUCCESS){
- printf("Failed.\n");
- exit (-1);
- }
- printf("OK\n");
+ STD_TEST_NEQ("Trying to destroy the tracking memory system",
+ apr_sms_destroy(tms))
- printf("Trying to destroy the standard memory segment...............");
- if (apr_sms_destroy(ams) != APR_SUCCESS){
- printf("Failed.\n");
- exit (-1);
- }
- printf("OK\n\n");
+
+ STD_TEST_NEQ("Trying to destroy the standard memory system",
+ apr_sms_destroy(ams))
printf("Memory test passed.\n");
return (0);