Home | History | Annotate | Download | only in tests
      1 #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,
     12    because they successully complete if interrupted by SIGCHLD.
     13  */
     14 static void handler(int s)
     15 {
     16 }
     17 
     18 int 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) {
     32 		fprintf(stderr, "FAILED: expected nanosleep to be interrupted\n");
     33 	} else {
     34 		VALGRIND_CHECK_VALUE_IS_DEFINED(rem);
     35 		fprintf(stderr, "PASSED\n"); /* assuming CHECK_VALUE_IS_DEFINED doesn't print anything */
     36 	}
     37 
     38 	return 0;
     39 }
     40