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 globalmutexchild.c testglobalmutex.h Makefile.in Makefile.win test_apr.h testall.c testglobalmutex.c
Date Mon, 15 Mar 2004 18:33:31 GMT
rbb         2004/03/15 10:33:30

  Modified:    test     Makefile.in Makefile.win test_apr.h testall.c
                        testglobalmutex.c
  Added:       test     globalmutexchild.c testglobalmutex.h
  Log:
  Port testglobalmutex to the unified framework.  There is a hack in
  globalmutexchild.c in that we create the mutex before we call child_init.
  
  Revision  Changes    Path
  1.153     +6 -8      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.152
  retrieving revision 1.153
  diff -u -r1.152 -r1.153
  --- Makefile.in	15 Mar 2004 02:09:52 -0000	1.152
  +++ Makefile.in	15 Mar 2004 18:33:30 -0000	1.153
  @@ -17,9 +17,6 @@
   	testmutexscope@EXEEXT@ \
   	testall@EXEEXT@
   
  -STDTEST_NONPORTABLE = \
  -	testglobalmutex@EXEEXT@
  -
   OTHER_PROGRAMS = sendfile@EXEEXT@ 
   
   PROGRAMS = $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) $(OTHER_PROGRAMS)
  @@ -60,6 +57,9 @@
   readchild@EXEEXT@: readchild.lo $(LOCAL_LIBS)
   	$(LINK_PROG) readchild.lo $(LOCAL_LIBS) $(ALL_LIBS)
           
  +globalmutexchild@EXEEXT@: globalmutexchild.lo $(LOCAL_LIBS)
  +	$(LINK_PROG) globalmutexchild.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +
   tryread@EXEEXT@: tryread.lo $(LOCAL_LIBS)
   	$(LINK_PROG) tryread.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -91,9 +91,6 @@
   testprocmutex@EXEEXT@: testprocmutex.lo $(LOCAL_LIBS)
   	$(LINK_PROG) testprocmutex.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testglobalmutex@EXEEXT@: testglobalmutex.lo $(LOCAL_LIBS)
  -	$(LINK_PROG) testglobalmutex.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testmutexscope@EXEEXT@: testmutexscope.lo $(LOCAL_LIBS)
   	$(LINK_PROG) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -104,11 +101,12 @@
   	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
   	testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
   	testenv.lo testprocmutex.lo testrand2.lo testfnmatch.lo \
  -        testatomic.lo testflock.lo testshm.lo testsock.lo
  +        testatomic.lo testflock.lo testshm.lo testsock.lo testglobalmutex.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 readchild@EXEEXT@ CuTest.lo proc_child@EXEEXT@ \
  -         tryread@EXEEXT@ sockchild@EXEEXT@ $(LOCAL_LIBS)
  +         tryread@EXEEXT@ sockchild@EXEEXT@ globalmutexchild@EXEEXT@ \
  +         $(LOCAL_LIBS)
   	$(LINK_PROG) $(TESTS) CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
   
  
  
  
  1.17      +5 -6      apr/test/Makefile.win
  
  Index: Makefile.win
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.win,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Makefile.win	14 Mar 2004 20:27:14 -0000	1.16
  +++ Makefile.win	15 Mar 2004 18:33:30 -0000	1.17
  @@ -1,10 +1,8 @@
   
   LINK=link /nologo
   
  -NONPORTABLE = \
  -	testglobalmutex.exe
  -
   PROGRAMS = \
  +        globalmutexchild.exe \
   	sendfile.exe \
   	proc_child.exe \
           tryread.exe \
  @@ -74,8 +72,8 @@
   testprocmutex.exe: testprocmutex.obj $(LOCAL_LIBS)
   	$(LINK) testprocmutex.obj $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testglobalmutex.exe: testglobalmutex.obj $(LOCAL_LIBS)
  -	$(LINK) testglobalmutex.obj $(LOCAL_LIBS) $(ALL_LIBS)
  +globalmutexchild.exe: globalmutexchild.obj $(LOCAL_LIBS)
  +	$(LINK) globalmutexchild.obj $(LOCAL_LIBS) $(ALL_LIBS)
   
   testmutexscope.exe: testmutexscope.obj $(LOCAL_LIBS)
   	$(LINK) testmutexscope.obj $(LOCAL_LIBS) $(ALL_LIBS)
  @@ -87,7 +85,8 @@
   	testpoll.obj testlock.obj testsockopt.obj testpipe.obj testthread.obj \
   	testhash.obj testargs.obj testnames.obj testuser.obj testpath.obj \
   	testenv.obj testprocmutex.obj testrand2.obj testfnmatch.obj \
  -        testatomic.obj testflock.obj testshm.obj testsock.obj
  +        testatomic.obj testflock.obj testshm.obj testsock.obj \
  +        testglobalmutex.obj
   
   testall.exe: $(TESTS) CuTest.obj $(LOCAL_LIBS)
   	$(LINK) /debug /subsystem:console /machine:I386 $(TESTS) CuTest.obj \
  
  
  
  1.52      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- test_apr.h	14 Mar 2004 20:27:14 -0000	1.51
  +++ test_apr.h	15 Mar 2004 18:33:30 -0000	1.52
  @@ -47,6 +47,7 @@
   CuSuite *testfmt(void);
   CuSuite *testfnmatch(void);
   CuSuite *testgetopt(void);
  +CuSuite *testglobalmutex(void);
   CuSuite *testhash(void);
   CuSuite *testipsub(void);
   CuSuite *testlock(void);
  
  
  
  1.56      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- testall.c	14 Mar 2004 20:27:14 -0000	1.55
  +++ testall.c	15 Mar 2004 18:33:30 -0000	1.56
  @@ -50,6 +50,7 @@
       {"testflock", testflock},
       {"testfmt", testfmt},
       {"testfnmatch", testfnmatch},
  +    {"testglobalmutex", testglobalmutex},
       {"testhash", testhash},
       {"testipsub", testipsub},
       {"testlock", testlock},
  
  
  
  1.6       +53 -117   apr/test/testglobalmutex.c
  
  Index: testglobalmutex.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testglobalmutex.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- testglobalmutex.c	13 Feb 2004 09:38:34 -0000	1.5
  +++ testglobalmutex.c	15 Mar 2004 18:33:30 -0000	1.6
  @@ -13,141 +13,77 @@
    * limitations under the License.
    */
   
  -#include "apr_shm.h"
  +#include "testglobalmutex.h"
   #include "apr_thread_proc.h"
  -#include "apr_file_io.h"
   #include "apr_global_mutex.h"
   #include "apr_errno.h"
  -#include "apr_general.h"
  -#include "apr_getopt.h"
  -#include "errno.h"
  -#include <stdio.h>
  -#include <stdlib.h>
   #include "test_apr.h"
   
  +static void launch_child(CuTest *tc, apr_proc_t *proc, apr_pool_t *p)
  +{
  +    apr_procattr_t *procattr;
  +    const char *args[2];
  +    apr_status_t rv;
   
  -#define MAX_ITER 4000
  -#define MAX_COUNTER (MAX_ITER * 4)
  +    rv = apr_procattr_create(&procattr, p);
  +    apr_assert_success(tc, "Couldn't create procattr", rv);
   
  -apr_global_mutex_t *global_lock;
  -apr_pool_t *pool;
  -int *x;
  +    rv = apr_procattr_io_set(procattr, APR_NO_PIPE, APR_NO_PIPE,
  +            APR_NO_PIPE);
  +    apr_assert_success(tc, "Couldn't set io in procattr", rv);
  +
  +    rv = apr_procattr_error_check_set(procattr, 1);
  +    apr_assert_success(tc, "Couldn't set error check in procattr", rv);
  +
  +    args[0] = "globalmutexchild" EXTENSION;
  +    args[2] = NULL;
  +    rv = apr_proc_create(proc, "./globalmutexchild" EXTENSION, args, NULL,
  +            procattr, p);
  +    apr_assert_success(tc, "Couldn't launch program", rv);
  +}
   
  -static int make_child(apr_proc_t **proc, apr_pool_t *p)
  +static int wait_child(CuTest *tc, apr_proc_t *proc)
   {
  -    int i = 0;
  -    *proc = apr_pcalloc(p, sizeof(**proc));
  +    int exitcode;
  +    apr_exit_why_e why;
   
  -    /* slight delay to allow things to settle */
  -    apr_sleep (1);
  +    CuAssert(tc, "Error waiting for child process",
  +            apr_proc_wait(proc, &exitcode, &why, APR_WAIT) == APR_CHILD_DONE);
   
  -    if (apr_proc_fork(*proc, p) == APR_INCHILD) {
  -        while (1) {
  -            apr_global_mutex_lock(global_lock); 
  -            if (i == MAX_ITER) {
  -                apr_global_mutex_unlock(global_lock); 
  -                exit(1);
  -            }
  -            i++;
  -            (*x)++;
  -            apr_global_mutex_unlock(global_lock); 
  -        }
  -        exit(1);
  -    }
  -    return APR_SUCCESS;
  +    CuAssert(tc, "child didn't terminate normally", why == APR_PROC_EXIT);
  +    return exitcode;
   }
   
  -static apr_status_t test_exclusive(const char *lockname)
  +static void test_exclusive(CuTest *tc)
   {
  -    apr_proc_t *p1, *p2, *p3, *p4;
  -    apr_status_t s1, s2, s3, s4;
  - 
  -    printf("Exclusive lock test\n");
  -    printf("%-60s", "    Initializing the lock");
  -    s1 = apr_global_mutex_create(&global_lock, lockname, APR_LOCK_DEFAULT, pool);
  - 
  -    if (s1 != APR_SUCCESS) {
  -        printf("Failed!\n");
  -        return s1;
  -    }
  -    printf("OK\n");
  - 
  -    printf("%-60s", "    Starting all of the processes");
  -    fflush(stdout);
  -    s1 = make_child(&p1, pool);
  -    s2 = make_child(&p2, pool);
  -    s3 = make_child(&p3, pool);
  -    s4 = make_child(&p4, pool);
  -    if (s1 != APR_SUCCESS || s2 != APR_SUCCESS ||
  -        s3 != APR_SUCCESS || s4 != APR_SUCCESS) {
  -        printf("Failed!\n");
  -        return s1;
  -    }
  -    printf("OK\n");
  +    apr_proc_t p1, p2, p3, p4;
  +    apr_status_t rv;
  +    apr_global_mutex_t *global_lock;
  +    int x = 0;
    
  -    printf("%-60s", "    Waiting for processes to exit");
  -    s1 = apr_proc_wait(p1, NULL, NULL, APR_WAIT);
  -    s2 = apr_proc_wait(p2, NULL, NULL, APR_WAIT);
  -    s3 = apr_proc_wait(p3, NULL, NULL, APR_WAIT);
  -    s4 = apr_proc_wait(p4, NULL, NULL, APR_WAIT);
  -    printf("OK\n");
  +    rv = apr_global_mutex_create(&global_lock, LOCKNAME, APR_LOCK_DEFAULT, p);
  +    apr_assert_success(tc, "Error creating mutex", rv);
  +
  +
  +    launch_child(tc, &p1, p);
  +    launch_child(tc, &p2, p);
  +    launch_child(tc, &p3, p);
  +    launch_child(tc, &p4, p);
    
  -    if ((*x) != MAX_COUNTER) {
  -        fprintf(stderr, "Locks don't appear to work!  x = %d instead of %d\n",
  -                (*x), MAX_COUNTER);
  -    }
  -    else {
  -        printf("Test passed\n");
  -    }
  -    return APR_SUCCESS;
  +    x += wait_child(tc, &p1);
  +    x += wait_child(tc, &p2);
  +    x += wait_child(tc, &p3);
  +    x += wait_child(tc, &p4);
  +
  +    CuAssertIntEquals(tc, MAX_COUNTER, x);
   }
   
  -int main(int argc, const char * const *argv)
  +CuSuite *testglobalmutex(void)
   {
  -    apr_status_t rv;
  -    char errmsg[200];
  -    const char *lockname = NULL;
  -    const char *shmname = "shm.file";
  -    apr_getopt_t *opt;
  -    char optchar;
  -    const char *optarg;
  -    apr_shm_t *shm;
  -
  -    printf("APR Proc Mutex Test\n==============\n\n");
  -        
  -    apr_initialize();
  -    atexit(apr_terminate);
  -
  -    if (apr_pool_create(&pool, NULL) != APR_SUCCESS)
  -        exit(-1);
  -
  -    if ((rv = apr_getopt_init(&opt, pool, argc, argv)) != APR_SUCCESS) {
  -        fprintf(stderr, "Could not set up to parse options: [%d] %s\n",
  -                rv, apr_strerror(rv, errmsg, sizeof errmsg));
  -        exit(-1);
  -    }
  -        
  -    while ((rv = apr_getopt(opt, "f:", &optchar, &optarg)) == APR_SUCCESS) {
  -        if (optchar == 'f') {
  -            lockname = optarg;
  -        }
  -    }
  -
  -    if (rv != APR_SUCCESS && rv != APR_EOF) {
  -        fprintf(stderr, "Could not parse options: [%d] %s\n",
  -                rv, apr_strerror(rv, errmsg, sizeof errmsg));
  -        exit(-1);
  -    }
  -
  -    apr_shm_create(&shm, sizeof(int), shmname, pool);
  -    x = apr_shm_baseaddr_get(shm);
  -
  -    if ((rv = test_exclusive(lockname)) != APR_SUCCESS) {
  -        fprintf(stderr,"Exclusive Lock test failed : [%d] %s\n",
  -                rv, apr_strerror(rv, (char*)errmsg, 200));
  -        exit(-2);
  -    }
  -    
  -    return 0;
  +    CuSuite *suite = CuSuiteNew("Global Mutex");
  +
  +    SUITE_ADD_TEST(suite, test_exclusive);
  +
  +    return suite;
   }
   
  
  
  
  1.1                  apr/test/globalmutexchild.c
  
  Index: globalmutexchild.c
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include "testglobalmutex.h"
  #include "apr_pools.h"
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include "apr_global_mutex.h"
  #include "apr.h"
  
  #if APR_HAVE_STDLIB_H
  #include <stdlib.h>
  #endif
  
  
  int main(int argc, const char * const argv[])
  {
      apr_pool_t *p;
      int i = 0;
      apr_global_mutex_t *global_lock;
  
      apr_initialize();
      atexit(apr_terminate);
      
      apr_pool_create(&p, NULL);
      apr_global_mutex_create(&global_lock, LOCKNAME, APR_LOCK_DEFAULT, p);
      apr_global_mutex_child_init(&global_lock, LOCKNAME, p);
      
      while (1) {
          apr_global_mutex_lock(global_lock);
          if (i == MAX_ITER) {
              apr_global_mutex_unlock(global_lock);
              exit(i);
          }
          i++;
          apr_global_mutex_unlock(global_lock);
      }
      exit(0);
  }
  
  
  
  1.1                  apr/test/testglobalmutex.h
  
  Index: testglobalmutex.h
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #ifndef TESTGLOBALMUTEX_H
  #define TESTGLOBALMUTEX_H
  
  /* set this to 255 so that the child processes can return it successfully. */
  #define MAX_ITER 255
  #define MAX_COUNTER (MAX_ITER * 4)
  
  #define LOCKNAME "data/apr_globalmutex.lock"
  
  #endif
  
  
  
  

Mime
View raw message