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

From: Brian Norris

Date: Fri Oct 02 2026 - 19:09:21 EST


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>
---

drivers/base/power/runtime-test.c | 101 ++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)

diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
index 24865ce844fc..4b507821912b 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,104 @@ 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);
+ u64 expiry1, expiry2;
+
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
+
+ put_device(dev->parent);
+ dev->parent = parent;
+ get_device(parent);
+
+ 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. */
+ msleep(1);
+
+ 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);
+ u64 expiry1, expiry2;
+
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+ 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. */
+ msleep(1);
+
+ 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 +392,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),
{}
};

--
2.56.0.rc1.315.gc6ed9934b7-goog