elf: Remove /etc/suid-debug support
[glibc.git] / rt / tst-cputimer2.c
bloba5700d4bac416f55307982da295a0e743574ac5e
1 /* Tests for POSIX timer implementation using thread CPU clock. */
3 #include <unistd.h>
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <fcntl.h>
12 #include <time.h>
13 #include <pthread.h>
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. */
24 static void *
25 chew_cpu (void *arg)
27 while (1)
29 static volatile char buf[4096];
30 for (int i = 0; i < 100; ++i)
31 for (size_t j = 0; j < sizeof buf; ++j)
32 buf[j] = 0xaa;
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)
36 buf[j] = 0xbb;
37 xwrite (nullfd, (char *) buf, sizeof buf);
38 close (nullfd);
41 return NULL;
44 static int
45 setup_test (void)
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. */
50 pthread_t th;
51 int e = pthread_create (&th, NULL, chew_cpu, NULL);
52 if (e != 0)
54 printf ("pthread_create: %s\n", strerror (e));
55 exit (1);
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");
62 return 1;
64 if (e != 0)
66 printf ("pthread_getcpuclockid: %s\n", strerror (e));
67 exit (1);
70 timer_t t;
71 if (timer_create (TEST_CLOCK, NULL, &t) != 0)
73 printf ("timer_create: %m\n");
74 return 1;
76 timer_delete (t);
78 return 0;
81 #else
82 # define TEST_CLOCK_MISSING(clock) "process clocks"
83 #endif
85 #include "tst-timer4.c"