[PATCH 5/5] PM: runtime: Add test for pending-autosuspend + teardown
From: Brian Norris
Date: Tue Sep 29 2026 - 14:49:09 EST
Add a KUnit regression test for the behavior fixed by the previous patch
("PM: runtime: Synchronous suspend when updating autosuspend"). Note
that the old behavior was racy -- a pending RPM_REQ_AUTOSUSPEND *might*
quiesce, but it wasn't guaranteed. Now the behavior should be non-racy.
Example invocation:
$ ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_PM=y \
'pm_runtime*'
Signed-off-by: Brian Norris <briannorris@xxxxxxxxxxxx>
---
drivers/base/power/runtime-test.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
index 3487392e0afd..67d637550092 100644
--- a/drivers/base/power/runtime-test.c
+++ b/drivers/base/power/runtime-test.c
@@ -354,6 +354,32 @@ static void pm_runtime_autosuspend_rearm_test(struct kunit *test)
dev_set_drvdata(dev, NULL);
}
+static void pm_runtime_pending_teardown_test(struct kunit *test)
+{
+ struct device *dev = kunit_device_register(test, DEVICE_NAME);
+
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+ pm_runtime_enable(dev);
+ pm_runtime_use_autosuspend(dev);
+
+ KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
+
+ KUNIT_EXPECT_EQ(test, 0, pm_runtime_get_sync(dev));
+ KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
+
+ /* Queue a RPM_REQ_AUTOSUSPEND (immediately, as autosuspend_delay is 0) */
+ KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_autosuspend(dev));
+
+ /*
+ * This is expected to quiesce a pending auto-suspend. See especially
+ * devm_pm_runtime_enable() -> pm_runtime_disable_action().
+ */
+ pm_runtime_dont_use_autosuspend(dev);
+
+ KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
+}
+
static struct kunit_case pm_runtime_test_cases[] = {
KUNIT_CASE(pm_runtime_depth_test),
KUNIT_CASE(pm_runtime_already_suspended_test),
@@ -363,6 +389,7 @@ static struct kunit_case pm_runtime_test_cases[] = {
KUNIT_CASE(pm_runtime_probe_active_test),
KUNIT_CASE(pm_runtime_supplier_suspend_test),
KUNIT_CASE(pm_runtime_autosuspend_rearm_test),
+ KUNIT_CASE(pm_runtime_pending_teardown_test),
{}
};
--
2.56.0.rc1.315.gc6ed9934b7-goog