diff mbox series

[v6,2/6] drm/sched: Add aspirational unit test mode

Message ID 20250310161516.39942-3-tvrtko.ursulin@igalia.com (mailing list archive)
State New
Headers show
Series DRM scheduler kunit tests | expand

Commit Message

Tvrtko Ursulin March 10, 2025, 4:15 p.m. UTC
Aspirational unit test mode can be activated via
CONFIG_DRM_SCHED_KUNIT_TEST_ASPIRATIONAL and will test the scheduler not
against the criteria of how it is implemented today, but according to the
future design goals and agreements.

First example of this is the scheduler cleanup flow which currently can
leak jobs from drivers which fail to implement own tear down of in-flight
submissions.

The test which can demonstrate this is
drm_sched_basic_entity_cleanup which, based on this kconfig, will skip the
mock scheduler specific cleanup and instead rely on drm_sched_fini to idle
and free everything. That will not currently happen and therefore
drm_mock_sched_fini will assert on test exit.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Suggested-by: Philipp Stanner <phasta@kernel.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <phasta@kernel.org>
---
 drivers/gpu/drm/Kconfig.debug                    | 13 +++++++++++++
 drivers/gpu/drm/scheduler/tests/mock_scheduler.c | 10 ++++++++++
 2 files changed, 23 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/Kconfig.debug b/drivers/gpu/drm/Kconfig.debug
index 6fd4c5669400..e98ff556e4c4 100644
--- a/drivers/gpu/drm/Kconfig.debug
+++ b/drivers/gpu/drm/Kconfig.debug
@@ -111,5 +111,18 @@  config DRM_SCHED_KUNIT_TEST
 
 	  If in doubt, say "N".
 
+config DRM_SCHED_KUNIT_TEST_ASPIRATIONAL
+	bool "Aspirational mode for DRM scheduler unit tests" if !KUNIT_ALL_TESTS
+	depends on DRM && KUNIT && DRM_SCHED_KUNIT_TEST
+	default n
+	help
+	  Choose this option to make the DRM scheduler unit tests test for
+	  behaviour which was agreed as a design goal, even if the current
+	  implementation can make specific tests fail.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".
+
 config DRM_EXPORT_FOR_TESTS
 	bool
diff --git a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
index b7d4890a1651..69b963b619d5 100644
--- a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
+++ b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
@@ -261,9 +261,13 @@  struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test)
 void drm_mock_sched_fini(struct drm_mock_scheduler *sched)
 {
 	struct drm_mock_sched_job *job, *next;
+	struct kunit  *test = sched->test;
 	unsigned long flags;
 	LIST_HEAD(signal);
 
+	if (IS_ENABLED(CONFIG_DRM_SCHED_KUNIT_TEST_ASPIRATIONAL))
+		goto sched_fini;
+
 	drm_sched_wqueue_stop(&sched->base);
 
 	spin_lock_irqsave(&sched->lock, flags);
@@ -278,7 +282,13 @@  void drm_mock_sched_fini(struct drm_mock_scheduler *sched)
 		drm_sched_job_cleanup(&job->base);
 	}
 
+sched_fini:
 	drm_sched_fini(&sched->base);
+
+	if (IS_ENABLED(CONFIG_DRM_SCHED_KUNIT_TEST_ASPIRATIONAL)) {
+		KUNIT_ASSERT_TRUE(test, list_empty(&sched->job_list));
+		KUNIT_ASSERT_TRUE(test, list_empty(&sched->base.pending_list));
+	}
 }
 
 /**