mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 22:23:56 +08:00
fix RateKeeper test
This commit is contained in:
@@ -6,11 +6,18 @@
|
||||
TEST_CASE("RateKeeper") {
|
||||
float freq = GENERATE(10, 50, 100);
|
||||
RateKeeper rk("Test RateKeeper", freq);
|
||||
|
||||
int lags = 0;
|
||||
int bad_keep_times = 0;
|
||||
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);
|
||||
lags += lagged;
|
||||
bad_keep_times += (seconds_since_boot() - begin - (1 / freq)) > 1e-3;
|
||||
}
|
||||
|
||||
// need a tolerance here due to scheduling
|
||||
REQUIRE(lags < 5);
|
||||
REQUIRE(bad_keep_times < 5);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user