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:28:12 UTC

svn commit: r562889 - in /apr/apr-util/trunk/test: Makefile.in Makefile.win abts_tests.h testreslist.c testutil.h

Author: davi
Date: Sun Aug  5 08:28:11 2007
New Revision: 562889

URL: http://svn.apache.org/viewvc?view=rev&rev=562889
Log:
Cleanup and merge testreslit 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/testreslist.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=562889&r1=562888&r2=562889
==============================================================================
--- apr/apr-util/trunk/test/Makefile.in (original)
+++ apr/apr-util/trunk/test/Makefile.in Sun Aug  5 08:28:11 2007
@@ -3,7 +3,7 @@
 INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
 
 PROGRAMS = testall testdbm testdate testxml testrmm \
-	   testreslist testqueue testxlate dbd testssl \
+	   testqueue testxlate dbd testssl \
            echod sockperf
 TARGETS = $(PROGRAMS)
 
@@ -61,11 +61,6 @@
 testrmm: $(testrmm_OBJECTS) $(testrmm_LDADD)
 	$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testrmm_OBJECTS) $(testrmm_LDADD) $(PROGRAM_DEPENDENCIES)
 
-testreslist_OBJECTS = testreslist.lo
-testreslist_LDADD =  $(TARGET_LIB_PATH)
-testreslist: $(testreslist_OBJECTS) $(testreslist_LDADD)
-	$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testreslist_OBJECTS) $(testreslist_LDADD) $(PROGRAM_DEPENDENCIES)
-
 testqueue_OBJECTS = testqueue.lo
 testqueue_LDADD =  $(TARGET_LIB_PATH)
 testqueue: $(testqueue_OBJECTS) $(testqueue_LDADD)
@@ -95,7 +90,7 @@
 
 testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \
 	testbuckets.lo testpass.lo testmd4.lo testmd5.lo testldap.lo \
-	testdaterfc.lo testdbd.lo testmemcache.lo
+	testdaterfc.lo testdbd.lo testmemcache.lo testreslist.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=562889&r1=562888&r2=562889
==============================================================================
--- apr/apr-util/trunk/test/Makefile.win (original)
+++ apr/apr-util/trunk/test/Makefile.win Sun Aug  5 08:28:11 2007
@@ -109,7 +109,6 @@
 ##!		$(OUTPUT_DIR)\testmd4.exe \
 ##!		$(OUTPUT_DIR)\testmd5.exe \
 ##!		$(OUTPUT_DIR)\testqueue.exe \
-##!		$(OUTPUT_DIR)\testreslist.exe \
 ##!		$(OUTPUT_DIR)\testrmm.exe \
 ##!		$(OUTPUT_DIR)\teststrmatch.exe \
 ##!		$(OUTPUT_DIR)\testuri.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=562889&r1=562888&r2=562889
==============================================================================
--- apr/apr-util/trunk/test/abts_tests.h (original)
+++ apr/apr-util/trunk/test/abts_tests.h Sun Aug  5 08:28:11 2007
@@ -33,7 +33,8 @@
     {testldap},
     {testdbd},
     {testdaterfc},
-    {testmemcache}
+    {testmemcache},
+    {testreslist}
 };
 
 #endif /* APR_TEST_INCLUDES */

Modified: apr/apr-util/trunk/test/testreslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testreslist.c?view=diff&rev=562889&r1=562888&r2=562889
==============================================================================
--- apr/apr-util/trunk/test/testreslist.c (original)
+++ apr/apr-util/trunk/test/testreslist.c Sun Aug  5 08:28:11 2007
@@ -16,22 +16,19 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#include "apu.h"
 #include "apr_reslist.h"
-#include "apr_thread_proc.h"
+#include "apr_thread_pool.h"
 
 #if APR_HAVE_TIME_H
 #include <time.h>
 #endif /* APR_HAVE_TIME_H */
 
-#if !APR_HAS_THREADS
-
-int main(void)
-{
-    fprintf(stderr, "this program requires APR thread support\n");
-    return 0;
-}
+#include "abts.h"
+#include "testutil.h"
 
-#else
+#if APR_HAS_THREADS
 
 #define RESLIST_MIN   3
 #define RESLIST_SMAX 10
@@ -64,9 +61,6 @@
     res = apr_palloc(pool, sizeof(*res));
     res->id = my_params->c_count++;
 
-    printf("++ constructing new resource [id:%d, #%d/%d]\n", res->id,
-       my_params->c_count, my_params->d_count);
-
     /* Sleep for awhile, to simulate construction overhead. */
     apr_sleep(my_params->sleep_upon_construct);
 
@@ -81,9 +75,6 @@
     my_resource_t *res = resource;
     my_parameters_t *my_params = params;
 
