1 /* Tests for POSIX timer implementation using another process's CPU clock. */
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
16 static clockid_t child_clock;
18 #define TEST_CLOCK child_clock
19 #define TEST_CLOCK_MISSING(clock) \
20 (setup_test () ? "other-process CPU clock timer support" : NULL)
22 /* This function is intended to rack up both user and system time. */
28 static volatile char buf[4096];
29 for (int i = 0; i < 100; ++i)
30 for (size_t j = 0; j < sizeof buf; ++j)
32 int nullfd = open ("/dev/null", O_WRONLY);
33 for (int i = 0; i < 100; ++i)
34 for (size_t j = 0; j < sizeof buf; ++j)
36 write (nullfd, (char *) buf, sizeof buf);
49 if (kill (child, SIGKILL) < 0 && errno != ESRCH)
50 printf ("cannot kill child %d: %m\n", child);
55 if (waitpid (child, &status, 0) != child)
56 printf ("waitpid %d: %m\n", child);
59 #define CLEANUP_HANDLER cleanup_child ()
64 /* Test timers on a process CPU clock by having a child process eating
65 CPU. First make sure we can make such timers at all. */
68 if (pipe (pipefd) < 0)
70 printf ("pipe: %m\n");
80 if (read (pipefd[0], &c, 1) == 1)
87 printf ("fork: %m\n");
91 atexit (&cleanup_child);
95 int e = clock_getcpuclockid (child, &child_clock);
98 puts ("clock_getcpuclockid does not support other processes");
103 printf ("clock_getcpuclockid: %s\n", strerror (e));
108 if (timer_create (TEST_CLOCK, NULL, &t) != 0)
110 printf ("timer_create: %m\n");
115 /* Get the child started chewing. */
116 if (write (pipefd[1], "x", 1) != 1)
118 printf ("write to pipe: %m\n");
127 # define TEST_CLOCK_MISSING(clock) "process clocks"
130 #include "tst-timer4.c"