Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/tests: Split drm_framebuffer_create_test into parameterized tests

The igt_check_drm_framebuffer_create is based on a loop that executes
tests for all createbuffer_tests test cases. This could be better
represented by parameterized tests, provided by KUnit.

So, convert the igt_check_drm_framebuffer_create into parameterized tests.

Signed-off-by: Maíra Canal <mairacanal@riseup.net>
Reviewed-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220911191756.203118-1-mairacanal@riseup.net

+31 -24
+31 -24
drivers/gpu/drm/tests/drm_framebuffer_test.c
··· 25 25 const char *name; 26 26 }; 27 27 28 - static struct drm_framebuffer_test createbuffer_tests[] = { 28 + static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { 29 29 { .buffer_created = 1, .name = "ABGR8888 normal sizes", 30 30 .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_ABGR8888, 31 31 .handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 }, ··· 330 330 .fb_create = fb_create_mock, 331 331 }; 332 332 333 - static struct drm_device mock_drm_device = { 334 - .mode_config = { 335 - .min_width = MIN_WIDTH, 336 - .max_width = MAX_WIDTH, 337 - .min_height = MIN_HEIGHT, 338 - .max_height = MAX_HEIGHT, 339 - .funcs = &mock_config_funcs, 340 - }, 341 - }; 342 - 343 - static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r) 333 + static int drm_framebuffer_test_init(struct kunit *test) 344 334 { 335 + struct drm_device *mock; 336 + 337 + mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); 338 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); 339 + 340 + mock->mode_config.min_width = MIN_WIDTH; 341 + mock->mode_config.max_width = MAX_WIDTH; 342 + mock->mode_config.min_height = MIN_HEIGHT; 343 + mock->mode_config.max_height = MAX_HEIGHT; 344 + mock->mode_config.funcs = &mock_config_funcs; 345 + 346 + test->priv = mock; 347 + return 0; 348 + } 349 + 350 + static void drm_test_framebuffer_create(struct kunit *test) 351 + { 352 + const struct drm_framebuffer_test *params = test->param_value; 353 + struct drm_device *mock = test->priv; 345 354 int buffer_created = 0; 346 355 347 - mock_drm_device.dev_private = &buffer_created; 348 - drm_internal_framebuffer_create(&mock_drm_device, r, NULL); 349 - return buffer_created; 356 + mock->dev_private = &buffer_created; 357 + drm_internal_framebuffer_create(mock, &params->cmd, NULL); 358 + KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); 350 359 } 351 360 352 - static void igt_check_drm_framebuffer_create(struct kunit *test) 361 + static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, char *desc) 353 362 { 354 - int i = 0; 355 - 356 - for (i = 0; i < ARRAY_SIZE(createbuffer_tests); i++) { 357 - KUNIT_EXPECT_EQ_MSG(test, createbuffer_tests[i].buffer_created, 358 - execute_drm_mode_fb_cmd2(&createbuffer_tests[i].cmd), 359 - "Test %d: \"%s\" failed\n", i, createbuffer_tests[i].name); 360 - } 363 + strcpy(desc, t->name); 361 364 } 365 + 366 + KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, 367 + drm_framebuffer_test_to_desc); 362 368 363 369 static struct kunit_case drm_framebuffer_tests[] = { 364 - KUNIT_CASE(igt_check_drm_framebuffer_create), 370 + KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), 365 371 { } 366 372 }; 367 373 368 374 static struct kunit_suite drm_framebuffer_test_suite = { 369 375 .name = "drm_framebuffer", 376 + .init = drm_framebuffer_test_init, 370 377 .test_cases = drm_framebuffer_tests, 371 378 }; 372 379