This test puts a system into suspend state and uses CLOCK_BOOTTIME_ALARM
to wake the system up. This alarm can only wake up systems that have a
wakeup capable RTC source. On systems without such an RTC (for example,
most RISC-V boards), this test puts the system into suspend and just
hangs, requiring power cycling.

clock_getres(CLOCK_BOOTTIME_ALARM) fails with EINVAL on such systems,
so add a check based on that to skip this test on systems without a
wakeup capable RTC source.

Signed-off-by: Anirudh Srinivasan <[email protected]>
---
 tools/testing/selftests/breakpoints/step_after_suspend_test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c 
b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
index ca2aaab9e4ca..727790259429 100644
--- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
+++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
@@ -18,6 +18,7 @@
 #include <sys/timerfd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <time.h>
 
 #include "kselftest.h"
 
@@ -158,11 +159,21 @@ void suspend(void)
        int err;
        int count_before;
        int count_after;
+       struct timespec res;
        struct itimerspec spec = {};
 
        if (getuid() != 0)
                ksft_exit_skip("Please run the test as root - Exiting.\n");
 
+       /*
+        * CLOCK_BOOTTIME_ALARM cannot wake up systems that don't have a
+        * wakeup capable RTC from suspend. Check if we have a wakeup-capable
+        * RTC to prevent this test from causing the system to hang after
+        * it suspends.
+        */
+       if (clock_getres(CLOCK_BOOTTIME_ALARM, &res) != 0)
+               ksft_exit_skip("No wakeup-capable RTC for 
CLOCK_BOOTTIME_ALARM\n");
+
        timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
        if (timerfd < 0)
                ksft_exit_fail_msg("timerfd_create() failed\n");

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20261002-breakpoints_rtc-0686388d44ff

Best regards,
--  
Anirudh Srinivasan <[email protected]>


Reply via email to