23uint32_t test_periodic_measurement(U*
unit,
const uint32_t times,
const uint32_t tolerance,
24 const uint32_t timeout_duration,
void (*callback)(U*),
const bool skip_after_test)
26 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
28 auto interval =
unit->interval();
29 decltype(interval) avg{}, avgCnt{};
31 auto prev =
unit->updatedMillis();
32 auto timeout_at = m5::utility::millis() + timeout_duration;
33 while (cnt && m5::utility::millis() <= timeout_at) {
35 if (
unit->updated()) {
37 auto um =
unit->updatedMillis();
39 auto duration = um - prev;
50 std::this_thread::yield();
53 if (!skip_after_test) {
55 EXPECT_EQ(avgCnt, times - 1);
58 EXPECT_LE(avg,
decltype(interval)(interval + tolerance));
66uint32_t test_periodic_measurement(U*
unit,
const uint32_t times = 8,
const uint32_t tolerance = 1,
67 void (*callback)(U*) =
nullptr,
const bool skip_after_test =
false)
69 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
70 auto timeout_duration = (
unit->interval() * 2) * times;
71 return test_periodic_measurement(
unit, times, tolerance, timeout_duration, callback, skip_after_test);
75uint32_t test_periodic_measurement(U*
unit,
const uint32_t times = 8,
void (*callback)(U*) =
nullptr,
76 const bool skip_after_test =
false)
78 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
79 auto timeout_duration = (
unit->interval() * 2) * times;
80 return test_periodic_measurement(
unit, times, 1, timeout_duration, callback, skip_after_test);