From: sashiko-bot@kernel.org
To: "Wake Liu" <wakel@google.com>
Cc: linux-rtc@vger.kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v2] selftests: rtc: Support harness test filtering and arguments
Date: Thu, 05 Nov 2026 03:15:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-198509@kernel.org> (raw)
In-Reply-To: <20261105030834.3318480-1-wakel@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests: rtc: incomplete getopt() reset on -h/-l in main()
--
commit 9bed5ee7eee853de78b5dce8eb5280f5ed1c8688
Author: Wake Liu <wakel@google.com>
selftests: rtc: Support harness test filtering and arguments
This commit updates main() in rtctest.c to parse command-line options with
getopt() so kselftest harness flags can be passed alongside the optional RTC
device node path.
> diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
> index 552191fe1ca09..eb26d957835d7 100644
> --- a/tools/testing/selftests/rtc/rtctest.c
> +++ b/tools/testing/selftests/rtc/rtctest.c
> @@ -487,18 +487,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);
[Severity: Medium]
What happens if -h or -l is passed as the first flag in a clustered short
option argument (such as -hd or -ld)?
When getopt() parses the first character in argv[1], optind is still 1 and
getopt()'s internal within-argument character cursor points to the second
character ('d'). Returning early from inside the getopt() loop after setting
optind = 1 does not reset that internal cursor when getopt() has not finished
consuming the current argument.
When main() calls test_harness_run() -> test_harness_argv_check():
tools/testing/selftests/kselftest_harness.h:test_harness_argv_check() {
...
while ((opt = getopt(argc, argv, "dhlF:f:V:v:t:T:r:")) != -1) {
switch (opt) {
...
case 'h':
test_harness_usage(argv[0]);
return KSFT_FAIL;
case 'l':
__test_harness_list_tests();
return KSFT_FAIL;
...
}
}
return KSFT_PASS;
}
getopt() in test_harness_argv_check() resumes at 'd' instead of re-reading
'h' or 'l', returns KSFT_PASS, and runs the full RTC test suite (while also
having bypassed the access(rtc_file, R_OK) check in main()).
Would it be better to let the getopt() loop finish scanning all options (for
example by recording a flag for -h/-l or resetting optind = 0 where supported)
before calling test_harness_run()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105030834.3318480-1-wakel@google.com?part=1
next prev parent reply other threads:[~2026-11-05 3:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 3:48 [PATCH] selftests: rtc: Support harness test filtering and arguments Wake Liu
2026-09-10 3:53 ` sashiko-bot
2026-09-21 19:31 ` Alexandre Belloni
2026-10-11 10:41 ` Wake Liu
2026-11-05 3:08 ` [PATCH v2] " Wake Liu
2026-11-05 3:15 ` sashiko-bot [this message]
2026-11-10 10:51 ` [PATCH v3] " Wake Liu
2026-11-10 10:55 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-198509@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-rtc@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wakel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.