1/* 2 * Copyright (c) 2002-3, 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() does not stop if a signal is received 9 * that has no signal handler. clock_nanosleep() should still respond 10 * to the signal, but should resume after a SIGCONT signal is received. 11 * 12 * SIGSTOP will be used to stop the sleep. 13 */ 14#include <stdio.h> 15#include <time.h> 16#include <signal.h> 17#include <unistd.h> 18#include <sys/wait.h> 19#include <stdlib.h> 20#include "posixtest.h" 21 22#define SLEEPSEC 5 23 24#define CHILDPASS 1 25#define CHILDFAIL 0 26 27int main(int argc, char *argv[]) 28{ 29 int pid, slepts; 30 struct timespec tsbefore, tsafter; 31 32 if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { 33 perror("clock_gettime() did not return success\n"); 34 return PTS_UNRESOLVED; 35 } 36 37 38 if ((pid = fork()) == 0) { 39 /* child here */ 40 struct timespec tssleep; 41 42 tssleep.tv_sec=SLEEPSEC; 43 tssleep.tv_nsec=0; 44 if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) == 0) { 45 printf("clock_nanosleep() returned success\n"); 46 return CHILDPASS; 47 } else { 48 printf("clock_nanosleep() did not return success\n"); 49 return CHILDFAIL; 50 } 51 return CHILDFAIL; 52 } else { 53 /* parent here */ 54 int i; 55 56 sleep(1); 57 58 if (kill(pid, SIGSTOP) != 0) { 59 printf("Could not raise SIGSTOP\n"); 60 return PTS_UNRESOLVED; 61 } 62 63 if (kill(pid, SIGCONT) != 0) { 64 printf("Could not raise SIGCONT\n"); 65 return PTS_UNRESOLVED; 66 } 67 68 if (wait(&i) == -1) { 69 perror("Error waiting for child to exit\n"); 70 return PTS_UNRESOLVED; 71 } 72 73 if (!WIFEXITED(i) || !WEXITSTATUS(i)) { 74 printf("Test FAILED\n"); 75 return PTS_FAIL; 76 } 77 78 if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { 79 perror("Error in clock_gettime()\n"); 80 return PTS_UNRESOLVED; 81 } 82 83 slepts=tsafter.tv_sec-tsbefore.tv_sec; 84 85#ifdef DEBUG 86 printf("Start %d sec; End %d sec\n", (int) tsbefore.tv_sec, 87 (int) tsafter.tv_sec); 88#endif 89 if (slepts >= SLEEPSEC) { 90 printf("Test PASSED\n"); 91 return PTS_PASS; 92 } else { 93 printf("clock_nanosleep() did not sleep long enough\n"); 94 return PTS_FAIL; 95 } 96 97 } //end fork 98 99 return PTS_UNRESOLVED; 100} 101