From 21d1dd0a71d723a0e74ea0152ee4c8512180d32c Mon Sep 17 00:00:00 2001 From: daniel-k Date: Tue, 16 Jan 2018 15:26:19 +0100 Subject: [PATCH] tests/timer: test absolute timing --- fpga/tests/timer.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fpga/tests/timer.cpp b/fpga/tests/timer.cpp index b25935c13..f6dd0b009 100644 --- a/fpga/tests/timer.cpp +++ b/fpga/tests/timer.cpp @@ -21,14 +21,14 @@ * along with this program. If not, see . *********************************************************************************/ +#include #include - -#include "config.h" - #include #include #include +#include "config.h" + extern villas::fpga::PCIeCard* fpga; Test(fpga, timer, .description = "Timer Counter") @@ -45,10 +45,26 @@ Test(fpga, timer, .description = "Timer Counter") auto timer = reinterpret_cast(*ip); + logger->info("Test simple waiting"); timer.start(timer.getFrequency() / 10); - cr_assert(timer.wait(), "Timer failed"); + cr_assert(timer.wait(), "Waiting failed"); + logger->info("-> passed"); - logger->info("Timer passed: {}", timer); + logger->info("Measure waiting time (1s)"); + timer.start(timer.getFrequency()); + + const auto start = std::chrono::high_resolution_clock::now(); + timer.wait(); + const auto stop = std::chrono::high_resolution_clock::now(); + + const int oneSecondInUs = 1000000; + const auto duration = stop - start; + const auto durationUs = + std::chrono::duration_cast(duration).count(); + logger->info("-> time passed: {} us", durationUs); + + cr_assert(std::abs(durationUs - oneSecondInUs) < 0.01 * oneSecondInUs, + "Timer deviation > 1%%"); } return;