Re: [PATCH v2 4/5] PM: runtime: Add tests for last_busy propagation

From: Jonathan Cameron

Date: Tue Nov 03 2026 - 18:21:43 EST


On Tue, 3 Nov 2026 14:14:42 -0800
Brian Norris <briannorris@xxxxxxxxxxxx> wrote:

> This is a regression test for the problem fixed in "PM: runtime:
> Propagate last_busy from dependent to dependency".
>
> Signed-off-by: Brian Norris <briannorris@xxxxxxxxxxxx>

Trivial style stuff.

> ---
>
> Changes in v2:
> * Use device_move() instead of manual re-parenting
> * fsleep() instead of msleep()
>
> drivers/base/power/runtime-test.c | 99 +++++++++++++++++++++++++++++++
> 1 file changed, 99 insertions(+)
>
> diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
> index 24865ce844fc..00ca3b10543a 100644
> --- a/drivers/base/power/runtime-test.c
> +++ b/drivers/base/power/runtime-test.c
> @@ -4,6 +4,7 @@
> */
>
> #include <linux/cleanup.h>
> +#include <linux/delay.h>
> #include <linux/pm_runtime.h>
> #include <linux/workqueue.h>
> #include <kunit/device.h>
> @@ -285,6 +286,102 @@ static void pm_runtime_supplier_suspend_test(struct kunit *test)
> KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(norpm_supplier));
> }
>
> +static void pm_runtime_parent_last_used_test(struct kunit *test)
> +{
> + struct device *parent = kunit_device_register(test, DEVICE_NAME "_parent");
> + struct device *dev = kunit_device_register(test, DEVICE_NAME);

Similar style comment to below.

> + u64 expiry1, expiry2;
> +
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
> +
> + KUNIT_ASSERT_EQ(test, 0, device_move(dev, parent, DPM_ORDER_NONE));
> +
> + pm_runtime_set_active(parent);
> + pm_runtime_set_active(dev);
> + pm_runtime_use_autosuspend(parent);
> + pm_runtime_use_autosuspend(dev);
> +
> + pm_runtime_set_autosuspend_delay(dev, 0);
> + /* Effectively infinite delay (prevent finishing autosuspend during this test). */
> + pm_runtime_set_autosuspend_delay(parent, 200000);
> +
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_mark_last_busy(parent);
> +
> + pm_runtime_get_noresume(dev);
> +
> + pm_runtime_enable(parent);
> + pm_runtime_enable(dev);
> +
> + expiry1 = pm_runtime_autosuspend_expiration(parent);
> + KUNIT_EXPECT_NE(test, 0, expiry1);
> +
> + /* Make absolutely sure the clock advances. */
> + fsleep(1000);
> +
> + KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync_autosuspend(dev));
> +
> + KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
> +
> + /* Flush, in case any request was pending. */
> + flush_workqueue(pm_wq);
> + KUNIT_EXPECT_FALSE(test, pm_runtime_suspended(parent));
> +
> + expiry2 = pm_runtime_autosuspend_expiration(parent);
> + KUNIT_EXPECT_NE(test, 0, expiry2);
> + /* The child's last_busy time should have bumped up the parent's expiration. */
> + KUNIT_EXPECT_GT(test, expiry2, expiry1);
> +}
> +
> +static void pm_runtime_supplier_last_used_test(struct kunit *test)
> +{
> + struct device *supplier = kunit_device_register(test, DEVICE_NAME "_supplier");
> + struct device *dev = kunit_device_register(test, DEVICE_NAME);
Having the assignment clear of the error check is never great, but now there are multiple
devs, I'd definitely move them.

struct device *supplier, *dev;

> + u64 expiry1, expiry2;
> +
supplier = kunit_device_register(test, DEVICE_NAME "_supplier");
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);

dev = kunit_device_register(test, DEVICE_NAME);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, supplier);

> +
> + KUNIT_ASSERT_NOT_NULL(test, device_link_add(dev, supplier, DL_FLAG_PM_RUNTIME));
> +
> + pm_runtime_set_active(supplier);
> + pm_runtime_set_active(dev);
> + pm_runtime_use_autosuspend(supplier);
> + pm_runtime_use_autosuspend(dev);
> +
> + pm_runtime_set_autosuspend_delay(dev, 0);
> + /* Effectively infinite delay (prevent finishing autosuspend during this test). */
> + pm_runtime_set_autosuspend_delay(supplier, 200000);
> +
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_mark_last_busy(supplier);
> +
> + pm_runtime_get_noresume(dev);
> +
> + pm_runtime_enable(supplier);
> + pm_runtime_enable(dev);
> +
> + expiry1 = pm_runtime_autosuspend_expiration(supplier);
> + KUNIT_EXPECT_NE(test, 0, expiry1);
> +
> + /* Make absolutely sure the clock advances. */
> + fsleep(1000);
> +
> + KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync_autosuspend(dev));
> +
> + KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
> +
> + /* Flush, in case any request was pending. */
> + flush_workqueue(pm_wq);
> + KUNIT_EXPECT_FALSE(test, pm_runtime_suspended(supplier));
> +
> + expiry2 = pm_runtime_autosuspend_expiration(supplier);
> + KUNIT_EXPECT_NE(test, 0, expiry2);
> + /* The consumer's last_busy time should have bumped up the supplier's expiration. */
> + KUNIT_EXPECT_GT(test, expiry2, expiry1);
> +}
> +
> static struct kunit_case pm_runtime_test_cases[] = {
> KUNIT_CASE(pm_runtime_depth_test),
> KUNIT_CASE(pm_runtime_already_suspended_test),
> @@ -293,6 +390,8 @@ static struct kunit_case pm_runtime_test_cases[] = {
> KUNIT_CASE(pm_runtime_error_test),
> KUNIT_CASE(pm_runtime_probe_active_test),
> KUNIT_CASE(pm_runtime_supplier_suspend_test),
> + KUNIT_CASE(pm_runtime_parent_last_used_test),
> + KUNIT_CASE(pm_runtime_supplier_last_used_test),
> {}
> };
>