From: Robin Murphy <robin.murphy@arm.com>
To: brendan.higgins@linux.dev, davidgow@google.com, corbet@lwn.net
Cc: rmoar@google.com, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-doc@vger.kernel.org,
workflows@vger.kernel.org
Subject: Re: [PATCH] Documentation: kunit: Fix kunit_device_register() example
Date: Thu, 16 Oct 2025 18:44:58 +0100 [thread overview]
Message-ID: <dbc6ec47-78a7-45bc-8df3-4f009731d302@arm.com> (raw)
In-Reply-To: <766a96de401a2c4361867144567bbc31edcf1a9e.1760535996.git.robin.murphy@arm.com>
On 2025-10-15 2:46 pm, Robin Murphy wrote:
> kunit_device_register() only returns error pointers, not NULL.
> Furthermore for regular users who aren't testing the KUnit API
> itself, errors most likely represent major system failure (e.g. OOM
> or sysfs collision) beyond the scope of their own test conditions.
> Replace the assert with straightforward error handling for clarity.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
> This seemed the logical conclusion by inspection, but please do correct
> me if I've misunderstood the intent...
> ---
> Documentation/dev-tools/kunit/usage.rst | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
> index 038f480074fd..3452c739dd44 100644
> --- a/Documentation/dev-tools/kunit/usage.rst
> +++ b/Documentation/dev-tools/kunit/usage.rst
> @@ -873,7 +873,8 @@ For example:
>
> // Create a fake device.
> fake_device = kunit_device_register(test, "my_device");
> - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fake_device)
> + if (IS_ERR(fake_device))
> + return;
On further consideration, I guess kunit_skip() (as used in various other
places) is actually what I want here?
Basically, as someone looking at KUnit with fresh eyes it seems
intuitive to me that not being able to run a test case is a not a
failure of the thing being tested, so shouldn't be reported as such, and
thus this example stood out. I for one wouldn't want to be getting CI
notifications to go and debug a "regression" in my code just because a
runner OOM'd, for example :)
Thanks,
Robin.
>
> // Pass it to functions which need a device.
> dev_managed_string = devm_kstrdup(fake_device, "Hello, World!");
next prev parent reply other threads:[~2025-10-16 17:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 13:46 Robin Murphy
2025-10-16 17:44 ` Robin Murphy [this message]
2025-10-17 5:28 ` David Gow
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=dbc6ec47-78a7-45bc-8df3-4f009731d302@arm.com \
--to=robin.murphy@arm.com \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rmoar@google.com \
--cc=workflows@vger.kernel.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