/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * EPICS BASE Versions 3.13.7 * and higher are distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ /* * Authors: Jeff HIll and Marty Kraimer */ #include #include #include #include #include "epicsTime.h" #include "epicsThread.h" #include "errlog.h" extern "C" { int epicsTimeTest (void); } struct l_fp { /* NTP time stamp */ epicsUInt32 l_ui; /* sec past NTP epoch */ epicsUInt32 l_uf; /* fractional seconds */ }; epicsTime useSomeCPU; static const unsigned mSecPerSec = 1000u; static const unsigned uSecPerSec = 1000u * mSecPerSec; static const unsigned nSecPerSec = 1000u * uSecPerSec; void testStringConversion() { char buf[64]; epicsTime uninit; const char * pFormat = "%a %b %d %Y %H:%M:%S.%f"; uninit.strftime ( buf, sizeof ( buf ), pFormat ); printf ("Uninitialized using \"%s\" %s\n", pFormat, buf ); epicsTime current = epicsTime::getCurrent(); pFormat = "%a %b %d %Y %H:%M:%S.%f"; current.strftime ( buf, sizeof ( buf ), pFormat ); printf ("using \"%s\" %s\n", pFormat, buf ); pFormat = "%a %b %d %Y %H:%M:%S.%4f"; current.strftime ( buf, sizeof ( buf ), pFormat ); printf ("using \"%s\" %s\n", pFormat, buf ); pFormat = "%a %b %d %Y %H:%M:%S.%05f"; current.strftime ( buf, sizeof ( buf ), pFormat ); printf ("using \"%s\" %s\n", pFormat, buf ); } int epicsTimeTest (void) { unsigned i, errors, sum_errors=0, sum_errloops=0; const epicsTime begin = epicsTime::getCurrent(); const unsigned wasteTime = 100000u; const int nTimes = 100; epicsTimeStamp stamp; struct timespec ts; struct tm tmAnsi; local_tm_nano_sec ansiDate; gm_tm_nano_sec ansiDateGMT; unsigned long nanoSec; { epicsTime tsi = epicsTime::getCurrent (); l_fp ntp = tsi; epicsTime tsf = ntp; const double diff = fabs ( tsf - tsi ); // the difference in the precision of the two time formats static const double precisionNTP = 1.0 / ( 1.0 + 0xffffffff ); static const double precisionEPICS = 1.0 / nSecPerSec; assert ( diff <= precisionEPICS + precisionNTP ); } printf ("epicsTime Test (%3d loops)\n========================\n\n", nTimes); for (int iTimes=0; iTimes < nTimes; ++iTimes) { for (i=0; i=end)) { printf ("#%3d: Failed copy>=end by %12.9f\n", iTimes, (end-copy)); errors += 1; } if (!(end>begin)) { printf ("#%3d: Failed end>begin by %12.9f\n", iTimes, (begin-end)); errors += 1; } if (!(end>=begin)) { printf ("#%3d: Failed end>=begin by %12.9f\n", iTimes, (begin-end)); errors += 1; } if (!(begin