You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Justin Erenkrantz <je...@ebuilt.com> on 2001/06/07 01:03:19 UTC

Re: cvs commit: apr/test testlock.c

Why were the apr_file_printf switched to printf?  printf isn't portable 
or even supported by APR (so says Ryan).  I'd rather we ate our own dog 
food here.  -- justin

On Wed, Jun 06, 2001 at 10:25:45PM -0000, dreid@apache.org wrote:
> dreid       01/06/06 15:25:44
> 
>   Modified:    test     testlock.c
>   Log:
>   Bring testlock in line with the rest of the test apps and change the order
>   of the tests to have the least implemented at the end.  Also now has better
>   output and errors are preserved shown.
>   
>   Revision  Changes    Path
>   1.3       +63 -49    apr/test/testlock.c
>   
>   Index: testlock.c
>   ===================================================================
>   RCS file: /home/cvs/apr/test/testlock.c,v
>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- testlock.c	2001/06/06 18:21:57	1.2
>   +++ testlock.c	2001/06/06 22:25:43	1.3
>   @@ -60,13 +60,13 @@
>    #include "errno.h"
>    #include <stdio.h>
>    #include <stdlib.h>
>   +#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");
>   +    printf("This program won't work on this platform because there is no "
>   +           "support for threads.\n");
>        return 0;
>    }
>    #else /* !APR_HAS_THREADS */
>   @@ -74,8 +74,12 @@
>    #define MAX_ITER 40000
>    
>    void * APR_THREAD_FUNC thread_rw_func(void *data);
>   -void * APR_THREAD_FUNC thread_func(void *data);
>   +void * APR_THREAD_FUNC thread_function(void *data);
>   +apr_status_t test_exclusive(void);
>   +apr_status_t test_rw(void);
>   +apr_status_t test_multiple_locking(void);
>    
>   +
>    apr_file_t *in, *out, *err;
>    apr_lock_t *thread_rw_lock, *thread_lock;
>    apr_pool_t *pool;
>   @@ -106,15 +110,16 @@
>        return NULL;
>    } 
>    
>   -void * APR_THREAD_FUNC thread_func(void *data)
>   +void * APR_THREAD_FUNC thread_function(void *data)
>    {
>        int exitLoop = 1;
>    
>   +    /* slight delay to allow things to settle */
>   +    apr_sleep (1);
>   +    
>        while (1)
>        {
>            apr_lock_acquire(thread_lock);
>   -        if (apr_lock_acquire(thread_lock) != APR_SUCCESS)
>   -            printf("Failed!\n");
>            if (i == MAX_ITER)
>                exitLoop = 0;
>            else 
>   @@ -123,7 +128,6 @@
>                x++;
>            }
>            apr_lock_release(thread_lock);
>   -        apr_lock_release(thread_lock);
>    
>            if (!exitLoop)
>                break;
>   @@ -136,91 +140,93 @@
>        apr_thread_t *t1, *t2, *t3, *t4;
>        apr_status_t s1, s2, s3, s4;
>    
>   -    apr_file_printf(out, "Initializing the rw lock.");
>   -    s1 = apr_lock_create(&thread_rw_lock, APR_READWRITE, APR_INTRAPROCESS, 
>   -                         "lock.file", pool); 
>   +    printf("RW Lock Tests\n");
>   +    printf("%-60s", "    Initializing the RW lock");
>   +    s1 = apr_lock_create(&thread_rw_lock, APR_READWRITE, APR_INTRAPROCESS,
>   +                         "lock.file", pool);
>        if (s1 != APR_SUCCESS) {
>   -        apr_file_printf(err, "Could not create lock\n");
>   +        printf("Failed!\n");
>            return s1;
>        }
>   -    apr_file_printf(out, " OK\n");
>   +    printf("OK\n");
>    
>        i = 0;
>        x = 0;
>    
>   -    apr_file_printf(out, "Starting all the threads......."); 
>   +    printf("%-60s","    Starting all the threads"); 
>        s1 = apr_thread_create(&t1, NULL, thread_rw_func, NULL, pool);
>        s2 = apr_thread_create(&t2, NULL, thread_rw_func, NULL, pool);
>        s3 = apr_thread_create(&t3, NULL, thread_rw_func, NULL, pool);
>        s4 = apr_thread_create(&t4, NULL, thread_rw_func, NULL, pool);
>        if (s1 != APR_SUCCESS || s2 != APR_SUCCESS || 
>            s3 != APR_SUCCESS || s4 != APR_SUCCESS) {
>   -        apr_file_printf(err, "Error starting threads\n");
>   +        printf("Failed!\n");
>            return s1;
>        }
>   -    apr_file_printf(out, "OK\n");
>   +    printf("OK\n");
>    
>   -    apr_file_printf(out, "Waiting for threads to exit.......");
>   +    printf("%-60s", "    Waiting for threads to exit");
>        apr_thread_join(&s1, t1);
>        apr_thread_join(&s2, t2);
>        apr_thread_join(&s3, t3);
>        apr_thread_join(&s4, t4);
>   -    apr_file_printf(out, "OK\n");
>   +    printf("OK\n");
>    
>   -    apr_file_printf(out, "OK\n");
>        if (x != MAX_ITER) {
>   -        apr_file_printf(err, "The locks didn't work????  %d\n", x);
>   +        fprintf(stderr, "RW locks didn't work as expected. x = %d instead of %d\n",
>   +                x, MAX_ITER);
>        }
>        else {
>   -        apr_file_printf(out, "Everything is working!\n");
>   +        printf("Test passed\n");
>        }
>        
>        return APR_SUCCESS;
>    }
>    
>   -int test_exclusive(void)
>   +apr_status_t test_exclusive(void)
>    {
>        apr_thread_t *t1, *t2, *t3, *t4;
>        apr_status_t s1, s2, s3, s4;
>    
>   -    apr_file_printf(out, "Initializing the lock.");
>   +    printf("Exclusive lock test\n");
>   +    printf("%-60s", "    Initializing the lock");
>        s1 = apr_lock_create(&thread_lock, APR_MUTEX, APR_INTRAPROCESS, 
>                             "lock.file", pool); 
>    
>        if (s1 != APR_SUCCESS) {
>   -        apr_file_printf(err, "Could not create lock\n");
>   +        printf("Failed!\n");
>            return s1;
>        }
>   -    apr_file_printf(out, " OK\n");
>   +    printf("OK\n");
>    
>        i = 0;
>        x = 0;
>    
>   -    apr_file_printf(out, "Starting all the threads......."); 
>   -    s1 = apr_thread_create(&t1, NULL, thread_func, NULL, pool);
>   -    s2 = apr_thread_create(&t2, NULL, thread_func, NULL, pool);
>   -    s3 = apr_thread_create(&t3, NULL, thread_func, NULL, pool);
>   -    s4 = apr_thread_create(&t4, NULL, thread_func, NULL, pool);
>   +    printf("%-60s", "    Starting all the threads"); 
>   +    s1 = apr_thread_create(&t1, NULL, thread_function, NULL, pool);
>   +    s2 = apr_thread_create(&t2, NULL, thread_function, NULL, pool);
>   +    s3 = apr_thread_create(&t3, NULL, thread_function, NULL, pool);
>   +    s4 = apr_thread_create(&t4, NULL, thread_function, NULL, pool);
>        if (s1 != APR_SUCCESS || s2 != APR_SUCCESS || 
>            s3 != APR_SUCCESS || s4 != APR_SUCCESS) {
>   -        apr_file_printf(err, "Error starting threads\n");
>   +        printf("Failed!\n");
>            return s1;
>        }
>   -    apr_file_printf(out, "OK\n");
>   +    printf("OK\n");
>    
>   -    apr_file_printf(out, "Waiting for threads to exit.......");
>   +    printf("%-60s", "    Waiting for threads to exit");
>        apr_thread_join(&s1, t1);
>        apr_thread_join(&s2, t2);
>        apr_thread_join(&s3, t3);
>        apr_thread_join(&s4, t4);
>   -    apr_file_printf(out, "OK\n");
>   +    printf("OK\n");
>    
>   -    apr_file_printf(out, "OK\n");
>        if (x != MAX_ITER) {
>   -        apr_file_printf(err, "The locks didn't work????  %d\n", x);
>   +        fprintf(stderr, "Locks don't appear to work!  x = %d instead of %d\n",
>   +                x, MAX_ITER);
>        }
>        else {
>   -        apr_file_printf(out, "Everything is working!\n");
>   +        printf("Test passed\n");
>        }
>        return APR_SUCCESS;
>    }
>   @@ -267,32 +273,40 @@
>        }
>        printf("OK\n");
>    
>   -    printf("Multiple locking test completed\n");
>   +    printf("Test passed\n");
>        return APR_SUCCESS;
>    }
>    
>    int main(void)
>    {
>   +    apr_status_t rv;
>   +    char errmsg[200];
>   +
>   +    printf("APR Locks Test\n==============\n\n");
>   +        
>        apr_initialize();
>        atexit(apr_terminate);
>    
>        if (apr_pool_create(&pool, NULL) != APR_SUCCESS)
>            exit(-1);
>    
>   -    apr_file_open_stdin(&in, pool); 
>   -    apr_file_open_stdout(&out, pool); 
>   -    apr_file_open_stderr(&err, pool); 
>   -
>   -    apr_file_printf(out, "OK\n");
>   -
>   -    if (test_rw() != APR_SUCCESS)
>   +    if ((rv = test_exclusive()) != APR_SUCCESS) {
>   +        fprintf(stderr,"Exclusive Lock test failed : [%d] %s\n",
>   +                rv, apr_strerror(rv, (char*)errmsg, 200));
>            exit(-2);
>   -
>   -    if (test_exclusive() != APR_SUCCESS)
>   +    }
>   +    
>   +    if ((rv = test_multiple_locking()) != APR_SUCCESS) {
>   +        fprintf(stderr,"Multiple Locking test failed : [%d] %s\n",
>   +                rv, apr_strerror(rv, (char*)errmsg, 200));
>            exit(-3);
>   -
>   -    if (test_multiple_locking() != APR_SUCCESS)
>   +    }
>   +    
>   +    if ((rv = test_rw()) != APR_SUCCESS) {
>   +        fprintf(stderr,"RW Lock test failed : [%d] %s\n",
>   +                rv, apr_strerror(rv, (char*)errmsg, 200));
>            exit(-4);
>   +    }
>    
>        return 1;
>    }
>   
>   
>   


