[PATCH] rtc02: skip (TCONF) on read-only RTCs that reject RTC_SET_TIME
Kuba Pawlak via ltp <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
Some RTC hardware does not allow setting the time from the host. For example Qualcomm PMIC RTCs (rtc-pm8xxx) that are configured without the allow-set-time DT property and without an nvmem/UEFI offset return -ENODEV from RTC_SET_TIME; the counter free-runs from the epoch and is only usable as an uptime source. On such devices rtc02 currently reports TFAIL, which is a hardware limitation rather than a kernel defect. Probe whether the RTC can be set in the setup phase, writing back the value just read so a writable RTC is left unchanged. When RTC_SET_TIME fails with an errno that indicates the operation is unsupported or not permitted (ENODEV, EOPNOTSUPP, EINVAL, EACCES, EPERM), skip the whole test with TCONF. Doing the check in setup, before tst_rtc_clock_save(), also avoids the cleanup path (tst_rtc_clock_restore()) issuing RTC_SET_TIME and turning the run into a TBROK on such devices. If the probe succeeds the test body runs as before, so no additional handling is needed there. Signed-off-by: Kuba Pawlak <[email protected]> --- testcases/kernel/device-drivers/rtc/rtc02.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testcases/kernel/device-drivers/rtc/rtc02.c b/testcases/kernel/device-drivers/rtc/rtc02.c index 34509ab..9103d60 100644 --- a/testcases/kernel/device-drivers/rtc/rtc02.c +++ b/testcases/kernel/device-drivers/rtc/rtc02.c @@ -16,6 +16,7 @@ */ #include <stdio.h> +#include <errno.h> #include "tst_rtctime.h" #include "tst_wallclock.h" #include "tst_test.h" @@ -133,10 +134,29 @@ static void set_rtc_test(void) static void rtc_setup(void) { int exists = access(rtc_dev, F_OK); + struct rtc_time probe_tm; if (exists < 0) tst_brk(TCONF, "RTC device %s not available", rtc_dev); + /* + * Skip on RTCs that do not allow setting the time, e.g. Qualcomm PMIC + * RTCs without allow-set-time or an nvmem offset, where RTC_SET_TIME + * returns -ENODEV. Probe with the current time so a writable RTC is + * left unchanged, and skip here (before tst_rtc_clock_save()) so the + * cleanup restore does not fail on such devices. + */ + if (tst_rtc_gettime(rtc_dev, &probe_tm)) + tst_brk(TBROK | TERRNO, "ioctl() RTC_RD_TIME"); + if (tst_rtc_settime(rtc_dev, &probe_tm)) { + if (errno == ENODEV || errno == EOPNOTSUPP || + errno == EINVAL || errno == EACCES || errno == EPERM) + tst_brk(TCONF | TERRNO, + "RTC does not support setting the time"); + + tst_brk(TBROK | TERRNO, "ioctl() RTC_SET_TIME"); + } + tst_rtc_clock_save(rtc_dev); } -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp