mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wake Liu <wakel@google.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	linux-rtc@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Wake Liu <wakel@google.com>
Subject: [PATCH v3] selftests: rtc: Support harness test filtering and arguments
Date: Tue, 10 Nov 2026 10:51:58 +0000	[thread overview]
Message-ID: <20261110105158.975652-1-wakel@google.com> (raw)
In-Reply-To: <20261105030834.3318480-1-wakel@google.com>

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. Only reset optind once
all options have been parsed, so the harness re-parses them from a clean
getopt() state, and bypass device accessibility checks when help or test
listing is requested.

Signed-off-by: Wake Liu <wakel@google.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
v3:
- Don't call test_harness_run() from inside the getopt() loop for -h
  and -l. getopt() keeps its position inside grouped options, so with
  e.g. "-ld" the harness resumed at 'd', missed -l/-h and ran the whole
  suite without the device check. Record -h/-l instead and reset optind
  only after all options have been parsed. Reported by Sashiko AI
  review.
- Kept Alexandre's Acked-by as the change is limited to the -h/-l
  handling. Alexandre, please let me know if you'd rather re-check.

v2: https://lore.kernel.org/all/20261105030834.3318480-1-wakel@google.com/
- Rebased onto v7.4-rc1, no code changes.
- Added Alexandre's Acked-by.

v1: https://lore.kernel.org/all/20260910034821.2935214-1-wakel@google.com/

Alexandre, if you're still fine with it, could you queue this via the
RTC tree along with the other rtctest changes? Shuah, please let me know
if you would rather take it via kselftest.

 tools/testing/selftests/rtc/rtctest.c | 54 ++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
index 552191fe1ca0..21c37764f9d3 100644
--- a/tools/testing/selftests/rtc/rtctest.c
+++ b/tools/testing/selftests/rtc/rtctest.c
@@ -487,18 +487,54 @@ 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;
+	bool skip_dev_check = false;
+
+	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]);
+			skip_dev_check = true;
+			break;
+		case 'l':
+			skip_dev_check = true;
+			break;
+		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;
+		}
 	}
 
+	/*
+	 * Rewind getopt() so test_harness_run() can parse the options again.
+	 * Only do this after the loop above has consumed every option, as
+	 * getopt() keeps its position within grouped options (e.g. "-ld").
+	 */
+	optind = 1;
+
+	/* -h and -l are handled by the harness and need no RTC device */
+	if (skip_dev_check)
+		return test_harness_run(argc, argv);
+
 	/* Run the test if rtc_file is accessible */
 	if (access(rtc_file, R_OK) == 0)
 		ret = test_harness_run(argc, argv);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.56.0.542.g3ef89b7020-goog


      reply	other threads:[~2026-11-10 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  3:48 [PATCH] " Wake Liu
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-10 10:51   ` Wake Liu [this message]

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=20261110105158.975652-1-wakel@google.com \
    --to=wakel@google.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®