diff options
author | rpj <rpj> | 2001-07-01 13:49:38 +0000 |
---|---|---|
committer | rpj <rpj> | 2001-07-01 13:49:38 +0000 |
commit | 19299847fdd32094b28377db1aea61b0f605dc8b (patch) | |
tree | 6790f92e1c0d67063edccf82a57616f977633aef /tests/condvar3_3.c | |
parent | a311086d622d3c778e1da57cfae167c0ab1c0fb4 (diff) |
2001-07-01 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
Contributed by - Alexander Terekhov.
* condvar.c: Fixed lost signal bug reported by Timur Aydin
(taydin@snet.net).
[RPJ (me) didn't translate the original algorithm
correctly.]
* semaphore.c: Added sem_post_multiple; this is a useful
routine, but it doesn't appear to be standard. For now it's
not an exported function.
tests/ChangeLog:
2001-07-01 Ross Johnson <rpj@special.ise.canberra.edu.au>
* benchtest3.c: New; timing mutexes.
* benchtest4.c: New; time mutexes.
* condvar3_1.c: Fixed bug - Alexander Terekhov
* condvar3_3.c: New test.
2001-06-25 Ross Johnson <rpj@special.ise.canberra.edu.au>
* priority1.c: New test.
* priority2.c: New test.
* inherit1.c: New test.
* benchtest1.c: New; timing mutexes.
* benchtest2.c: New; timing mutexes.
* mutex4.c: Modified to test all mutex types.
Diffstat (limited to 'tests/condvar3_3.c')
-rw-r--r-- | tests/condvar3_3.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/condvar3_3.c b/tests/condvar3_3.c new file mode 100644 index 0000000..43e6f3a --- /dev/null +++ b/tests/condvar3_3.c @@ -0,0 +1,100 @@ +/* + * File: condvar3_3.c + * + * Test Synopsis: + * - Test timeouts and lost signals on a CV. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait does not return ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +/* Timur Aydin (taydin@snet.net) */ + +#include "test.h" + +#include <sys/timeb.h> + +pthread_cond_t cnd; +pthread_mutex_t mtx; + +int main() +{ + int rc; + + struct timespec abstime = { 0, 0 }; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert(pthread_cond_init(&cnd, 0) == 0); + assert(pthread_mutex_init(&mtx, 0) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + abstime.tv_sec += 1; + + /* Here pthread_cond_timedwait should time out after one second. */ + + assert(pthread_mutex_lock(&mtx) == 0); + + assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); + + assert(pthread_mutex_unlock(&mtx) == 0); + + /* Here, the condition variable is signaled, but there are no + threads waiting on it. The signal should be lost and + the next pthread_cond_timedwait should time out too. */ + + assert(pthread_mutex_lock(&mtx) == 0); + + assert((rc = pthread_cond_signal(&cnd)) == 0); + + assert(pthread_mutex_unlock(&mtx) == 0); + + assert(pthread_mutex_lock(&mtx) == 0); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + abstime.tv_sec += 1; + + assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); + + assert(pthread_mutex_unlock(&mtx) == 0); + + return 0; +} |