Re: cvs commit: apr/test testlock.c

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Thu, Jun 07, 2001 at 12:30:17AM +0100, David Reid wrote:
> Hmm, well all the other test apps are using it...

Doesn't mean they are right.  =)

> The general rule I'm moving to is that the "output" all goes to stdout,
> error messages to stderr.  So if we have
> 
> testing foo
> 
> The OK or Failed are both printed on stdout as part of the "output" and the
> error message as to why it failed goes to stderr.  This means we end up with
> something like
> 
> testing foo            Failed
> we coudn't do foo : [1001] bar is not supported on this platform

As long as we have a convention, I don't care much where things go.
This seems reasonable enough to me.

> The aim is to move to a script based test run whereby we get simple reports
> of what tests passed and what failed with the output being dumped into a
> file, hence the desire for the distinction.  Of course it'll be a while
> before we get there :)  test_apr.h is the start but there is more support
> needed yet.
> 
> If we have to make the change fair enough, but we haven't been using it
> anywhere else in the test apps

Oh, I'd love to see that.  "make check" does the obvious things.  I 
think most tests were written before we had the ability to get stdin, 
stdout, and stderr via APR.

> BTW, do other people even run them anymore?

I do.  -- justin


Re: cvs commit: apr/test testlock.c

Posted by rb...@covalent.net.
> Hmm, well all the other test apps are using it...
>
> The general rule I'm moving to is that the "output" all goes to stdout,
> error messages to stderr.  So if we have
>
> testing foo
>
> The OK or Failed are both printed on stdout as part of the "output" and the
> error message as to why it failed goes to stderr.  This means we end up with
> something like
>
> testing foo            Failed
> we coudn't do foo : [1001] bar is not supported on this platform
>
> The aim is to move to a script based test run whereby we get simple reports
> of what tests passed and what failed with the output being dumped into a
> file, hence the desire for the distinction.  Of course it'll be a while
> before we get there :)  test_apr.h is the start but there is more support
> needed yet.
>
> If we have to make the change fair enough, but we haven't been using it
> anywhere else in the test apps
>
>
> BTW, do other people even run them anymore?

