From: "David Matlack" <dmatlack@google.com>
To: "Aaron Lewis" <aaronlewis@google.com>, <kvm@vger.kernel.org>
Cc: <alex@shazbot.org>, <dmatlack@google.com>, <jgg@nvidia.com>,
"Kees Cook" <kees@kernel.org>,
"Andy Lutomirski" <luto@amacapital.net>,
"Will Drewry" <wad@chromium.org>, "Shuah Khan" <shuah@kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v4 4/5] selftests: harness: Support custom command-line options
Date: Wed, 25 Nov 2026 11:40:22 -0800 [thread overview]
Message-ID: <DN4JPCW1VT9K.1HWW8L3LMPE35@google.com> (raw)
In-Reply-To: <20261114132200.113697-5-aaronlewis@google.com>
On Sat Nov 14, 2026 at 5:21 AM PST, Aaron Lewis wrote:
> Also update test_enabled() to match exact option characters rather than
> tolower(opt) so custom options that differ only by case (such as 'R') do
> not mistakenly match built-in single-case options like '-r'.
Please also explain the has_positive change, since it's not obvious
from the diff. How about replacing this paragraph with something like:
Pass the full optstring (including custom options) to test_enabled()
so that getopt() correctly parses custom options that take an
argument. Since test_enabled() now sees custom options, only update
has_positive for the filter options (-t, -f, -v, -r). Otherwise a
lowercase custom option would be treated as a positive filter that
matches nothing, and every test would get filtered out. Similarly,
match exact option characters rather than tolower(opt) so that custom
options that differ only by case (such as -R) do not get treated as
built-in options (such as -r).
[...]
> +/**
> + * struct test_harness_cli_opts - Custom command-line options for test harness
> + * @optstring: getopt option string; must not conflict with harness options.
> + * @handler: Callback to handle custom options; returns KSFT_PASS or KSFT_FAIL.
> + * @help: Optional callback to print custom option help text.
> + */
> +struct test_harness_cli_opts {
> + const char *optstring;
> + int (*handler)(int opt, char *optarg);
> + void (*help)(void);
> +};
KSFT_PASS and KSFT_FAIL are test result codes, which seems like an odd
fit for a callback that handles a command-line option. Please follow the
usual kernel convention instead and have the handler return 0 on success
and non-zero on error, e.g. in test_harness_argv_check():
default:
if (opts && opts->handler && !opts->handler(opt, optarg))
break;
and in the next patch:
static int opts_handler(int opt, char *optarg)
{
if (opt == 'b') {
...
return 0;
}
return -EINVAL;
}
The @handler kernel-doc above will need to be updated to match.
Also, kselftest.rst explicitly lists which kernel-doc comments to pull
in from kselftest_harness.h, so this comment won't show up in the
rendered docs as-is. Please add kernel-doc for test_harness_run_opts()
too, and add both to the "Helpers" list in
Documentation/dev-tools/kselftest.rst so test authors can discover how
to add custom options.
[...]
> +#define OPTSTRING_LEN 128
kselftest_harness.h is included by a lot of tests, so please use a more
specific name (e.g. KSFT_OPTSTRING_LEN) to avoid clashing with something
a test defines, or hard-code it locally.
> +
> +static void optstring_append_custom(char *optstring, size_t size,
> + const struct test_harness_cli_opts *opts)
> +{
> + const char *c;
> +
> + if (!opts || !opts->optstring)
> + return;
> +
> + assert(strlen(optstring) + strlen(opts->optstring) < size);
> +
> + for (c = opts->optstring; *c; c++) {
> + if (isalnum(*c))
> + assert(!strchr(optstring, *c));
> + }
assert() compiles out if a test is built with -DNDEBUG, in which case
these checks silently disappear, and nothing else in kselftest_harness.h
uses assert(). Please follow what the harness already does for misuse
it detects at runtime (e.g. "Illegal usage of low-level ksft APIs in
harness test") and for bad command-line options: print an error with
ksft_print_msg() and fail. e.g. have optstring_append_custom() return an
error and test_harness_run_opts() return KSFT_FAIL, the same way it
handles a failure from test_harness_argv_check(). That also avoids
pulling <assert.h> into every test that includes the harness.
next prev parent reply other threads:[~2026-11-25 19:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261114132200.113697-1-aaronlewis@google.com>
2026-11-14 13:21 ` [PATCH v4 4/5] selftests: harness: Support custom command-line options Aaron Lewis
2026-11-25 19:40 ` David Matlack [this message]
2026-11-14 13:22 ` [PATCH v4 5/5] vfio: selftests: Allow a size for vfio_dma_mapping_perf_test Aaron Lewis
2026-11-25 19:56 ` David Matlack
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=DN4JPCW1VT9K.1HWW8L3LMPE35@google.com \
--to=dmatlack@google.com \
--cc=aaronlewis@google.com \
--cc=alex@shazbot.org \
--cc=jgg@nvidia.com \
--cc=kees@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=shuah@kernel.org \
--cc=wad@chromium.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