From abe8d262465409e7e421f87fdd31488782c49f04 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 24 May 2017 21:16:43 +0200 Subject: [PATCH] move epoch_usec() to test.c --- demos/test.c | 30 ++++++++++++++++++++++++++++++ testprof/tomcrypt_test.h | 1 - testprof/x86_prof.c | 30 ------------------------------ 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/demos/test.c b/demos/test.c index bdb6496..85165d8 100644 --- a/demos/test.c +++ b/demos/test.c @@ -32,6 +32,36 @@ static const struct { LTC_TEST_FN(multi_test), }; +#if defined(_WIN32) + #include /* GetSystemTimeAsFileTime */ +#else + #include +#endif + +/* microseconds since 1970 (UNIX epoch) */ +static ulong64 epoch_usec(void) +{ +#if defined(LTC_NO_TEST_TIMING) + return 0; +#elif defined(_WIN32) + FILETIME CurrentTime; + ulong64 cur_time; + ULARGE_INTEGER ul; + GetSystemTimeAsFileTime(&CurrentTime); + ul.LowPart = CurrentTime.dwLowDateTime; + ul.HighPart = CurrentTime.dwHighDateTime; + cur_time = ul.QuadPart; + cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */ + cur_time /= 10; /* nanoseconds > microseconds */ + return cur_time; +#else + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); + return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */ +#endif +} + int main(int argc, char **argv) { int x, pass = 0, fail = 0, nop = 0; diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h index 6ad1408..59745b9 100644 --- a/testprof/tomcrypt_test.h +++ b/testprof/tomcrypt_test.h @@ -70,7 +70,6 @@ extern const struct ltc_prng_descriptor no_prng_desc; int sorter(const void *a, const void *b); void tally_results(int type); ulong64 rdtsc (void); -ulong64 epoch_usec(void); void t_start(void); ulong64 t_read(void); diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c index 240fb91..03f4003 100644 --- a/testprof/x86_prof.c +++ b/testprof/x86_prof.c @@ -1,35 +1,5 @@ #include -#if defined(_WIN32) - #include /* GetSystemTimeAsFileTime */ -#else - #include -#endif - -/* microseconds since 1970 (UNIX epoch) */ -ulong64 epoch_usec(void) -{ -#if defined(LTC_NO_TEST_TIMING) - return 0; -#elif defined(_WIN32) - FILETIME CurrentTime; - ulong64 cur_time; - ULARGE_INTEGER ul; - GetSystemTimeAsFileTime(&CurrentTime); - ul.LowPart = CurrentTime.dwLowDateTime; - ul.HighPart = CurrentTime.dwHighDateTime; - cur_time = ul.QuadPart; - cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */ - cur_time /= 10; /* nanoseconds > microseconds */ - return cur_time; -#else - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */ -#endif -} - struct list results[100]; int no_results; int sorter(const void *a, const void *b)