1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

tests/timer: test absolute timing

This commit is contained in:
daniel-k 2018-01-16 15:26:19 +01:00
parent 61de103c9e
commit 21d1dd0a71

View file

@ -21,14 +21,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <chrono>
#include <criterion/criterion.h>
#include "config.h"
#include <villas/log.hpp>
#include <villas/fpga/card.hpp>
#include <villas/fpga/ips/timer.hpp>
#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<villas::fpga::ip::Timer&>(*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<std::chrono::microseconds>(duration).count();
logger->info("-> time passed: {} us", durationUs);
cr_assert(std::abs(durationUs - oneSecondInUs) < 0.01 * oneSecondInUs,
"Timer deviation > 1%%");
}
return;