linux: Fix fstat64 on alpha and sparc64
[glibc.git] / rt / tst-cputimer1.c
blob18d8b195a27da3c7c6a7f92c5345f3dd9b4cebb8
1 /* Tests for POSIX timer implementation using process CPU clock. */
3 #include <unistd.h>
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <fcntl.h>
11 #include <time.h>
12 #include <pthread.h>
14 #include <support/xunistd.h>
16 #define TEST_CLOCK CLOCK_PROCESS_CPUTIME_ID
17 #define TEST_CLOCK_MISSING(clock) \
18 (setup_test () ? "process CPU clock timer support" : NULL)
20 /* This function is intended to rack up both user and system time. */
21 static void *
22 chew_cpu (void *arg)
24 while (1)
26 static volatile char buf[4096];
27 for (int i = 0; i < 100; ++i)
28 for (size_t j = 0; j < sizeof buf; ++j)
29 buf[j] = 0xaa;
30 int nullfd = open ("/dev/null", O_WRONLY);
31 for (int i = 0; i < 100; ++i)
32 for (size_t j = 0; j < sizeof buf; ++j)
33 buf[j] = 0xbb;
34 xwrite (nullfd, (char *) buf, sizeof buf);
35 close (nullfd);
38 return NULL;
41 static int
42 setup_test (void)
44 /* Test timers on our own process CPU clock by having a worker thread
45 eating CPU. First make sure we can make such timers at all. */
47 timer_t t;
48 if (timer_create (TEST_CLOCK, NULL, &t) != 0)
50 printf ("timer_create: %m\n");
51 return 1;
53 timer_delete (t);
55 pthread_t th;
56 int e = pthread_create (&th, NULL, chew_cpu, NULL);
57 if (e != 0)
59 printf ("pthread_create: %s\n", strerror (e));
60 exit (1);
63 return 0;
66 #else
67 # define TEST_CLOCK_MISSING(clock) "process clocks"
68 #endif
70 #include "tst-timer4.c"