From: Szabolcs Nagy Date: Tue, 6 Aug 2013 00:30:10 +0000 (+0000) Subject: add pthread_condattr_setclock regression test X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=0dee0dca0a980073abfcd4f78a328c77f1aa5979 add pthread_condattr_setclock regression test --- diff --git a/src/regression/mkdtemp-failure.c b/src/regression/mkdtemp-failure.c index 09fa78d..61d7ae6 100644 --- a/src/regression/mkdtemp-failure.c +++ b/src/regression/mkdtemp-failure.c @@ -1,5 +1,6 @@ // commit: 69ecbd0f3188be97f91cc0d6415836d23e88f7fc 2011-02-19 // commit: 382584724308442f03f3d29f7fc6de9e9d140982 2011-06-12 +// commit: c4685ae429a0cce4b285859d62a71fe603f0a864 2013-08-02 // mkdtemp should return -1 on bad template #define _BSD_SOURCE 1 #include diff --git a/src/regression/pthread_condattr_setclock.c b/src/regression/pthread_condattr_setclock.c new file mode 100644 index 0000000..1ddc1d2 --- /dev/null +++ b/src/regression/pthread_condattr_setclock.c @@ -0,0 +1,53 @@ +// commit: 9d5251f72b627974bcf438501e07ad42c24d94be 2011-03-08 +// disallow cpu time clocks in condattr +#include +#include +#include +#include +#include "test.h" + +#define T(r,f) if ((r=(f))) t_error(#f " failed: %s\n", strerror(r)) + +int main(void) +{ + pthread_cond_t c; + pthread_condattr_t a; + pthread_mutex_t m; + clockid_t clk; + struct timespec ts; + void *p; + int r; + + T(r,pthread_condattr_init(&a)); + r = pthread_condattr_setclock(&a, CLOCK_PROCESS_CPUTIME_ID); + if (r != EINVAL) + t_error("pthread_condattr_setclock CLOCK_PROCESS_CPUTIME_ID should fail with EINVAL, got %s\n", strerror(r)); + r = pthread_condattr_setclock(&a, CLOCK_THREAD_CPUTIME_ID); + if (r != EINVAL) + t_error("pthread_condattr_setclock CLOCK_THREAD_CPUTIME_ID should fail with EINVAL, got %s\n", strerror(r)); + T(r,pthread_condattr_getclock(&a, &clk)); + if (clk != CLOCK_REALTIME) + t_error("condattr default clock is %d, wanted CLOCK_REALTIME (%d)\n", (int)clk, (int)CLOCK_REALTIME); + + T(r,pthread_cond_init(&c, &a)); + T(r,pthread_mutex_init(&m, 0)); + T(r,pthread_mutex_lock(&m)); + r = clock_gettime(CLOCK_REALTIME, &ts); + if (r) + t_error("clock_gettime failed: %s\n", strerror(errno)); + /* wait 10ms */ + ts.tv_nsec += 10*1000*1000; + if (ts.tv_nsec >= 1000*1000*1000) { + ts.tv_nsec -= 1000*1000*1000; + ts.tv_sec += 1; + } + r = pthread_cond_timedwait(&c, &m, &ts); + if (r != ETIMEDOUT) + t_error("pthread_cond_timedwait did not timeout, returned %s\n", strerror(r)); + T(r,pthread_mutex_unlock(&m)); + + T(r,pthread_mutex_destroy(&m)); + T(r,pthread_cond_destroy(&c)); + T(r,pthread_condattr_destroy(&a)); + return t_status; +}