Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libpthread/cond6 Add tests for pthread_cond_time...



details:   https://anonhg.NetBSD.org/src/rev/b05cb133b13b
branches:  trunk
changeset: 572318:b05cb133b13b
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Wed Dec 29 20:34:11 2004 +0000

description:
Add tests for pthread_cond_timedwait() at time zero, as discussed
in PR lib/28700.

diffstat:

 regress/lib/libpthread/cond6/cond6.c |  32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diffs (65 lines):

diff -r 55b599015cf2 -r b05cb133b13b regress/lib/libpthread/cond6/cond6.c
--- a/regress/lib/libpthread/cond6/cond6.c      Wed Dec 29 19:43:27 2004 +0000
+++ b/regress/lib/libpthread/cond6/cond6.c      Wed Dec 29 20:34:11 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond6.c,v 1.1 2004/12/10 17:07:31 nathanw Exp $        */
+/*     $NetBSD: cond6.c,v 1.2 2004/12/29 20:34:11 nathanw Exp $        */
 
 #include <assert.h>
 #include <err.h>
@@ -20,13 +20,13 @@
        struct timespec ts;
        struct timeval tv;
 
-       printf("condition variable test 6: bogus timedwait\n");
+       printf("condition variable test 6: bogus timedwaits\n");
 
        ret = pthread_mutex_lock(&mutex);
        if (ret)
                err(1, "pthread_mutex_lock(1)");
 
-       printf("unthreaded test\n");
+       printf("unthreaded test (past)\n");
        gettimeofday(&tv, NULL);
        tv.tv_sec -= 2; /* Place the time in the past */
        TIMEVAL_TO_TIMESPEC(&tv, &ts);
@@ -37,7 +37,19 @@
                    " in the past returned %d\n", ret);
                exit(1);
        }
-               
+
+       printf("unthreaded test (zero time)\n");
+       tv.tv_sec = 0;
+       tv.tv_usec = 0;
+       TIMEVAL_TO_TIMESPEC(&tv, &ts);
+
+       ret = pthread_cond_timedwait(&cond, &mutex, &ts);
+       if (ret != ETIMEDOUT) {
+               printf("FAIL: pthread_cond_timedwait() (unthreaded)"
+                   " with zero time returned %d\n", ret);
+               exit(1);
+       }
+
        ret = pthread_create(&new, NULL, threadfunc, NULL);
        if (ret != 0)
                err(1, "pthread_create");
@@ -57,6 +69,18 @@
                exit(1);
        }
 
+       printf("threaded test (zero time)\n");
+       tv.tv_sec = 0;
+       tv.tv_usec = 0;
+       TIMEVAL_TO_TIMESPEC(&tv, &ts);
+
+       ret = pthread_cond_timedwait(&cond, &mutex, &ts);
+       if (ret != ETIMEDOUT) {
+               printf("FAIL: pthread_cond_timedwait() (threaded)"
+                   " with zero time returned %d\n", ret);
+               exit(1);
+       }
+
        pthread_mutex_unlock(&mutex);
 
        return 0;



Home | Main Index | Thread Index | Old Index