1 /* Tests for POSIX timer implementation using thread CPU clock. */
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
15 static clockid_t worker_thread_clock
;
17 #define TEST_CLOCK worker_thread_clock
18 #define TEST_CLOCK_MISSING(clock) \
19 (setup_test () ? "thread CPU clock timer support" : NULL)
21 /* This function is intended to rack up both user and system time. */
27 static volatile char buf
[4096];
28 for (int i
= 0; i
< 100; ++i
)
29 for (size_t j
= 0; j
< sizeof buf
; ++j
)
31 int nullfd
= open ("/dev/null", O_WRONLY
);
32 for (int i
= 0; i
< 100; ++i
)
33 for (size_t j
= 0; j
< sizeof buf
; ++j
)
35 write (nullfd
, (char *) buf
, sizeof buf
);
45 /* Test timers on a thread CPU clock by having a worker thread eating
46 CPU. First make sure we can make such timers at all. */
49 int e
= pthread_create (&th
, NULL
, chew_cpu
, NULL
);
52 printf ("pthread_create: %s\n", strerror (e
));
56 e
= pthread_getcpuclockid (th
, &worker_thread_clock
);
57 if (e
== EPERM
|| e
== ENOENT
|| e
== ENOTSUP
)
59 puts ("pthread_getcpuclockid does not support other threads");
64 printf ("pthread_getcpuclockid: %s\n", strerror (e
));
69 if (timer_create (TEST_CLOCK
, NULL
, &t
) != 0)
71 printf ("timer_create: %m\n");
80 # define TEST_CLOCK_MISSING(clock) "process clocks"
83 #include "tst-timer4.c"