12c28215423293e443469a07ae7011135d058b671Garrett Cooper/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license. For the full content 52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree. 70dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that parameter CLOCK_REALTIME returns seconds since the 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Epoch. (This test is similar to other tests written, but rewritten 90dc076565f772bb1953209fb69ea150b494aaa40robbiew * here for completeness.) 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * Validity is compared with gettimeofday(). See rationale.txt for 110dc076565f772bb1953209fb69ea150b494aaa40robbiew * more info. 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * If the clocks are within a few seconds of each other, the test is 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * a pass. 140dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 150dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 160dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <time.h> 170dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/time.h> 180dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdlib.h> 190dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 200dc076565f772bb1953209fb69ea150b494aaa40robbiew 210dc076565f772bb1953209fb69ea150b494aaa40robbiew#define ACCEPTABLEDELTA 1 220dc076565f772bb1953209fb69ea150b494aaa40robbiew 239cfdedaa7deeeff1697de9deb1996d0b6e0bbb6bCyril Hrubisint main(void) 240dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 250dc076565f772bb1953209fb69ea150b494aaa40robbiew struct timespec tpundertest; 260dc076565f772bb1953209fb69ea150b494aaa40robbiew struct timeval tvstandard; 270dc076565f772bb1953209fb69ea150b494aaa40robbiew int delta; 280dc076565f772bb1953209fb69ea150b494aaa40robbiew 290dc076565f772bb1953209fb69ea150b494aaa40robbiew if (clock_gettime(CLOCK_REALTIME, &tpundertest) == 0) { 300dc076565f772bb1953209fb69ea150b494aaa40robbiew if (gettimeofday(&tvstandard, NULL) == 0) { 31354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao delta = (int)tvstandard.tv_sec - 32354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (int)tpundertest.tv_sec; 33df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (abs(delta) <= ACCEPTABLEDELTA) { 340dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 350dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 360dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 370dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("FAIL: expected %d, received %d\n", 38354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (int)tvstandard.tv_sec, 39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (int)tpundertest.tv_sec); 400dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 410dc076565f772bb1953209fb69ea150b494aaa40robbiew } 420dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 430dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Error calling gettimeofday()\n"); 440dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 450dc076565f772bb1953209fb69ea150b494aaa40robbiew } 460dc076565f772bb1953209fb69ea150b494aaa40robbiew } 470dc076565f772bb1953209fb69ea150b494aaa40robbiew 489ca9633cb75c407a81b98673891982b2e0702b29Cyril Hrubis printf("clock_gettime() failed\n"); 490dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 50ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 51