-    printf("-- destructing old resource [id:%d, #%d/%d]\n", res->id,
-           my_params->c_count, ++my_params->d_count);
-
     apr_sleep(my_params->sleep_upon_destruct);
 
     return APR_SUCCESS;
@@ -91,6 +82,7 @@
 
 typedef struct {
     int tid;
+    abts_case *tc;
     apr_reslist_t *reslist;
     apr_interval_time_t work_delay_sleep;
 } my_thread_info_t;
@@ -98,47 +90,33 @@
 static void * APR_THREAD_FUNC resource_consuming_thread(apr_thread_t *thd,
                                                         void *data)
 {
+    int i;
+    void *vp;
     apr_status_t rv;
+    my_resource_t *res;
     my_thread_info_t *thread_info = data;
     apr_reslist_t *rl = thread_info->reslist;
-    int i;
 
     for (i = 0; i < CONSUMER_ITERATIONS; i++) {
-        my_resource_t *res;
-        void *vp;
         rv = apr_reslist_acquire(rl, &vp);
-        if (rv != APR_SUCCESS) {
-            fprintf(stderr, "Failed to retrieve resource from reslist\n");
-            apr_thread_exit(thd, rv);
-            return NULL;
-        }
+        ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
         res = vp;
-        printf("  [tid:%d,iter:%d] using resource id:%d\n", thread_info->tid,
-               i, res->id);
         apr_sleep(thread_info->work_delay_sleep);
-/* simulate a 5% chance of the resource being bad */
-        if ( drand48() < 0.95 ) {
+
+        /* simulate a 5% chance of the resource being bad */
+        if (drand48() < 0.95) {
            rv = apr_reslist_release(rl, res);
-            if (rv != APR_SUCCESS) {
-                fprintf(stderr, "Failed to return resource to reslist\n");
-                apr_thread_exit(thd, rv);
-                return NULL;
-            }
+           ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
        } else {
-           printf("invalidating resource id:%d\n", res->id) ;
            rv = apr_reslist_invalidate(rl, res);
-            if (rv != APR_SUCCESS) {
-                fprintf(stderr, "Failed to invalidate resource\n");
-                apr_thread_exit(thd, rv);
-                return NULL;
-            }
+           ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
        }
     }
 
     return APR_SUCCESS;
 }
 
-static void test_timeout(apr_reslist_t *rl)
+static void test_timeout(abts_case *tc, apr_reslist_t *rl)
 {
     apr_status_t rv;
     my_resource_t *resources[RESLIST_HMAX];
@@ -146,31 +124,23 @@
     void *vp;
     int i;
 
-    printf("Setting timeout to 1000us: ");
     apr_reslist_timeout_set(rl, 1000);
-    fprintf(stdout, "OK\n");
 
-    /* deplete all possible resources from the resource list 
-     * so that the next call will block until timeout is reached 
-     * (since there are no other threads to make a resource 
+    /* deplete all possible resources from the resource list
+     * so that the next call will block until timeout is reached
+     * (since there are no other threads to make a resource
      * available)
      */
 
     for (i = 0; i < RESLIST_HMAX; i++) {
         rv = apr_reslist_acquire(rl, (void**)&resources[i]);
-        if (rv != APR_SUCCESS) {
-            fprintf(stderr, "couldn't acquire resource: %d\n", rv);
-            exit(1);
-        }
+        ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
     }
 
     /* next call will block until timeout is reached */
     rv = apr_reslist_acquire(rl, &vp);
-    if (!APR_STATUS_IS_TIMEUP(rv)) {
-        fprintf(stderr, "apr_reslist_acquire()->%d instead of TIMEUP\n", 
-                rv);
-        exit(1);
-    }
+    ABTS_TRUE(tc, APR_STATUS_IS_TIMEUP(rv));
+
     res = vp;
 
     /* release the resources; otherwise the destroy operation
@@ -178,123 +148,65 @@
      */
     for (i = 0; i < RESLIST_HMAX; i++) {
         rv = apr_reslist_release(rl, &resources[i]);
-        if (rv != APR_SUCCESS) {
-            fprintf(stderr, "couldn't release resource: %d\n", rv);
-            exit(1);
-        }
+        ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
     }
 }
 
-static apr_status_t test_reslist(apr_pool_t *parpool)
+static void test_reslist(abts_case *tc, void *data)
 {
+    int i;
     apr_status_t rv;
-    apr_pool_t *pool;
     apr_reslist_t *rl;
     my_parameters_t *params;
-    int i;
-    apr_thread_t *my_threads[CONSUMER_THREADS];
-    my_thread_info_t my_thread_info[CONSUMER_THREADS];
-    srand48(time(0)) ;
-
-    printf("Creating child pool.......................");
-    rv = apr_pool_create(&pool, parpool);
-    if (rv != APR_SUCCESS) {
-        fprintf(stderr, "Error creating child pool\n");
-        return rv;
-    }
-    printf("OK\n");
+    apr_thread_pool_t *thrp;
+    my_thread_info_t thread_info[CONSUMER_THREADS];
+
+    /* XXX: non-portable */
+    srand48(time(0));
+
+    rv = apr_thread_pool_create(&thrp, CONSUMER_THREADS/2, CONSUMER_THREADS, p);
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
 
     /* Create some parameters that will be passed into each
      * constructor and destructor call. */
-    params = apr_pcalloc(pool, sizeof(*params));
+    params = apr_pcalloc(p, sizeof(*params));
     params->sleep_upon_construct = CONSTRUCT_SLEEP_TIME;
     params->sleep_upon_destruct = DESTRUCT_SLEEP_TIME;
 
     /* We're going to want 10 blocks of data from our target rmm. */
-    printf("Creating resource list:\n"
-           " min/smax/hmax: %d/%d/%d\n"
-           " ttl: %" APR_TIME_T_FMT "\n", RESLIST_MIN, RESLIST_SMAX,
-           RESLIST_HMAX, RESLIST_TTL);
     rv = apr_reslist_create(&rl, RESLIST_MIN, RESLIST_SMAX, RESLIST_HMAX,
                             RESLIST_TTL, my_constructor, my_destructor,
-                            params, pool);
-    if (rv != APR_SUCCESS) { 
-        fprintf(stderr, "Error allocating shared memory block\n");
-        return rv;
-    }
-    fprintf(stdout, "OK\n");
+                            params, p);
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
 
-    printf("Creating %d threads", CONSUMER_THREADS);
     for (i = 0; i < CONSUMER_THREADS; i++) {
-        putchar('.');
-        my_thread_info[i].tid = i;
-        my_thread_info[i].reslist = rl;
-        my_thread_info[i].work_delay_sleep = WORK_DELAY_SLEEP_TIME;
-        rv = apr_thread_create(&my_threads[i], NULL,
-                               resource_consuming_thread, &my_thread_info[i],
-                               pool);
-        if (rv != APR_SUCCESS) {
-            fprintf(stderr, "Failed to create thread %d\n", i);
-            return rv;
-        }
+        thread_info[i].tid = i;
+        thread_info[i].tc = tc;
+        thread_info[i].reslist = rl;
+        thread_info[i].work_delay_sleep = WORK_DELAY_SLEEP_TIME;
+        rv = apr_thread_pool_push(thrp, resource_consuming_thread,
+                                  &thread_info[i], 0, NULL);
+        ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
     }
-    printf("\nDone!\n");
 
-    printf("Waiting for threads to finish");
-    for (i = 0; i < CONSUMER_THREADS; i++) {
-        apr_status_t thread_rv;
-        putchar('.');
-        apr_thread_join(&thread_rv, my_threads[i]);
-        if (rv != APR_SUCCESS) {
-            fprintf(stderr, "Failed to join thread %d\n", i);
-            return rv;
-        }
-    }
-    printf("\nDone!\n");
+    rv = apr_thread_pool_destroy(thrp);
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
 
-    test_timeout(rl);
+    test_timeout(tc, rl);
 
-    printf("Destroying resource list.................");
     rv = apr_reslist_destroy(rl);
-    if (rv != APR_SUCCESS) {
-        printf("FAILED\n");
-        return rv;
-    }
-    printf("OK\n");
-
-    apr_pool_destroy(pool);
-
-    return APR_SUCCESS;
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
 }
 
