mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-15 03:53:58 +08:00
common: C++ RateKeeper (#29374)
* c++ RateKeeper * add to files_common * use util::random_int * improve monotor_time * remove ~ratekeeper old-commit-hash: 3eef63af9b4f4a25bc4c3a0d6ad450bba9f62205
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
test_ratekeeper
|
||||
test_util
|
||||
test_swaglog
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch2/catch.hpp"
|
||||
#include "common/ratekeeper.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/util.h"
|
||||
|
||||
TEST_CASE("RateKeeper") {
|
||||
float freq = GENERATE(10, 50, 100);
|
||||
RateKeeper rk("Test RateKeeper", freq);
|
||||
for (int i = 0; i < freq; ++i) {
|
||||
double begin = seconds_since_boot();
|
||||
util::sleep_for(util::random_int(0, 1000.0 / freq - 1));
|
||||
bool lagged = rk.keepTime();
|
||||
REQUIRE(std::abs(seconds_since_boot() - begin - (1 / freq)) < 1e-3);
|
||||
REQUIRE(lagged == false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user