2-1.c revision 0dc076565f772bb1953209fb69ea150b494aaa40
10dc076565f772bb1953209fb69ea150b494aaa40robbiew/* 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 50dc076565f772bb1953209fb69ea150b494aaa40robbiew * 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 230dc076565f772bb1953209fb69ea150b494aaa40robbiewint main(int argc, char *argv[]) 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) { 310dc076565f772bb1953209fb69ea150b494aaa40robbiew delta = (int) tvstandard.tv_sec - 320dc076565f772bb1953209fb69ea150b494aaa40robbiew (int) tpundertest.tv_sec; 330dc076565f772bb1953209fb69ea150b494aaa40robbiew if ( abs(delta) <= ACCEPTABLEDELTA) { 340dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 350dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 360dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 370dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("FAIL: expected %d, received %d\n", 380dc076565f772bb1953209fb69ea150b494aaa40robbiew (int) tvstandard.tv_sec, 390dc076565f772bb1953209fb69ea150b494aaa40robbiew (int) tpundertest.tv_sec); 400dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 410dc076565f772bb1953209fb69ea150b494aaa40robbiew } 420dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 430dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Error calling gettimeofday()\n"); 440dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 450dc076565f772bb1953209fb69ea150b494aaa40robbiew } 460dc076565f772bb1953209fb69ea150b494aaa40robbiew } else { 470dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("clock_gettime() failed\n"); 480dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 490dc076565f772bb1953209fb69ea150b494aaa40robbiew } 500dc076565f772bb1953209fb69ea150b494aaa40robbiew 510dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("This code should not be executed.\n"); 520dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 530dc076565f772bb1953209fb69ea150b494aaa40robbiew} 54