apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test Makefile.in test_apr.h testall.c testthread.c
Date Tue, 03 Dec 2002 22:42:02 GMT
rbb         2002/12/03 14:42:02

  Modified:    test     Makefile.in test_apr.h testall.c testthread.c
  Log:
  Migrate testthread to the new test suite.
  
  Revision  Changes    Path
  1.125     +1 -5      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- Makefile.in	3 Dec 2002 22:09:04 -0000	1.124
  +++ Makefile.in	3 Dec 2002 22:42:02 -0000	1.125
  @@ -13,7 +13,6 @@
   	testnames@EXEEXT@ \
   	testflock@EXEEXT@ \
   	testsock@EXEEXT@ \
  -	testthread@EXEEXT@ \
   	testlock@EXEEXT@ \
   	testlockperf@EXEEXT@ \
   	testargs@EXEEXT@ \
  @@ -75,9 +74,6 @@
   testargs@EXEEXT@: testargs.lo $(LOCAL_LIBS)
   	$(LINK) testargs.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testthread@EXEEXT@: testthread.lo $(LOCAL_LIBS)
  -	$(LINK) testthread.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testlockperf@EXEEXT@: testlockperf.lo $(LOCAL_LIBS)
   	$(LINK) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -124,7 +120,7 @@
   	testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
   	testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
   	testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
  -	testpoll.lo testlock.lo testsockopt.lo testpipe.lo
  +	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
  
  
  
  1.33      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- test_apr.h	3 Dec 2002 22:01:00 -0000	1.32
  +++ test_apr.h	3 Dec 2002 22:42:02 -0000	1.33
  @@ -89,5 +89,6 @@
   CuSuite *testlock(void);
   CuSuite *testsockopt(void);
   CuSuite *testpipe(void);
  +CuSuite *testthread(void);
   
   #endif /* APR_TEST_INCLUDES */
  
  
  
  1.30      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- testall.c	3 Dec 2002 22:01:00 -0000	1.29
  +++ testall.c	3 Dec 2002 22:42:02 -0000	1.30
  @@ -87,6 +87,7 @@
       {"testproc", testproc},
       {"testpoll", testpoll},
       {"testlock", testlock},
  +    {"testthread", testthread},
       {"LastTest", NULL}
   };
   
  
  
  
  1.31      +80 -103   apr/test/testthread.c
  
  Index: testthread.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testthread.c,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- testthread.c	19 Jul 2002 17:49:24 -0000	1.30
  +++ testthread.c	3 Dec 2002 22:42:02 -0000	1.31
  @@ -56,41 +56,30 @@
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "errno.h"
  -#include <stdio.h>
  -#include <stdlib.h>
   #include "apr_time.h"
  -#if APR_HAVE_UNISTD_H
  -#include <unistd.h>
  -#endif
  +#include "test_apr.h"
   
  -#if !APR_HAS_THREADS
  -int main(void)
  -{
  -    fprintf(stderr,
  -            "This program won't work on this platform because there is no "
  -            "support for threads.\n");
  -    return 0;
  -}
  -#else /* !APR_HAS_THREADS */
  -
  -void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data);
  -void * APR_THREAD_FUNC thread_func2(apr_thread_t *thd, void *data);
  -void * APR_THREAD_FUNC thread_func3(apr_thread_t *thd, void *data);
  -void * APR_THREAD_FUNC thread_func4(apr_thread_t *thd, void *data);
  -
  -apr_thread_mutex_t *thread_lock;
  -apr_pool_t *context;
  -apr_thread_once_t *control = NULL;
  -int x = 0;
  -int value = 0;
  -apr_status_t exit_ret_val = 123; /* just some made up number to check on later */
  +#if APR_HAS_THREADS
  +
  +static apr_thread_mutex_t *thread_lock;
  +static apr_thread_once_t *control = NULL;
  +static int x = 0;
  +static int value = 0;
  +
  +static apr_thread_t *t1;
  +static apr_thread_t *t2;
  +static apr_thread_t *t3;
  +static apr_thread_t *t4;
  +
  +/* just some made up number to check on later */
  +static apr_status_t exit_ret_val = 123;
   
   static void init_func(void)
   {
       value++;
   }
   
  -void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data)
  +static void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data)
   {
       int i;
   
  @@ -105,90 +94,78 @@
       return NULL;
   } 
   
  -int main(void)
  +static void thread_init(CuTest *tc)
   {
  -    apr_thread_t *t1;
  -    apr_thread_t *t2;
  -    apr_thread_t *t3;
  -    apr_thread_t *t4;
  -    apr_status_t r1, r2, r3, r4;
  -    apr_status_t s1, s2, s3, s4;
  -    apr_initialize();
  -
  -    printf("APR Simple Thread Test\n======================\n\n");
  -    
  -    printf("%-60s", "Initializing the context"); 
  -    if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
  -        fflush(stdout);
  -        fprintf(stderr, "Failed.\nCould not initialize\n");
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +    apr_status_t rv;
   
  -    apr_thread_once_init(&control, context);
  +    rv = apr_thread_once_init(&control, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
  -    printf("%-60s", "Initializing the lock"); 
  -    r1 = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT,
  -                                 context); 
  -    if (r1 != APR_SUCCESS) {
  -        fflush(stdout);
  -        fprintf(stderr, "Failed\nCould not create lock\n");
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +    rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p); 
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +}
   
  -    printf("%-60s", "Starting all the threads"); 
  -    r1 = apr_thread_create(&t1, NULL, thread_func1, NULL, context);
  -    r2 = apr_thread_create(&t2, NULL, thread_func1, NULL, context);
  -    r3 = apr_thread_create(&t3, NULL, thread_func1, NULL, context);
  -    r4 = apr_thread_create(&t4, NULL, thread_func1, NULL, context);
  -    if (r1 != APR_SUCCESS || r2 != APR_SUCCESS || 
  -        r3 != APR_SUCCESS || r4 != APR_SUCCESS) {
  -        fflush(stdout);
  -        fprintf(stderr, "Failed\nError starting thread\n");
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +static void create_threads(CuTest *tc)
  +{
  +    apr_status_t rv;
   
  -    printf("%-60s", "Waiting for threads to exit");
  -    fflush(stdout);
  -    apr_thread_join(&s1, t1);
  -    apr_thread_join(&s2, t2);
  -    apr_thread_join(&s3, t3);
  -    apr_thread_join(&s4, t4);
  -    printf("OK\n");
  -
  -    printf("%-60s", "Checking thread's returned value");
  -    if (s1 != exit_ret_val || s2 != exit_ret_val ||
  -        s3 != exit_ret_val || s4 != exit_ret_val) {
  -        fflush(stdout);
  -        fprintf(stderr, 
  -                "Invalid return value\nGot %d/%d/%d/%d, but expected %d for all 4\n",
  -                s1, s2, s3, s4, exit_ret_val);
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +    rv = apr_thread_create(&t1, NULL, thread_func1, NULL, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_thread_create(&t2, NULL, thread_func1, NULL, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_thread_create(&t3, NULL, thread_func1, NULL, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_thread_create(&t4, NULL, thread_func1, NULL, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +}
   
  -    printf("%-60s", "Checking if locks worked"); 
  -    if (x != 40000) {
  -        fflush(stdout);
  -        fprintf(stderr, "No!\nThe locks didn't work????  x = %d instead of 40,000\n", x);
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +static void join_threads(CuTest *tc)
  +{
  +    apr_status_t s;
   
  -    printf("%-60s", "Checking if apr_thread_once worked");
  -    if (value != 1) {
  -        fflush(stdout);
  -        fprintf(stderr, "Failed!\napr_thread_once must not have worked, "
  -                "value is %d instead of 1\n", value);
  -        exit(-1);
  -    }
  -    printf("OK\n");
  +    apr_thread_join(&s, t1);
  +    CuAssertIntEquals(tc, exit_ret_val, s);
  +    apr_thread_join(&s, t2);
  +    CuAssertIntEquals(tc, exit_ret_val, s);
  +    apr_thread_join(&s, t3);
  +    CuAssertIntEquals(tc, exit_ret_val, s);
  +    apr_thread_join(&s, t4);
  +    CuAssertIntEquals(tc, exit_ret_val, s);
  +}
   
  -    apr_terminate();
  +static void check_locks(CuTest *tc)
  +{
  +    CuAssertIntEquals(tc, 40000, x);
  +}
  +
  +static void check_thread_once(CuTest *tc)
  +{
  +    CuAssertIntEquals(tc, 1, value);
  +}
  +
  +#else
  +
  +static void threads_not_impl(CuTest *tc)
  +{
  +    CuNotImpl(tc, "Threads not implemented on this platform");
  +}
  +
  +#endif
  +
  +CuSuite *testthread(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Threads");
  +
  +#if !APR_HAS_THREADS
  +    SUITE_ADD_TEST(suite, threads_not_impl);
  +#else
  +    SUITE_ADD_TEST(suite, thread_init);
  +    SUITE_ADD_TEST(suite, create_threads);
  +    SUITE_ADD_TEST(suite, join_threads);
  +    SUITE_ADD_TEST(suite, check_locks);
  +    SUITE_ADD_TEST(suite, check_thread_once);
  +#endif
   
  -    return 0;
  +    return suite;
   }
   
  -#endif /* !APR_HAS_THREADS */
  
  
  

Mime
View raw message