1 /* Tests for POSIX timer implementation using thread CPU clock. */
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
15 #include <support/xunistd.h>
17 static clockid_t worker_thread_clock
;
19 #define TEST_CLOCK worker_thread_clock
20 #define TEST_CLOCK_MISSING(clock) \
21 (setup_test () ? "thread CPU clock timer support" : NULL)
23 /* This function is intended to rack up both user and system time. */
29 static volatile char buf
[4096];
30 for (int i
= 0; i
< 100; ++i
)
31 for (size_t j
= 0; j
< sizeof buf
; ++j
)
33 int nullfd
= open ("/dev/null", O_WRONLY
);
34 for (int i
= 0; i
< 100; ++i
)
35 for (size_t j
= 0; j
< sizeof buf
; ++j
)
37 xwrite (nullfd
, (char *) buf
, sizeof buf
);
47 /* Test timers on a thread CPU clock by having a worker thread eating
48 CPU. First make sure we can make such timers at all. */
51 int e
= pthread_create (&th
, NULL
, chew_cpu
, NULL
);
54 printf ("pthread_create: %s\n", strerror (e
));
58 e
= pthread_getcpuclockid (th
, &worker_thread_clock
);
59 if (e
== EPERM
|| e
== ENOENT
|| e
== ENOTSUP
)
61 puts ("pthread_getcpuclockid does not support other threads");
66 printf ("pthread_getcpuclockid: %s\n", strerror (e
));
71 if (timer_create (TEST_CLOCK
, NULL
, &t
) != 0)
73 printf ("timer_create: %m\n");
82 # define TEST_CLOCK_MISSING(clock) "process clocks"
85 #include "tst-timer4.c"