This is an automated email from the ASF dual-hosted git repository.

linguini pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit e69f9e902b354a94a37672296af41bcb4a0e5ef4
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Thu Jan 29 16:08:24 2026 +0800

    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 <[email protected]>
---
 testing/ostest/hrtimer.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/testing/ostest/hrtimer.c b/testing/ostest/hrtimer.c
index 585c6f30a..d82cf171a 100644
--- a/testing/ostest/hrtimer.c
+++ b/testing/ostest/hrtimer.c
@@ -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)
-    {
-      /* Verify the timer interval is exactly
-       * 500ms with nsec resolution
-       */
+  diff = now - expired;
 
-      diff = (uint32_t)(now - expired);
+  /* Ensure the time diff is valid. */
 
-      ASSERT(NSEC_PER_50MS < diff + HRTIMER_TEST_MARGIN);
-      ASSERT(NSEC_PER_50MS > diff - HRTIMER_TEST_MARGIN);
+  ASSERT(diff >= 0);
+
+  if (diff > HRTIMER_TEST_MARGIN)
+    {
+      printf("hrtimer_test: warning diff=%" PRIu64 " > %" PRIu64 "\n",
+             diff, HRTIMER_TEST_MARGIN);
     }
 
   test->timestamp = now;

Reply via email to