Skip to content

Commit c2668a0

Browse files
author
Philipp Stanner
committed
drm/sched/tests: Add unit test for cancel_job()
The scheduler unit tests now provide a new callback, cancel_job(). This callback gets used by drm_sched_fini() for all still pending jobs to cancel them. Implement a new unit test to test this. Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Signed-off-by: Philipp Stanner <phasta@kernel.org> Link: https://lore.kernel.org/r/20250710125412.128476-6-phasta@kernel.org
1 parent 4576de9 commit c2668a0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

drivers/gpu/drm/scheduler/tests/tests_basic.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,47 @@ static struct kunit_suite drm_sched_basic = {
204204
.test_cases = drm_sched_basic_tests,
205205
};
206206

207+
static void drm_sched_basic_cancel(struct kunit *test)
208+
{
209+
struct drm_mock_sched_entity *entity;
210+
struct drm_mock_scheduler *sched;
211+
struct drm_mock_sched_job *job;
212+
bool done;
213+
214+
/*
215+
* Check that drm_sched_fini() uses the cancel_job() callback to cancel
216+
* jobs that are still pending.
217+
*/
218+
219+
sched = drm_mock_sched_new(test, MAX_SCHEDULE_TIMEOUT);
220+
entity = drm_mock_sched_entity_new(test, DRM_SCHED_PRIORITY_NORMAL,
221+
sched);
222+
223+
job = drm_mock_sched_job_new(test, entity);
224+
225+
drm_mock_sched_job_submit(job);
226+
227+
done = drm_mock_sched_job_wait_scheduled(job, HZ);
228+
KUNIT_ASSERT_TRUE(test, done);
229+
230+
drm_mock_sched_entity_free(entity);
231+
drm_mock_sched_fini(sched);
232+
233+
KUNIT_ASSERT_EQ(test, job->hw_fence.error, -ECANCELED);
234+
}
235+
236+
static struct kunit_case drm_sched_cancel_tests[] = {
237+
KUNIT_CASE(drm_sched_basic_cancel),
238+
{}
239+
};
240+
241+
static struct kunit_suite drm_sched_cancel = {
242+
.name = "drm_sched_basic_cancel_tests",
243+
.init = drm_sched_basic_init,
244+
.exit = drm_sched_basic_exit,
245+
.test_cases = drm_sched_cancel_tests,
246+
};
247+
207248
static void drm_sched_basic_timeout(struct kunit *test)
208249
{
209250
struct drm_mock_scheduler *sched = test->priv;
@@ -471,6 +512,7 @@ static struct kunit_suite drm_sched_credits = {
471512

472513
kunit_test_suites(&drm_sched_basic,
473514
&drm_sched_timeout,
515+
&drm_sched_cancel,
474516
&drm_sched_priority,
475517
&drm_sched_modify_sched,
476518
&drm_sched_credits);

0 commit comments

Comments
 (0)