1 /* Tests for POSIX timer implementation using another process's CPU clock. */
5 #if _POSIX_THREADS && defined _POSIX_CPUTIME
16 #include <support/xunistd.h>
18 static clockid_t child_clock
;
20 #define TEST_CLOCK child_clock
21 #define TEST_CLOCK_MISSING(clock) \
22 (setup_test () ? "other-process CPU clock timer support" : NULL)
24 /* This function is intended to rack up both user and system time. */
30 static volatile char buf
[4096];
31 for (int i
= 0; i
< 100; ++i
)
32 for (size_t j
= 0; j
< sizeof buf
; ++j
)
34 int nullfd
= open ("/dev/null", O_WRONLY
);
35 for (int i
= 0; i
< 100; ++i
)
36 for (size_t j
= 0; j
< sizeof buf
; ++j
)
38 xwrite (nullfd
, (char *) buf
, sizeof buf
);
51 if (kill (child
, SIGKILL
) < 0 && errno
!= ESRCH
)
52 printf ("cannot kill child %d: %m\n", child
);
57 if (waitpid (child
, &status
, 0) != child
)
58 printf ("waitpid %d: %m\n", child
);
61 #define CLEANUP_HANDLER cleanup_child ()
66 /* Test timers on a process CPU clock by having a child process eating
67 CPU. First make sure we can make such timers at all. */
70 if (pipe (pipefd
) < 0)
72 printf ("pipe: %m\n");
82 if (read (pipefd
[0], &c
, 1) == 1)
89 printf ("fork: %m\n");
93 atexit (&cleanup_child
);
97 int e
= clock_getcpuclockid (child
, &child_clock
);
100 puts ("clock_getcpuclockid does not support other processes");
105 printf ("clock_getcpuclockid: %s\n", strerror (e
));
110 if (timer_create (TEST_CLOCK
, NULL
, &t
) != 0)
112 printf ("timer_create: %m\n");
117 /* Get the child started chewing. */
118 if (write (pipefd
[1], "x", 1) != 1)
120 printf ("write to pipe: %m\n");
129 # define TEST_CLOCK_MISSING(clock) "process clocks"
132 #include "tst-timer4.c"