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 the time interval in rqtp passes if TIMER_ABSTIME is not set 10 * in flags. 11 */ 12#include <stdio.h> 13#include <time.h> 14#include "posixtest.h" 15 16#define SLEEPNSEC 3000000 17 18int main(int argc, char *argv[]) 19{ 20 struct timespec tssleep, tsbefore, tsafter; 21 int slepts=0,sleptns=0; 22 23 if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { 24 perror("clock_gettime() did not return success\n"); 25 return PTS_UNRESOLVED; 26 } 27 28 tssleep.tv_sec=0; 29 tssleep.tv_nsec=SLEEPNSEC; 30 if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) != 0) { 31 printf("clock_nanosleep() did not return success\n"); 32 return PTS_UNRESOLVED; 33 } 34 35 if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { 36 perror("Error in clock_gettime()\n"); 37 return PTS_UNRESOLVED; 38 } 39 40 /* 41 * Generic alg for calculating slept time. 42 */ 43 slepts=tsafter.tv_sec-tsbefore.tv_sec; 44 sleptns=tsafter.tv_nsec-tsbefore.tv_nsec; 45 if (sleptns < 0) { 46 sleptns = sleptns+1000000000; 47 slepts = slepts-1; 48 } 49 50 if ((slepts > 0) || (sleptns > SLEEPNSEC)) { 51 printf("Test PASSED\n"); 52 return PTS_PASS; 53 } else { 54 printf("clock_nanosleep() did not sleep long enough\n"); 55 return PTS_FAIL; 56 } 57 58 printf("This code should not be executed.\n"); 59 return PTS_UNRESOLVED; 60} 61