* [PATCH] selftests: rtc: Support harness test filtering and arguments
@ 2026-09-10 3:48 Wake Liu
2026-09-10 3:53 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Wake Liu @ 2026-09-10 3:48 UTC (permalink / raw)
To: Alexandre Belloni, Shuah Khan
Cc: linux-rtc, linux-kselftest, linux-kernel, Wake Liu
rtctest implements its own main() function with a rigid switch (argc)
check that only accepts an optional single argument for the RTC device
node path. This prevents kselftest_harness standard arguments from
working properly:
1. Passing filter options like -t <name> or -T <name> triggers a usage
error because argc is greater than 2.
2. Passing -l or -h causes rtctest to treat "-l" or "-h" as the device
node path and fail with access() errors before ever reaching the
harness argument checker.
Parse command line arguments with getopt() to pass all kselftest harness
options (such as -t, -T, -v, -V, -f, -F, -r, -d, -h, and -l) through to
test_harness_run(), while preserving the ability to specify an optional
RTC device node path as a non-option argument. Also ensure optind is
reset before invoking test_harness_run() so the harness can inspect the
options, and bypass device accessibility checks when help or test
listing is requested.
Signed-off-by: Wake Liu <wakel@google.com>
---
tools/testing/selftests/rtc/rtctest.c | 44 +++++++++++++++++++++------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
index 8047d9879039..57dda87ba813 100644
--- a/tools/testing/selftests/rtc/rtctest.c
+++ b/tools/testing/selftests/rtc/rtctest.c
@@ -486,18 +486,44 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
int main(int argc, char **argv)
{
int ret = -1;
+ int opt, i;
+ int non_opt = 0;
+
+ while ((opt = getopt(argc, argv, "dhlF:f:V:v:t:T:r:")) != -1) {
+ switch (opt) {
+ case 'h':
+ fprintf(stderr,
+ "Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name] [rtcdev]\n\n",
+ argv[0]);
+ optind = 1;
+ return test_harness_run(argc, argv);
+ case 'l':
+ optind = 1;
+ return test_harness_run(argc, argv);
+ case '?':
+ fprintf(stderr,
+ "Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name] [rtcdev]\n",
+ argv[0]);
+ return KSFT_FAIL;
+ default:
+ break;
+ }
+ }
- switch (argc) {
- case 2:
- rtc_file = argv[1];
- /* FALLTHROUGH */
- case 1:
- break;
- default:
- fprintf(stderr, "usage: %s [rtcdev]\n", argv[0]);
- return 1;
+ for (i = optind; i < argc; i++) {
+ if (non_opt == 0) {
+ rtc_file = argv[i];
+ non_opt++;
+ } else {
+ fprintf(stderr,
+ "Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name] [rtcdev]\n",
+ argv[0]);
+ return KSFT_FAIL;
+ }
}
+ optind = 1;
+
/* Run the test if rtc_file is accessible */
if (access(rtc_file, R_OK) == 0)
ret = test_harness_run(argc, argv);
--
2.55.0.979.g7e5102b832-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests: rtc: Support harness test filtering and arguments
2026-09-10 3:48 [PATCH] selftests: rtc: Support harness test filtering and arguments Wake Liu
@ 2026-09-10 3:53 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-10 3:53 UTC (permalink / raw)
To: Wake Liu; +Cc: Alexandre Belloni, linux-rtc
> rtctest implements its own main() function with a rigid switch (argc)
> check that only accepts an optional single argument for the RTC device
> node path. This prevents kselftest_harness standard arguments from
> working properly:
>
> 1. Passing filter options like -t <name> or -T <name> triggers a usage
> error because argc is greater than 2.
> 2. Passing -l or -h causes rtctest to treat "-l" or "-h" as the device
> node path and fail with access() errors before ever reaching the
> harness argument checker.
>
> Parse command line arguments with getopt() to pass all kselftest harness
> options (such as -t, -T, -v, -V, -f, -F, -r, -d, -h, and -l) through to
> test_harness_run(), while preserving the ability to specify an optional
> RTC device node path as a non-option argument. Also ensure optind is
> reset before invoking test_harness_run() so the harness can inspect the
> options, and bypass device accessibility checks when help or test
> listing is requested.
>
> Signed-off-by: Wake Liu <wakel@google.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910034821.2935214-1-wakel@google.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-10 3:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 3:48 [PATCH] selftests: rtc: Support harness test filtering and arguments Wake Liu
2026-09-10 3:53 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.