updated tests
This commit is contained in:
@@ -1,9 +1,26 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <winsock.h>
|
||||
|
||||
#include "tsDefs.h"
|
||||
#include "osiTime.h"
|
||||
#include "osiSleep.h"
|
||||
#include "epicsAssert.h"
|
||||
|
||||
#ifndef CLOCK_REALTIME
|
||||
|
||||
//
|
||||
// this is part of the POSIX RT standard but some OS
|
||||
// still do not define this in time.h
|
||||
//
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds since some epoch */
|
||||
long tv_nsec; /* nanoseconds within the second */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -11,23 +28,34 @@ int main ()
|
||||
osiTime begin = osiTime::getCurrent();
|
||||
const unsigned iter = 100000u;
|
||||
TS_STAMP stamp;
|
||||
struct timespec ts;
|
||||
struct tm tm;
|
||||
tm_nano_sec ansiDate;
|
||||
char stampText[128];
|
||||
double diff;
|
||||
|
||||
for (i=0;i<iter;i++) {
|
||||
for (i=0; i<iter; i++) {
|
||||
osiTime tmp = osiTime::getCurrent();
|
||||
}
|
||||
|
||||
osiTime end = osiTime::getCurrent();
|
||||
|
||||
osiTime diff = end - begin;
|
||||
diff = end - begin;
|
||||
printf ("elapsed per call to osiTime::getCurrent() = %f\n",
|
||||
((double) diff)/iter);
|
||||
diff/iter);
|
||||
|
||||
stamp = osiTime::getCurrent();
|
||||
stamp = begin;
|
||||
ansiDate = begin;
|
||||
ts = begin;
|
||||
|
||||
tsStampToText (&stamp, TS_TEXT_MMDDYY, stampText);
|
||||
|
||||
printf ("osiTime::getCurrent() = %s\n", stampText);
|
||||
printf ("TS_STAMP = %s\n", stampText);
|
||||
printf ("struct tm = %s %f\n", asctime(&ansiDate.tm),
|
||||
ansiDate.nsec/(double)osiTime::nSecPerSec);
|
||||
tm = *localtime (&ts.tv_sec);
|
||||
printf ("struct timespec = %s %f\n", asctime(&ansiDate.tm),
|
||||
ts.tv_nsec/(double)osiTime::nSecPerSec);
|
||||
begin.show (0);
|
||||
|
||||
osiTime copy = end;
|
||||
assert (copy==end);
|
||||
@@ -44,6 +72,20 @@ int main ()
|
||||
begin -= diff;
|
||||
assert (begin+diff==end);
|
||||
|
||||
//
|
||||
// test struct tm conversions
|
||||
//
|
||||
ansiDate = begin;
|
||||
begin = ansiDate;
|
||||
assert (begin+diff==end);
|
||||
|
||||
//
|
||||
// test struct timespec conversion
|
||||
//
|
||||
ts = begin;
|
||||
begin = ts;
|
||||
assert (begin+diff==end);
|
||||
|
||||
//
|
||||
// examine the drift
|
||||
//
|
||||
@@ -54,5 +96,7 @@ int main ()
|
||||
}
|
||||
#endif
|
||||
|
||||
printf ("test complete\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user