1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 * Test that clock_nanosleep() causes the current thread to be suspended 9 * until a signal whose action is to terminate the process is received. 10 */ 11 #include <stdio.h> 12 #include <time.h> 13 #include <signal.h> 14 #include <unistd.h> 15 #include <sys/wait.h> 16 #include "posixtest.h" 17 18 #define SLEEPSEC 30 19 20 int main(void) 21 { 22 struct timespec tssleep, tsbefore, tsafter; 23 int pid; 24 25 if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { 26 perror("clock_gettime() did not return success\n"); 27 return PTS_UNRESOLVED; 28 } 29 30 if ((pid = fork()) == 0) { 31 /* child here */ 32 tssleep.tv_sec = SLEEPSEC; 33 tssleep.tv_nsec = 0; 34 clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL); 35 } else { 36 /* parent here */ 37 int i; 38 39 sleep(1); 40 41 if (kill(pid, SIGABRT) != 0) { 42 printf("Could not raise signal being tested\n"); 43 return PTS_UNRESOLVED; 44 } 45 46 if (wait(&i) == -1) { 47 perror("Error waiting for child to exit\n"); 48 return PTS_UNRESOLVED; 49 } 50 if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { 51 perror("clock_gettime() did not return success\n"); 52 return PTS_UNRESOLVED; 53 } 54 55 /* 56 * pass if we slept for less than the (large) sleep time 57 * allotted 58 */ 59 if ((tsafter.tv_sec - tsbefore.tv_sec) < SLEEPSEC) { 60 printf("Test PASSED\n"); 61 return PTS_PASS; 62 } else { 63 printf("Slept for too long: %d >= %d\n", 64 (int)tsafter.tv_sec - (int)tsbefore.tv_sec, 65 SLEEPSEC); 66 printf("Test FAILED\n"); 67 return PTS_FAIL; 68 } 69 } 70 71 return PTS_UNRESOLVED; 72 } 73