blob: 6655ab49852a0a7764a5f8b98806745cb709e3fc [file] [log] [blame]
sewardjcbdddcf2005-03-10 23:23:45 +00001#include <time.h>
2#include <unistd.h>
3#include <stdio.h>
4#include <errno.h>
5#include <signal.h>
6
7#include "../memcheck.h"
8
9/* Check that a syscall's POST function gets called if it completes
10 due to being interrupted. nanosleep is used here, because it
11 writes a result even if it fails. wait*() could also be used,
florianad4e9792015-07-05 21:53:33 +000012 because they successfully complete if interrupted by SIGCHLD.
sewardjcbdddcf2005-03-10 23:23:45 +000013 */
14static void handler(int s)
15{
16}
17
18int main()
19{
20 struct timespec req, rem;
21 int ret;
22
23 req.tv_sec = 2;
24 req.tv_nsec = 0;
25
26 signal(SIGALRM, handler);
27
28 alarm(1);
29 ret = nanosleep(&req, &rem);
30
31 if (ret != -1 || errno != EINTR) {
njn6cfb1df2009-05-04 01:17:56 +000032 fprintf(stderr, "FAILED: expected nanosleep to be interrupted\n");
sewardjcbdddcf2005-03-10 23:23:45 +000033 } else {
florian06bc7222013-10-01 22:38:43 +000034 (void) VALGRIND_CHECK_VALUE_IS_DEFINED(rem);
njn6cfb1df2009-05-04 01:17:56 +000035 fprintf(stderr, "PASSED\n"); /* assuming CHECK_VALUE_IS_DEFINED doesn't print anything */
sewardjcbdddcf2005-03-10 23:23:45 +000036 }
37
38 return 0;
39}