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

drm/tests: Add test cases for drm_rect_rotate()

Insert a parameterized test for the drm_rect_rotate() to ensure
correctness and prevent future regressions.

All possible rotation modes are covered by the test.

Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Maíra Canal <mairacanal@riseup.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20230418230146.461129-5-arthurgrillo@riseup.net

authored by

Arthur Grillo and committed by
Maíra Canal
b5d88ec0 881e2a9c

+72
+72
drivers/gpu/drm/tests/drm_rect_test.c
··· 8 8 #include <kunit/test.h> 9 9 10 10 #include <drm/drm_rect.h> 11 + #include <drm/drm_mode.h> 11 12 12 13 #include <linux/string_helpers.h> 13 14 #include <linux/errno.h> ··· 426 425 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); 427 426 } 428 427 428 + struct drm_rect_rotate_case { 429 + const char *name; 430 + unsigned int rotation; 431 + struct drm_rect rect; 432 + int width, height; 433 + struct drm_rect expected; 434 + }; 435 + 436 + static const struct drm_rect_rotate_case drm_rect_rotate_cases[] = { 437 + { 438 + .name = "reflect-x", 439 + .rotation = DRM_MODE_REFLECT_X, 440 + .rect = DRM_RECT_INIT(0, 0, 5, 5), 441 + .width = 5, .height = 10, 442 + .expected = DRM_RECT_INIT(0, 0, 5, 5), 443 + }, 444 + { 445 + .name = "reflect-y", 446 + .rotation = DRM_MODE_REFLECT_Y, 447 + .rect = DRM_RECT_INIT(2, 0, 5, 5), 448 + .width = 5, .height = 10, 449 + .expected = DRM_RECT_INIT(2, 5, 5, 5), 450 + }, 451 + { 452 + .name = "rotate-0", 453 + .rotation = DRM_MODE_ROTATE_0, 454 + .rect = DRM_RECT_INIT(0, 2, 5, 5), 455 + .width = 5, .height = 10, 456 + .expected = DRM_RECT_INIT(0, 2, 5, 5), 457 + }, 458 + { 459 + .name = "rotate-90", 460 + .rotation = DRM_MODE_ROTATE_90, 461 + .rect = DRM_RECT_INIT(0, 0, 5, 10), 462 + .width = 5, .height = 10, 463 + .expected = DRM_RECT_INIT(0, 0, 10, 5), 464 + }, 465 + { 466 + .name = "rotate-180", 467 + .rotation = DRM_MODE_ROTATE_180, 468 + .rect = DRM_RECT_INIT(11, 3, 5, 10), 469 + .width = 5, .height = 10, 470 + .expected = DRM_RECT_INIT(-11, -3, 5, 10), 471 + }, 472 + { 473 + .name = "rotate-270", 474 + .rotation = DRM_MODE_ROTATE_270, 475 + .rect = DRM_RECT_INIT(6, 3, 5, 10), 476 + .width = 5, .height = 10, 477 + .expected = DRM_RECT_INIT(-3, 6, 10, 5), 478 + }, 479 + }; 480 + 481 + static void drm_rect_rotate_case_desc(const struct drm_rect_rotate_case *t, char *desc) 482 + { 483 + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); 484 + } 485 + 486 + KUNIT_ARRAY_PARAM(drm_rect_rotate, drm_rect_rotate_cases, drm_rect_rotate_case_desc); 487 + 488 + static void drm_test_rect_rotate(struct kunit *test) 489 + { 490 + const struct drm_rect_rotate_case *params = test->param_value; 491 + struct drm_rect r = params->rect; 492 + 493 + drm_rect_rotate(&r, params->width, params->height, params->rotation); 494 + 495 + drm_rect_compare(test, &r, &params->expected); 496 + } 497 + 429 498 static struct kunit_case drm_rect_tests[] = { 430 499 KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), 431 500 KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), ··· 504 433 KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params), 505 434 KUNIT_CASE_PARAM(drm_test_rect_calc_hscale, drm_rect_scale_gen_params), 506 435 KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_scale_gen_params), 436 + KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params), 507 437 { } 508 438 }; 509 439