From: sashiko-bot@kernel.org
To: "Vaibhav Jain" <vaibhav@linux.ibm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] kunit: Add example of test suite that can be skipped at runtime
Date: Thu, 04 Jun 2026 16:42:43 +0000 [thread overview]
Message-ID: <20260604164243.7A2871F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604162805.556135-3-vaibhav@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The new example promotes a `suite_init` skip pattern that triggers multiple existing KUnit infrastructure bugs, leading to resource leaks and malformed KTAP output.
- [Low] Macro duck-typing API misuse: `kunit_mark_skipped()` is intended for `struct kunit *` but is passed a `struct kunit_suite *`.
--
commit bb04d5d94394b78bbd531471f54e3d41268deac5
Author: Vaibhav Jain <vaibhav@linux.ibm.com>
kunit: Add example of test suite that can be skipped at runtime
This patch adds an example test suite to kunit-example-test.c demonstrating
how to skip an entire test suite based on runtime conditions. It uses the
suite_init callback to mark the suite as skipped using kunit_mark_skipped().
> diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c
> index 0bae7b7ca0b05..b8ded54fa46d8 100644
> --- a/lib/kunit/kunit-example-test.c
> +++ b/lib/kunit/kunit-example-test.c
> @@ -591,5 +591,34 @@ static struct kunit_suite example_init_test_suite = {
> */
> kunit_test_init_section_suites(&example_init_test_suite);
>
[ ... ]
> +static int example_skip_suite_init(struct kunit_suite *suite)
> +{
> + kunit_mark_skipped(suite, "Test suite expected to be skipped");
[Severity: Medium]
Does this example promote a pattern that triggers underlying KUnit
infrastructure bugs?
The underlying framework bugs predate this patch, but promoting this pattern
could lead to resource leaks. In kunit_run_tests(), skipping a suite causes
it to completely bypass suite_exit():
lib/kunit/test.c:kunit_run_tests() {
...
} else if (suite->status == KUNIT_SKIPPED) {
/* Skip this kunit suite */
goto suite_end;
}
...
}
This contradicts the KUnit API documentation (which guarantees suite_exit
will run even if suite_init fails) and structurally guarantees a memory leak
if test authors follow this example and allocate resources prior to checking
the skip condition.
Additionally, skipping the suite here leads to malformed KTAP output because
debugfs_print_results() unconditionally prints the test plan without the
inner test results. It also permanently locks the suite in the skipped state
across debugfs re-runs because kunit_init_suite() fails to reset
suite->status back to KUNIT_SUCCESS.
[Severity: Low]
Is it safe to pass a struct kunit_suite pointer to kunit_mark_skipped()?
The kunit_mark_skipped() macro is designed and explicitly documented to
accept a struct kunit pointer (the individual test case context), rather
than a suite:
include/kunit/test.h:
#define kunit_mark_skipped(test, fmt, ...) \
do { \
WRITE_ONCE((test)->status, KUNIT_SKIPPED); \
This only compiles because both structs coincidentally share identically
named status and status_comment fields, relying on C macro structural
duck-typing.
If this macro is ever refactored into a type-safe inline function, this
example and any downstream code that copies it will fail to compile. Should
a proper type-safe API like kunit_suite_mark_skipped() be introduced instead?
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604162805.556135-1-vaibhav@linux.ibm.com?part=2
next prev parent reply other threads:[~2026-06-04 16:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 16:27 [PATCH 0/2] kunit: Add support for skipping entire test suites Vaibhav Jain
2026-06-04 16:28 ` [PATCH 1/2] kunit: Add ability to skip " Vaibhav Jain
2026-06-04 16:47 ` sashiko-bot
2026-06-05 5:09 ` David Gow
2026-06-08 9:04 ` Vaibhav Jain
2026-06-04 16:28 ` [PATCH 2/2] kunit: Add example of test suite that can be skipped at runtime Vaibhav Jain
2026-06-04 16:42 ` sashiko-bot [this message]
2026-06-05 5:10 ` David Gow
2026-06-08 8:41 ` Vaibhav Jain
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=20260604164243.7A2871F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vaibhav@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox