sched/hrtimer: Fix test in QEMU.

This commit fixed the hrtimer test.
In a QEMU environment, the hrtimer latency can be arbitrary because vCPUs can be preempted. We can not assert the latency. we can only issue alerts for excessively high latency.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen 2026-01-29 16:08:24 +08:00 committed by Matteo Golin
parent 9b84a0ab02
commit e69f9e902b

View file

@ -100,9 +100,9 @@ static uint64_t
test_hrtimer_callback(FAR const hrtimer_t *hrtimer, uint64_t expired)
{
struct timespec ts;
uint32_t diff;
int64_t diff;
uint64_t now;
int ret;
int ret;
FAR struct hrtimer_test_s *test =
(FAR struct hrtimer_test_s *)hrtimer;
@ -116,18 +116,20 @@ test_hrtimer_callback(FAR const hrtimer_t *hrtimer, uint64_t expired)
clock_systime_timespec(&ts);
now = clock_time2nsec(&ts);
/* Skip comparison for first two invocations */
/* Verify the timer interval is exactly
* 500ms with nsec resolution
*/
if (test->count > 2)
diff = now - expired;
/* Ensure the time diff is valid. */
ASSERT(diff >= 0);
if (diff > HRTIMER_TEST_MARGIN)
{
/* Verify the timer interval is exactly
* 500ms with nsec resolution
*/
diff = (uint32_t)(now - expired);
ASSERT(NSEC_PER_50MS < diff + HRTIMER_TEST_MARGIN);
ASSERT(NSEC_PER_50MS > diff - HRTIMER_TEST_MARGIN);
printf("hrtimer_test: warning diff=%" PRIu64 " > %" PRIu64 "\n",
diff, HRTIMER_TEST_MARGIN);
}
test->timestamp = now;