From: Philipp Zabel <p.zabel@pengutronix.de>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] reset: Add KUnit test cases
Date: Tue, 03 Nov 2026 11:21:53 +0100 [thread overview]
Message-ID: <48d7459fc34adac1ac614e79d9930902345759d2.camel@pengutronix.de> (raw)
In-Reply-To: <20261102155207.19252-1-tzungbi@kernel.org>
On Mo, 2026-11-02 at 23:52 +0800, Tzung-Bi Shih wrote:
> Since commit 9035073d0ef1 ("reset: convert reset core to using firmware
> nodes"), reset suppliers and consumers can be wired up using software
> nodes without requiring Device Tree or hardware devices. Leverage this
> to add KUnit test cases for the reset controller framework.
>
> The test cases cover the following scenarios:
>
> - Basic: Verifies that a consumer can acquire a reset control via
> fwnode and perform reset, assert, deassert, status, release, and
> acquire operations.
> - Use After Unregister: Verifies that after the supplier unregisters
> the reset_controller_dev while a consumer still holds a reset_control
> handle, subsequent consumer operations fail safely with -ENODEV.
> - Concurrent Unregister: Verifies that unregistering the
> reset_controller_dev concurrently with an in-flight reset operation
> waits for the active operation to complete before returning.
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> ---
> Test:
> $ ./tools/testing/kunit/kunit.py run \
> --kconfig_add CONFIG_RESET_CONTROLLER=y \
> --kconfig_add CONFIG_RESET_KUNIT_TEST=y \
> reset_test
> ---
> v2:
> - Separate out from the revocable series.
> - Add reset_test_exit() to clean up rstc and rcdev on test exit or
> assertion failure.
> - Clean up kthreads on error paths in reset_test_concurrent_unregister().
>
> v1: https://lore.kernel.org/all/20261011121246.162759-5-tzungbi@kernel.org
> ---
> drivers/reset/Kconfig | 5 +
> drivers/reset/Makefile | 2 +
> drivers/reset/core-test.c | 351 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 358 insertions(+)
> create mode 100644 drivers/reset/core-test.c
>
[...]
> diff --git a/drivers/reset/core-test.c b/drivers/reset/core-test.c
> new file mode 100644
> index 000000000000..613db78040c6
> --- /dev/null
> +++ b/drivers/reset/core-test.c
> @@ -0,0 +1,351 @@
[...]
> +static void reset_test_concurrent_unregister(struct kunit *test)
> +{
> + struct reset_test_context *rtc = test->priv;
> + struct test_concurrent_unregister_context *ctx;
> + int i, ret, val;
> +
> + rtc->rcdev.ops = &reset_test_concurrent_unregister_ops;
> +
> + ctx = kunit_kmalloc_array(test, 3, sizeof(*ctx), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, ctx);
> +
> + for (i = 0; i < 3; ++i) {
> + ctx[i].test = test;
> + init_completion(&ctx[i].started);
> + init_completion(&ctx[i].enter);
> +
> + if (i == 0) {
> + ctx[i].thread = kthread_run(
> + test_concurrent_unregister_supplier, ctx + i,
> + "supplier%d", i);
> + } else {
> + init_completion(&ctx[i].entered);
> + init_completion(&ctx[i].exit);
> +
> + ctx[i].thread = kthread_run(
> + test_concurrent_unregister_consumer, ctx + i,
> + "consumer%d", i);
> + }
> + if (IS_ERR(ctx[i].thread)) {
> + ret = PTR_ERR(ctx[i].thread);
> + while (i--)
> + kthread_stop_put(ctx[i].thread);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> + }
> + get_task_struct(ctx[i].thread);
> +
> + wait_for_completion(&ctx[i].started);
> + }
> +
> + rtc->priv = &ctx[1];
> + ctx[1].expected_ret = 0x12345678;
> + /* consumer1 enters reset(). */
> + KUNIT_EXPECT_EQ(test, rtc->reset_count, 0);
> + complete(&ctx[1].enter);
> + wait_for_completion(&ctx[1].entered);
> + KUNIT_EXPECT_EQ(test, rtc->reset_count, 1);
> +
> + /* supplier0 unregisters. */
> + complete(&ctx[0].enter);
> + ret = read_poll_timeout(reset_control_status, val, val == -ENODEV,
> + 1000, 100000, false, rtc->rstc);
> + if (ret) {
> + for (i = 2; i >= 0; --i)
> + kthread_stop_put(ctx[i].thread);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> + }
> + /* supplier0 can't exit. It's waiting for all consumers. */
This comment looks like an untested assertion. For all we know,
reset_controller_unregister() may have already returned by now.
How about signalling a completion "ctx->exited" after
reset_controller_unregister() returns, calling
wait_for_completion_timeout() here, and asserting it times out?
regards
Philipp
prev parent reply other threads:[~2026-11-03 10:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 15:52 Tzung-Bi Shih
2026-11-03 10:21 ` Philipp Zabel [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=48d7459fc34adac1ac614e79d9930902345759d2.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tzungbi@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
all inboxes | Powered by JetHome®