We are dealing with history here, sorry.  When I first started to write
the test programs, we didn't have the ability to open stdin, out, and err
and use apr_fprintf.  Therefore, I used printf and fprintf.  David is just
following exactly what we had done in the past.

As for if anybody still runs them, I do.  Though not as often as I should.
I want to improve the test cases, but I have limited time right now.  Some
day soon I hope to get more time.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: cvs commit: apr/test testlock.c

Posted by David Reid <dr...@jetnet.co.uk>.
Hmm, well all the other test apps are using it...

The general rule I'm moving to is that the "output" all goes to stdout,
error messages to stderr.  So if we have

testing foo

The OK or Failed are both printed on stdout as part of the "output" and the
error message as to why it failed goes to stderr.  This means we end up with
something like

testing foo            Failed
we coudn't do foo : [1001] bar is not supported on this platform

The aim is to move to a script based test run whereby we get simple reports
of what tests passed and what failed with the output being dumped into a
file, hence the desire for the distinction.  Of course it'll be a while
before we get there :)  test_apr.h is the start but there is more support
needed yet.

If we have to make the change fair enough, but we haven't been using it
anywhere else in the test apps


BTW, do other people even run them anymore?

david



> Why were the apr_file_printf switched to printf?  printf isn't portable
> or even supported by APR (so says Ryan).  I'd rather we ate our own dog
> food here.  -- justin
>



Re: cvs commit: apr/test testlock.c

Posted by Jeff Trawick <tr...@bellsouth.net>.
Justin Erenkrantz <je...@ebuilt.com> writes:

> Why were the apr_file_printf switched to printf?  printf isn't portable 
> or even supported by APR (so says Ryan).  I'd rather we ate our own dog 
> food here.  -- justin

[f]printf not portable?  huh?

How does the level of printf support in APR affect whether or not a
program which uses APR can use printf?

Note that we rely on APR-provided format strings to be compatible with
printf format strings whenever possible so that gcc can keep us honest.

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...