* [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test
@ 2025-11-12 6:15 Xinyu Zheng
2025-11-19 22:15 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: Xinyu Zheng @ 2025-11-12 6:15 UTC (permalink / raw)
To: Shuah Khan
Cc: Moon Hee Lee, yifei.l.liu, zhujun2, linux-kselftest, linux-kernel,
zouyipeng, zhengxinyu6
If RTC wakeup alarm feature is unsupported, this testcase may cause
infinite suspend if there is no other wakeup source. To solve this
problem, set wakeup alarm up before we trigger suspend. In this case,
we can test if RTC support RTC_FEATURE_ALARM and efi_set_alarm function.
Signed-off-by: Xinyu Zheng <zhengxinyu6@huawei.com>
---
.../breakpoints/step_after_suspend_test.c | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
index 8d233ac95696..e738af896ce1 100644
--- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
+++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
@@ -13,6 +13,8 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/timerfd.h>
@@ -159,10 +161,30 @@ void suspend(void)
int count_before;
int count_after;
struct itimerspec spec = {};
+ char *rtc_file = "/dev/rtc0";
+ int rtc_fd;
+ struct rtc_wkalrm alarm = { 0 };
+ time_t secs;
if (getuid() != 0)
ksft_exit_skip("Please run the test as root - Exiting.\n");
+ rtc_fd = open(rtc_file, O_RDONLY);
+ if (rtc_fd < 0)
+ ksft_exit_fail_msg("open rtc0 failed\n");
+
+ err = ioctl(rtc_fd, RTC_RD_TIME, &alarm.time);
+ if (err < 0)
+ ksft_exit_fail_msg("get rtc time failed\n");
+
+ secs = timegm((struct tm *)&alarm.time) + 3;
+ gmtime_r(&secs, (struct tm *)&alarm.time);
+ alarm.enabled = 1;
+
+ err = ioctl(rtc_fd, RTC_WKALM_SET, &alarm);
+ if (err < 0)
+ ksft_exit_fail_msg("set wake alarm test failed, errno %d\n", errno);
+
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
if (timerfd < 0)
ksft_exit_fail_msg("timerfd_create() failed\n");
@@ -180,6 +202,7 @@ void suspend(void)
if (count_after <= count_before)
ksft_exit_fail_msg("Failed to enter Suspend state\n");
+ close(rtc_fd);
close(timerfd);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test
2025-11-12 6:15 [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test Xinyu Zheng
@ 2025-11-19 22:15 ` Shuah Khan
2025-12-01 8:31 ` Xinyu Zheng
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2025-11-19 22:15 UTC (permalink / raw)
To: Xinyu Zheng, Shuah Khan
Cc: Moon Hee Lee, yifei.l.liu, zhujun2, linux-kselftest, linux-kernel,
zouyipeng, Shuah Khan
On 11/11/25 23:15, Xinyu Zheng wrote:
> If RTC wakeup alarm feature is unsupported, this testcase may cause
It may cause infinite suspend? Doesn't sound definitive.> infinite suspend if there is no other wakeup source. To solve this
> problem, set wakeup alarm up before we trigger suspend. In this case,
> we can test if RTC support RTC_FEATURE_ALARM and efi_set_alarm function.
>
For a "may cause" problem, this change> Signed-off-by: Xinyu Zheng <zhengxinyu6@huawei.com>
> ---> .../breakpoints/step_after_suspend_test.c | 23 +++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
> index 8d233ac95696..e738af896ce1 100644
> --- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
> +++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
> @@ -13,6 +13,8 @@
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> +#include <linux/rtc.h>
> +#include <sys/ioctl.h>
> #include <sys/ptrace.h>
> #include <sys/stat.h>
> #include <sys/timerfd.h>
> @@ -159,10 +161,30 @@ void suspend(void)
> int count_before;
> int count_after;
> struct itimerspec spec = {};
> + char *rtc_file = "/dev/rtc0";
> + int rtc_fd;
> + struct rtc_wkalrm alarm = { 0 };
> + time_t secs;
>
> if (getuid() != 0)
> ksft_exit_skip("Please run the test as root - Exiting.\n");
>
> + rtc_fd = open(rtc_file, O_RDONLY);
> + if (rtc_fd < 0)
> + ksft_exit_fail_msg("open rtc0 failed\n");
> +
> + err = ioctl(rtc_fd, RTC_RD_TIME, &alarm.time);
> + if (err < 0)
> + ksft_exit_fail_msg("get rtc time failed\n");
> +
> + secs = timegm((struct tm *)&alarm.time) + 3;
> + gmtime_r(&secs, (struct tm *)&alarm.time);
> + alarm.enabled = 1;
> +
> + err = ioctl(rtc_fd, RTC_WKALM_SET, &alarm);
> + if (err < 0)
> + ksft_exit_fail_msg("set wake alarm test failed, errno %d\n", errno);
Essentially with this change the test doesn't run unless
RTC wake is supported. That sounds restrictive - is there
another way do do this?
> +
> timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
> if (timerfd < 0)
> ksft_exit_fail_msg("timerfd_create() failed\n");
> @@ -180,6 +202,7 @@ void suspend(void)
> if (count_after <= count_before)
> ksft_exit_fail_msg("Failed to enter Suspend state\n");
>
> + close(rtc_fd);
> close(timerfd);
> }
>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test
2025-11-19 22:15 ` Shuah Khan
@ 2025-12-01 8:31 ` Xinyu Zheng
0 siblings, 0 replies; 3+ messages in thread
From: Xinyu Zheng @ 2025-12-01 8:31 UTC (permalink / raw)
To: Shuah Khan, Shuah Khan
Cc: Moon Hee Lee, yifei.l.liu, zhujun2, linux-kselftest, linux-kernel,
zouyipeng
On 11/20/2025 6:15 AM, Shuah Khan wrote:
> On 11/11/25 23:15, Xinyu Zheng wrote:
>> If RTC wakeup alarm feature is unsupported, this testcase may cause
>
> It may cause infinite suspend? Doesn't sound definitive.> infinite
> suspend if there is no other wakeup source. To solve this
>> problem, set wakeup alarm up before we trigger suspend. In this case,
>> we can test if RTC support RTC_FEATURE_ALARM and efi_set_alarm function.
>>
>
> For a "may cause" problem, this change> Signed-off-by: Xinyu Zheng
> <zhengxinyu6@huawei.com>
>> ---> .../breakpoints/step_after_suspend_test.c | 23 ++++++++++++
>> +++++++
>> 1 file changed, 23 insertions(+)
>>
>> diff --git a/tools/testing/selftests/breakpoints/
>> step_after_suspend_test.c b/tools/testing/selftests/breakpoints/
>> step_after_suspend_test.c
>> index 8d233ac95696..e738af896ce1 100644
>> --- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
>> +++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
>> @@ -13,6 +13,8 @@
>> #include <stdio.h>
>> #include <string.h>
>> #include <unistd.h>
>> +#include <linux/rtc.h>
>> +#include <sys/ioctl.h>
>> #include <sys/ptrace.h>
>> #include <sys/stat.h>
>> #include <sys/timerfd.h>
>> @@ -159,10 +161,30 @@ void suspend(void)
>> int count_before;
>> int count_after;
>> struct itimerspec spec = {};
>> + char *rtc_file = "/dev/rtc0";
>> + int rtc_fd;
>> + struct rtc_wkalrm alarm = { 0 };
>> + time_t secs;
>> if (getuid() != 0)
>> ksft_exit_skip("Please run the test as root - Exiting.\n");
>> + rtc_fd = open(rtc_file, O_RDONLY);
>> + if (rtc_fd < 0)
>> + ksft_exit_fail_msg("open rtc0 failed\n");
>> +
>> + err = ioctl(rtc_fd, RTC_RD_TIME, &alarm.time);
>> + if (err < 0)
>> + ksft_exit_fail_msg("get rtc time failed\n");
>> +
>> + secs = timegm((struct tm *)&alarm.time) + 3;
>> + gmtime_r(&secs, (struct tm *)&alarm.time);
>> + alarm.enabled = 1;
>> +
>> + err = ioctl(rtc_fd, RTC_WKALM_SET, &alarm);
>> + if (err < 0)
>> + ksft_exit_fail_msg("set wake alarm test failed, errno %d\n",
>> errno);
>
> Essentially with this change the test doesn't run unless
> RTC wake is supported. That sounds restrictive - is there
> another way do do this?
Hi, Shuah.
If RTC wake is a must in this testcase?
In my test, when EFI report supporting EFI_RT_SUPPORTED_SET_WAKEUP_TIME.
There will be a alarmtimer.0.auto under /sys/class/rtc/rtc0/,while
suspending, I found alarmtimer will also been suspended and pass the
wakeup job to RTC. When RTC calls efi_set_alarm(), this function returns
EFI_UNSUPPORTED then suspend fails.
When EFI doesn't report supporting EFI_RT_SUPPORTED_SET_WAKEUP_TIME,
there is no /sys/class/rtc/rtc0/alarmtimer.0.auto and alarmtimer is not
a suspend target. Then suspend success, but never wakeup.
>
>> +
>> timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
>> if (timerfd < 0)
>> ksft_exit_fail_msg("timerfd_create() failed\n");
>> @@ -180,6 +202,7 @@ void suspend(void)
>> if (count_after <= count_before)
>> ksft_exit_fail_msg("Failed to enter Suspend state\n");
>> + close(rtc_fd);
>> close(timerfd);
>> }
>>
> thanks,
> -- Shuah
--
Xinyu Zheng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-01 8:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 6:15 [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test Xinyu Zheng
2025-11-19 22:15 ` Shuah Khan
2025-12-01 8:31 ` Xinyu Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox