1 /* 2 * Copyright (c) 2004, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 * author: adam li 7 * Test that clock_getres() returns the resolution of clock_id in res. 8 * 9 * The clock chosen for this test is CLOCK_PROCESS_CPUTIME_ID. 10 */ 11 12 #define _XOPEN_SOURCE 600 13 #include <unistd.h> 14 #include <stdio.h> 15 #include <time.h> 16 #include "posixtest.h" 17 18 #define LARGENUM 100000 19 int main(void) 20 { 21 #if _POSIX_CPUTIME != -1 22 struct timespec res; 23 24 if (sysconf(_SC_CPUTIME) == -1) { 25 printf("_POSIX_CPUTIME not supported\n"); 26 return PTS_UNSUPPORTED; 27 } 28 29 /* Initialize res to a number much larger than the resolution 30 * could possibly be 31 */ 32 res.tv_sec = LARGENUM; 33 res.tv_nsec = LARGENUM; 34 if (clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res) == 0) { 35 if (res.tv_sec != LARGENUM) { //assume initialized 36 #ifdef DEBUG 37 printf("Resolution is %d sec %d nsec\n", 38 (int)res.tv_sec, (int)res.tv_nsec); 39 #endif 40 printf("Test PASSED\n"); 41 return PTS_PASS; 42 } else { 43 printf("clock_getres() success, but res not filled\n"); 44 } 45 } else { 46 printf("clock_getres() failed\n"); 47 } 48 49 printf("Test FAILED\n"); 50 return PTS_FAIL; 51 #else 52 printf("_POSIX_CPUTIME not supported\n"); 53 return PTS_UNSUPPORTED; 54 #endif 55 } 56