+#endif /* APR_HAS_THREADS */
 
-int main(void)
+abts_suite *testreslist(abts_suite *suite)
 {
-    apr_status_t rv;
-    apr_pool_t *pool;
-    char errmsg[200];
-
-    apr_initialize();
-    
-    printf("APR Resource List 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");
+    suite = ADD_SUITE(suite);
 
-    rv = test_reslist(pool);
-    if (rv != APR_SUCCESS) {
-        printf("Resource list test FAILED: [%d] %s\n",
-               rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
-        exit(-2);
-    }
-    printf("Resource list test passed!\n");
+#if APR_HAS_THREADS
+    abts_run_test(suite, test_reslist, NULL);
+#endif
 
-    return 0;
+    return suite;
 }
-
-#endif /* APR_HAS_THREADS */

Modified: apr/apr-util/trunk/test/testutil.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testutil.h?view=diff&rev=562889&r1=562888&r2=562889
==============================================================================
--- apr/apr-util/trunk/test/testutil.h (original)
+++ apr/apr-util/trunk/test/testutil.h Sun Aug  5 08:28:11 2007
@@ -54,5 +54,6 @@
 abts_suite *testdbd(abts_suite *suite);
 abts_suite *testdaterfc(abts_suite *suite);
 abts_suite *testmemcache(abts_suite *suite);
+abts_suite *testreslist(abts_suite *suite);
 
 #endif /* APR_TEST_INCLUDES */