Re: [PATCH v2] drm/sched: Create a fake device for KUnit tests

From: Philipp Stanner

Date: Fri Sep 04 2026 - 03:25:50 EST


On Thu, 2026-09-03 at 20:15 +0800, oushixiong1025@xxxxxxx wrote:
>

[…]

> +
>  #include "sched_tests.h"
>  
>  /*
> @@ -288,6 +290,7 @@ static const struct drm_sched_backend_ops drm_mock_scheduler_ops = {
>   */
>  struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout)
>  {
> + static unsigned int instance;

I know statics are initialized to 0 automatically, but writing it out
explicitly is probably advantageous for readability, especially since
we're incrementing.

>   struct drm_sched_init_args args = {
>   .ops = &drm_mock_scheduler_ops,
>   .num_rqs = DRM_SCHED_PRIORITY_COUNT,
> @@ -297,11 +300,19 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout)
>   .name = "drm-mock-scheduler",
>   };
>   struct drm_mock_scheduler *sched;
> + struct device *dev;
> + char name[64];
>   int ret;
>  
>   sched = kunit_kzalloc(test, sizeof(*sched), GFP_KERNEL);
>   KUNIT_ASSERT_NOT_NULL(test, sched);
>  
> + snprintf(name, sizeof(name), "%s-%u", args.name, ++instance);

Any particular reason why you begin with index 1?