From a0f1d61a4a8e4aca5a44c680bd209eb117c72bff Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 23 Apr 2017 12:55:45 +0300 Subject: [PATCH] test: fixup for Windows. Change-Id: I13468caf53988d9599235d1423603146abf9eb46 --- TODO.md | 1 + dll.vcxproj | 4 ++-- test/chrono.cc | 4 ++-- test/osal-windows.cc | 17 ++++++++++++----- test/test.vcxproj | 6 ++++++ test/utils.cc | 2 ++ 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 9fb41a2b..601d2fe0 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,4 @@ +- [ ] разделение errno и GetLastError() - [x] CI посредством AppVeyor - [ ] uint32/uint64 в структурах - [ ] правки API (много...) diff --git a/dll.vcxproj b/dll.vcxproj index 42658ccb..13cee8f4 100644 --- a/dll.vcxproj +++ b/dll.vcxproj @@ -77,7 +77,7 @@ - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDB_DEBUG=1 MultiThreadedDebugDLL Level3 ProgramDatabase @@ -121,7 +121,7 @@ Level3 - WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions) + WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDB_DEBUG=1 MultiThreadedDebugDLL true diff --git a/test/chrono.cc b/test/chrono.cc index 3481ad74..20eb7c36 100644 --- a/test/chrono.cc +++ b/test/chrono.cc @@ -94,7 +94,8 @@ time now_motonic() { if (reciprocal == 0) { if (!QueryPerformanceFrequency(&Frequency)) failure_perror("QueryPerformanceFrequency()", GetLastError()); - reciprocal = (UINT64_C(1) << 32) / Frequency.QuadPart; + reciprocal = + ((UINT64_C(1) << 32) + Frequency.QuadPart / 2) / Frequency.QuadPart; assert(reciprocal); } @@ -107,7 +108,6 @@ time now_motonic() { uint64_t mod = Counter.QuadPart % Frequency.QuadPart; assert(mod < UINT32_MAX); result.fractional = UInt32x32To64((uint32_t)mod, reciprocal); - assert(result.fractional == (mod << 32) / Frequency.QuadPart); return result; #else struct timespec ts; diff --git a/test/osal-windows.cc b/test/osal-windows.cc index 8a93b247..7ed4522d 100644 --- a/test/osal-windows.cc +++ b/test/osal-windows.cc @@ -14,7 +14,7 @@ #include "test.h" -static std::vector events; +static std::unordered_map events; static HANDLE hBarrierSemaphore, hBarrierEvent; static int waitstatus2errcode(DWORD result) { @@ -67,13 +67,13 @@ void osal_setup(const std::vector &actors) { const size_t n = actors.size() + 1; events.reserve(n); - for (size_t i = 0; i < n; ++i) { + for (unsigned i = 0; i < n; ++i) { HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!hEvent) failure_perror("CreateEvent()", GetLastError()); hEvent = make_inharitable(hEvent); log_trace("osal_setup: event %zu -> %p", i, hEvent); - events.push_back(hEvent); + events[i] = hEvent; } hBarrierSemaphore = CreateSemaphore(NULL, 0, (LONG)actors.size(), NULL); @@ -121,7 +121,7 @@ actor_config::osal_serialize(simple_checksum &checksum) const { HANDLE hSignal = INVALID_HANDLE_VALUE; if (wanna_event4signalling()) { - hSignal = events.at(id); + hSignal = events.at(actor_id); checksum.push(hSignal); } @@ -156,7 +156,7 @@ bool actor_config::osal_deserialize(const char *str, const char *end, if (wanna_event4signalling()) { checksum.push(hSignal); - events[id] = hSignal; + events[actor_id] = hSignal; } TRACE("<< osal_deserialize: OK\n"); @@ -278,9 +278,16 @@ void osal_udelay(unsigned us) { static unsigned threshold_us; if (threshold_us == 0) { +#if 1 + unsigned timeslice_ms = 1; + while (timeBeginPeriod(timeslice_ms) == TIMERR_NOCANDO) + ++timeslice_ms; + threshold_us = timeslice_ms * 1500u; +#else ULONGLONG InterruptTimePrecise_100ns; QueryInterruptTimePrecise(&InterruptTimePrecise_100ns); threshold_us = InterruptTimePrecise_100ns / 5; +#endif assert(threshold_us > 0); } diff --git a/test/test.vcxproj b/test/test.vcxproj index e2a123f6..047e6ae3 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -102,6 +102,7 @@ Console true + winmm.lib;%(AdditionalDependencies) @@ -116,6 +117,7 @@ Console true + winmm.lib;%(AdditionalDependencies) @@ -134,6 +136,7 @@ true true true + winmm.lib;%(AdditionalDependencies) @@ -152,10 +155,12 @@ true true true + winmm.lib;%(AdditionalDependencies) + @@ -164,6 +169,7 @@ + diff --git a/test/utils.cc b/test/utils.cc index ae6797f8..07020be2 100644 --- a/test/utils.cc +++ b/test/utils.cc @@ -14,7 +14,9 @@ #include "test.h" #include +#ifndef _MSC_VER #include +#endif std::string format(const char *fmt, ...) { va_list ap, ones;