diff --git a/CMakeLists.txt b/CMakeLists.txt index f8841783c5b..a38d409bc4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1823,6 +1823,7 @@ add_executable(mixxx-test src/test/broadcastsettings_test.cpp src/test/cache_test.cpp src/test/channelhandle_test.cpp + src/test/chrono_clock_resolution_test.cpp src/test/colorconfig_test.cpp src/test/colormapperjsproxy_test.cpp src/test/colorpalette_test.cpp diff --git a/src/test/chrono_clock_resolution_test.cpp b/src/test/chrono_clock_resolution_test.cpp new file mode 100644 index 00000000000..c087dd40488 --- /dev/null +++ b/src/test/chrono_clock_resolution_test.cpp @@ -0,0 +1,30 @@ +#include + +#include +#include +#include + +namespace { + +static constexpr auto kMinResolution = std::chrono::milliseconds(1); +static constexpr auto kNumIterations = 1000; + +} // namespace + +using namespace std::chrono_literals; + +TEST(ChronoClockResolutionTest, SteadyClockTicksAreSmallerThan1Ms) { + std::vector ticks; + ticks.reserve(kNumIterations); + for (int i = 0; i < kNumIterations; ++i) { + const auto start = std::chrono::steady_clock::now(); + const auto end = std::chrono::steady_clock::now(); + ticks.push_back(end - start); + } + // Make sure there is no aliasing going on. + ASSERT_TRUE(std::all_of(ticks.begin(), ticks.end(), [](const auto& tick) { + return tick >= 0ns; + })); + // make sure that at least one duration is smaller than the minimum resolution + ASSERT_LT(*std::min_element(ticks.begin(), ticks.end()), kMinResolution); +};