You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by da...@apache.org on 2007/08/05 17:42:30 UTC
svn commit: r562897 - in /apr/apr-util/trunk/test: Makefile.in Makefile.win
abts_tests.h testrmm.c testutil.h
Author: davi
Date: Sun Aug 5 08:42:29 2007
New Revision: 562897
URL: http://svn.apache.org/viewvc?view=rev&rev=562897
Log:
Cleanup and merge testrmm into the abts test suite (testall).
Modified:
apr/apr-util/trunk/test/Makefile.in
apr/apr-util/trunk/test/Makefile.win
apr/apr-util/trunk/test/abts_tests.h
apr/apr-util/trunk/test/testrmm.c
apr/apr-util/trunk/test/testutil.h
Modified: apr/apr-util/trunk/test/Makefile.in
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/Makefile.in?view=diff&rev=562897&r1=562896&r2=562897
==============================================================================
--- apr/apr-util/trunk/test/Makefile.in (original)
+++ apr/apr-util/trunk/test/Makefile.in Sun Aug 5 08:42:29 2007
@@ -2,9 +2,7 @@
INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
-PROGRAMS = testall testdbm testrmm \
- dbd testssl \
- echod sockperf
+PROGRAMS = testall testdbm dbd testssl echod sockperf
TARGETS = $(PROGRAMS)
APRUTIL_DOTTED_VERSION=@APRUTIL_DOTTED_VERSION@
@@ -46,11 +44,6 @@
testdbd: $(testdbd_OBJECTS) $(testdbd_LDADD)
$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testdbd_OBJECTS) $(testdbd_LDADD) $(PROGRAM_DEPENDENCIES)
-testrmm_OBJECTS = testrmm.lo
-testrmm_LDADD = $(TARGET_LIB_PATH)
-testrmm: $(testrmm_OBJECTS) $(testrmm_LDADD)
- $(LINK_PROG) $(APRUTIL_LDFLAGS) $(testrmm_OBJECTS) $(testrmm_LDADD) $(PROGRAM_DEPENDENCIES)
-
testssl_OBJECTS = testssl.lo
testssl_LDADD = $(TARGET_LIB_PATH)
testssl: $(testssl_OBJECTS) $(testssl_LDADD)
@@ -71,7 +64,7 @@
testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \
testbuckets.lo testpass.lo testmd4.lo testmd5.lo testldap.lo \
testdate.lo testdbd.lo testmemcache.lo testreslist.lo testqueue.lo \
- testxml.lo testxlate.lo
+ testxml.lo testxlate.lo testrmm.lo
testall_LDADD = $(TARGET_LIB_PATH)
testall: $(testall_OBJECTS) $(testall_LDADD)
$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD) $(PROGRAM_DEPENDENCIES)
Modified: apr/apr-util/trunk/test/Makefile.win
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/Makefile.win?view=diff&rev=562897&r1=562896&r2=562897
==============================================================================
--- apr/apr-util/trunk/test/Makefile.win (original)
+++ apr/apr-util/trunk/test/Makefile.win Sun Aug 5 08:42:29 2007
@@ -109,14 +109,12 @@
##! $(OUTPUT_DIR)\testmd4.exe \
##! $(OUTPUT_DIR)\testmd5.exe \
##! $(OUTPUT_DIR)\testqueue.exe \
-##! $(OUTPUT_DIR)\testrmm.exe \
##! $(OUTPUT_DIR)\teststrmatch.exe \
##! $(OUTPUT_DIR)\testuri.exe \
##! $(OUTPUT_DIR)\testuuid.exe
ALL_TARGETS = $(OUTPUT_DIR)\testdbm.exe \
$(OUTPUT_DIR)\testqueue.exe \
- $(OUTPUT_DIR)\testrmm.exe \
$(OUTPUT_DIR)\testmd4.exe \
$(OUTPUT_DIR)\testmd5.exe
Modified: apr/apr-util/trunk/test/abts_tests.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/abts_tests.h?view=diff&rev=562897&r1=562896&r2=562897
==============================================================================
--- apr/apr-util/trunk/test/abts_tests.h (original)
+++ apr/apr-util/trunk/test/abts_tests.h Sun Aug 5 08:42:29 2007
@@ -37,7 +37,8 @@
{testreslist},
{testqueue},
{testxml},
- {testxlate}
+ {testxlate},
+ {testrmm}
};
#endif /* APR_TEST_INCLUDES */
Modified: apr/apr-util/trunk/test/testrmm.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testrmm.c?view=diff&rev=562897&r1=562896&r2=562897
==============================================================================
--- apr/apr-util/trunk/test/testrmm.c (original)
+++ apr/apr-util/trunk/test/testrmm.c Sun Aug 5 08:42:29 2007
@@ -21,12 +21,8 @@
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_time.h"
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#if APR_HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+#include "abts.h"
+#include "testutil.h"
#if APR_HAS_SHARED_MEMORY
@@ -34,7 +30,7 @@
#define FRAG_COUNT 10
#define SHARED_SIZE (apr_size_t)(FRAG_SIZE * FRAG_COUNT * sizeof(char*))
-static apr_status_t test_rmm(apr_pool_t *parpool)
+static void test_rmm(abts_case *tc, void *data)
{
apr_status_t rv;
apr_pool_t *pool;
@@ -45,152 +41,108 @@
int i;
void *entity;
- rv = apr_pool_create(&pool, parpool);
- if (rv != APR_SUCCESS) {
- fprintf(stderr, "Error creating child pool\n");
- return rv;
- }
+ rv = apr_pool_create(&pool, p);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
/* We're going to want 10 blocks of data from our target rmm. */
size = SHARED_SIZE + apr_rmm_overhead_get(FRAG_COUNT + 1);
- printf("Creating anonymous shared memory (%"
- APR_SIZE_T_FMT " bytes).....", size);
rv = apr_shm_create(&shm, size, NULL, pool);
- if (rv != APR_SUCCESS) {
- fprintf(stderr, "Error allocating shared memory block\n");
- return rv;
- }
- fprintf(stdout, "OK\n");
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- printf("Creating rmm segment.............................");
- rv = apr_rmm_init(&rmm, NULL, apr_shm_baseaddr_get(shm), size,
- pool);
-
- if (rv != APR_SUCCESS) {
- fprintf(stderr, "Error allocating rmm..............\n");
- return rv;
- }
- fprintf(stdout, "OK\n");
+ if (rv != APR_SUCCESS)
+ return;
+
+ rv = apr_rmm_init(&rmm, NULL, apr_shm_baseaddr_get(shm), size, pool);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+ if (rv != APR_SUCCESS)
+ return;
+
+ /* Creating each fragment of size fragsize */
fragsize = SHARED_SIZE / FRAG_COUNT;
- printf("Creating each fragment of size %" APR_SIZE_T_FMT "................",
- fragsize);
off = apr_palloc(pool, FRAG_COUNT * sizeof(apr_rmm_off_t));
for (i = 0; i < FRAG_COUNT; i++) {
off[i] = apr_rmm_malloc(rmm, fragsize);
- }
- fprintf(stdout, "OK\n");
-
- printf("Checking for out of memory allocation............");
- if (apr_rmm_malloc(rmm, FRAG_SIZE * FRAG_COUNT) == 0) {
- fprintf(stdout, "OK\n");
- }
- else {
- return APR_EGENERAL;
}
- printf("Checking each fragment for address alignment.....");
+ /* Checking for out of memory allocation */
+ i = apr_rmm_malloc(rmm, FRAG_SIZE * FRAG_COUNT);
+ ABTS_INT_EQUAL(tc, i, 0);
+
+ /* Checking each fragment for address alignment */
for (i = 0; i < FRAG_COUNT; i++) {
char *c = apr_rmm_addr_get(rmm, off[i]);
apr_size_t sc = (apr_size_t)c;
- if (off[i] == 0) {
- printf("allocation failed for offset %d\n", i);
- return APR_ENOMEM;
- }
-
- if (sc & 7) {
- printf("Bad alignment for fragment %d; %p not %p!\n",
- i, c, (void *)APR_ALIGN_DEFAULT((apr_size_t)c));
- return APR_EGENERAL;
- }
+ ABTS_TRUE(tc, off[i]);
+ ABTS_TRUE(tc, !(sc & 7));
}
- fprintf(stdout, "OK\n");
-
- printf("Setting each fragment to a unique value..........");
+
+ /* Setting each fragment to a unique value */
for (i = 0; i < FRAG_COUNT; i++) {
int j;
char **c = apr_rmm_addr_get(rmm, off[i]);
for (j = 0; j < FRAG_SIZE; j++, c++) {
*c = apr_itoa(pool, i + j);
}
- }
- fprintf(stdout, "OK\n");
+ }
- printf("Checking each fragment for its unique value......");
+ /* Checking each fragment for its unique value */
for (i = 0; i < FRAG_COUNT; i++) {
int j;
char **c = apr_rmm_addr_get(rmm, off[i]);
for (j = 0; j < FRAG_SIZE; j++, c++) {
char *d = apr_itoa(pool, i + j);
- if (strcmp(*c, d) != 0) {
- return APR_EGENERAL;
- }
+ ABTS_STR_EQUAL(tc, *c, d);
}
- }
- fprintf(stdout, "OK\n");
+ }
- printf("Freeing each fragment............................");
+ /* Freeing each fragment */
for (i = 0; i < FRAG_COUNT; i++) {
rv = apr_rmm_free(rmm, off[i]);
- if (rv != APR_SUCCESS) {
- return rv;
- }
- }
- fprintf(stdout, "OK\n");
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+ }
- printf("Creating one large segment.......................");
+ /* Creating one large segment */
off[0] = apr_rmm_calloc(rmm, SHARED_SIZE);
- fprintf(stdout, "OK\n");
- printf("Setting large segment............................");
+ /* Setting large segment */
for (i = 0; i < FRAG_COUNT * FRAG_SIZE; i++) {
char **c = apr_rmm_addr_get(rmm, off[0]);
c[i] = apr_itoa(pool, i);
}
- fprintf(stdout, "OK\n");
- printf("Freeing large segment............................");
- apr_rmm_free(rmm, off[0]);
- fprintf(stdout, "OK\n");
+ /* Freeing large segment */
+ rv = apr_rmm_free(rmm, off[0]);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- printf("Creating each fragment of size %" APR_SIZE_T_FMT " (again)........",
- fragsize);
+ /* Creating each fragment of size fragsize */
for (i = 0; i < FRAG_COUNT; i++) {
off[i] = apr_rmm_malloc(rmm, fragsize);
- }
- fprintf(stdout, "OK\n");
+ }
- printf("Freeing each fragment backwards..................");
+ /* Freeing each fragment backwards */
for (i = FRAG_COUNT - 1; i >= 0; i--) {
rv = apr_rmm_free(rmm, off[i]);
- if (rv != APR_SUCCESS) {
- return rv;
- }
- }
- fprintf(stdout, "OK\n");
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+ }
- printf("Creating one large segment (again)...............");
+ /* Creating one large segment (again) */
off[0] = apr_rmm_calloc(rmm, SHARED_SIZE);
- fprintf(stdout, "OK\n");
- printf("Freeing large segment............................");
- apr_rmm_free(rmm, off[0]);
- fprintf(stdout, "OK\n");
+ /* Freeing large segment */
+ rv = apr_rmm_free(rmm, off[0]);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- printf("Checking realloc.................................");
+ /* Checking realloc */
off[0] = apr_rmm_calloc(rmm, SHARED_SIZE - 100);
off[1] = apr_rmm_calloc(rmm, 100);
- if (off[0] == 0 || off[1] == 0) {
- printf("FAILED\n");
- return APR_EINVAL;
- }
+ ABTS_TRUE(tc, off[0]);
+ ABTS_TRUE(tc, off[1]);
+
entity = apr_rmm_addr_get(rmm, off[1]);
rv = apr_rmm_free(rmm, off[0]);
- if (rv != APR_SUCCESS) {
- printf("FAILED\n");
- return rv;
- }
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
{
unsigned char *c = entity;
@@ -205,77 +157,35 @@
/* now we can realloc off[1] and get many more bytes */
off[0] = apr_rmm_realloc(rmm, entity, SHARED_SIZE - 100);
- if (off[0] == 0) {
- printf("FAILED\n");
- return APR_EINVAL;
- }
+ ABTS_TRUE(tc, off[0]);
{
unsigned char *c = apr_rmm_addr_get(rmm, off[0]);
/* fill in the region */
for (i = 0; i < 100; i++) {
- if (c[i] != (i < 50 ? 0 : i)) {
- printf("FAILED at offset %d: %hx\n", i, c[i]);
- return APR_EGENERAL;
- }
+ ABTS_TRUE(tc, c[i] == (i < 50 ? 0 : i));
}
}
- fprintf(stdout, "OK\n");
-
- printf("Destroying rmm segment...........................");
rv = apr_rmm_destroy(rmm);
- if (rv != APR_SUCCESS) {
- printf("FAILED\n");
- return rv;
- }
- printf("OK\n");
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- printf("Destroying shared memory segment.................");
rv = apr_shm_destroy(shm);
- if (rv != APR_SUCCESS) {
- printf("FAILED\n");
- return rv;
- }
- printf("OK\n");
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
apr_pool_destroy(pool);
-
- return APR_SUCCESS;
}
+#endif /* APR_HAS_SHARED_MEMORY */
-int main(void)
+abts_suite *testrmm(abts_suite *suite)
{
- apr_status_t rv;
- apr_pool_t *pool;
- char errmsg[200];
+ suite = ADD_SUITE(suite);
- apr_initialize();
-
- printf("APR RMM Memory Test\n");
- printf("======================\n\n");
-
- printf("Initializing the pool............................");
- if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
- printf("could not initialize pool\n");
- exit(-1);
- }
- printf("OK\n");
-
- rv = test_rmm(pool);
- if (rv != APR_SUCCESS) {
- printf("Anonymous shared memory test FAILED: [%d] %s\n",
- rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
- exit(-2);
- }
- printf("RMM test passed!\n");
+#if APR_HAS_SHARED_MEMORY
+ abts_run_test(suite, test_rmm, NULL);
+#endif
- return 0;
+ return suite;
}
-
-#else /* APR_HAS_SHARED_MEMORY */
-#error shmem is not supported on this platform
-#endif /* APR_HAS_SHARED_MEMORY */
-
Modified: apr/apr-util/trunk/test/testutil.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testutil.h?view=diff&rev=562897&r1=562896&r2=562897
==============================================================================
--- apr/apr-util/trunk/test/testutil.h (original)
+++ apr/apr-util/trunk/test/testutil.h Sun Aug 5 08:42:29 2007
@@ -58,5 +58,6 @@
abts_suite *testqueue(abts_suite *suite);
abts_suite *testxml(abts_suite *suite);
abts_suite *testxlate(abts_suite *suite);
+abts_suite *testrmm(abts_suite *suite);
#endif /* APR_TEST_INCLUDES */