Merge pull request #6733 from gojimmypi/windows-gettime_secs

implement gettime_secs for Windows (_MSC_VER) in tests/api.c
This commit is contained in:
JacobBarthelmeh
2023-09-11 09:31:30 -06:00
committed by GitHub

View File

@ -66471,12 +66471,28 @@ static const char* apitest_res_string(int res)
#ifndef WOLFSSL_UNIT_TEST_NO_TIMING #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
static double gettime_secs(void) static double gettime_secs(void)
{ #if defined(_MSC_VER) && defined(_WIN32)
struct timeval tv; {
LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); /* there's no gettimeofday for Windows, so we'll use system time */
#define EPOCH_DIFF 11644473600LL
FILETIME currentFileTime;
GetSystemTimePreciseAsFileTime(&currentFileTime);
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; ULARGE_INTEGER uli = { 0, 0 };
} uli.LowPart = currentFileTime.dwLowDateTime;
uli.HighPart = currentFileTime.dwHighDateTime;
/* Convert to seconds since Unix epoch */
return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
}
#else
{
struct timeval tv;
LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
}
#endif
#endif #endif
int ApiTest(void) int ApiTest(void)