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

Configure Feed

Select the types of activity you want to include in your feed.

drm/tests: Add output formats tests

Now that we track the HDMI output format as part of the connector state,
let's add a few tests to make sure it works as expected.

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-8-c5af16c3aae2@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>

+130 -1
+98 -1
drivers/gpu/drm/tests/drm_connector_test.c
··· 364 364 } 365 365 366 366 /* 367 + * Test that the registration of an HDMI connector with no supported 368 + * format fails. 369 + */ 370 + static void drm_test_connector_hdmi_init_formats_empty(struct kunit *test) 371 + { 372 + struct drm_connector_init_priv *priv = test->priv; 373 + int ret; 374 + 375 + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, 376 + &dummy_funcs, 377 + DRM_MODE_CONNECTOR_HDMIA, 378 + &priv->ddc, 379 + 0, 380 + 8); 381 + KUNIT_EXPECT_LT(test, ret, 0); 382 + } 383 + 384 + /* 385 + * Test that the registration of an HDMI connector not listing RGB as a 386 + * supported format fails. 387 + */ 388 + static void drm_test_connector_hdmi_init_formats_no_rgb(struct kunit *test) 389 + { 390 + struct drm_connector_init_priv *priv = test->priv; 391 + int ret; 392 + 393 + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, 394 + &dummy_funcs, 395 + DRM_MODE_CONNECTOR_HDMIA, 396 + &priv->ddc, 397 + BIT(HDMI_COLORSPACE_YUV422), 398 + 8); 399 + KUNIT_EXPECT_LT(test, ret, 0); 400 + } 401 + 402 + /* 367 403 * Test that the registration of an HDMI connector with an HDMI 368 404 * connector type succeeds. 369 405 */ ··· 484 448 KUNIT_CASE(drm_test_connector_hdmi_init_bpc_12), 485 449 KUNIT_CASE(drm_test_connector_hdmi_init_bpc_invalid), 486 450 KUNIT_CASE(drm_test_connector_hdmi_init_bpc_null), 451 + KUNIT_CASE(drm_test_connector_hdmi_init_formats_empty), 452 + KUNIT_CASE(drm_test_connector_hdmi_init_formats_no_rgb), 487 453 KUNIT_CASE(drm_test_connector_hdmi_init_null_ddc), 488 454 KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_valid, 489 455 drm_connector_hdmi_init_type_valid_gen_params), ··· 563 525 .test_cases = drm_get_tv_mode_from_name_tests, 564 526 }; 565 527 528 + struct drm_hdmi_connector_get_output_format_name_test { 529 + unsigned int kind; 530 + const char *expected_name; 531 + }; 532 + 533 + #define OUTPUT_FORMAT_TEST(_kind, _name) \ 534 + { \ 535 + .kind = _kind, \ 536 + .expected_name = _name, \ 537 + } 538 + 539 + static void drm_test_drm_hdmi_connector_get_output_format_name(struct kunit *test) 540 + { 541 + const struct drm_hdmi_connector_get_output_format_name_test *params = 542 + test->param_value; 543 + 544 + KUNIT_EXPECT_STREQ(test, 545 + drm_hdmi_connector_get_output_format_name(params->kind), 546 + params->expected_name); 547 + } 548 + 549 + static const 550 + struct drm_hdmi_connector_get_output_format_name_test 551 + drm_hdmi_connector_get_output_format_name_valid_tests[] = { 552 + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_RGB, "RGB"), 553 + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV420, "YUV 4:2:0"), 554 + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV422, "YUV 4:2:2"), 555 + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV444, "YUV 4:4:4"), 556 + }; 557 + 558 + static void 559 + drm_hdmi_connector_get_output_format_name_valid_desc(const struct drm_hdmi_connector_get_output_format_name_test *t, 560 + char *desc) 561 + { 562 + sprintf(desc, "%s", t->expected_name); 563 + } 564 + 565 + KUNIT_ARRAY_PARAM(drm_hdmi_connector_get_output_format_name_valid, 566 + drm_hdmi_connector_get_output_format_name_valid_tests, 567 + drm_hdmi_connector_get_output_format_name_valid_desc); 568 + 569 + static void drm_test_drm_hdmi_connector_get_output_format_name_invalid(struct kunit *test) 570 + { 571 + KUNIT_EXPECT_NULL(test, drm_hdmi_connector_get_output_format_name(4)); 572 + }; 573 + 574 + static struct kunit_case drm_hdmi_connector_get_output_format_name_tests[] = { 575 + KUNIT_CASE_PARAM(drm_test_drm_hdmi_connector_get_output_format_name, 576 + drm_hdmi_connector_get_output_format_name_valid_gen_params), 577 + KUNIT_CASE(drm_test_drm_hdmi_connector_get_output_format_name_invalid), 578 + { } 579 + }; 580 + 581 + static struct kunit_suite drm_hdmi_connector_get_output_format_name_test_suite = { 582 + .name = "drm_hdmi_connector_get_output_format_name", 583 + .test_cases = drm_hdmi_connector_get_output_format_name_tests, 584 + }; 585 + 566 586 kunit_test_suites( 567 587 &drmm_connector_hdmi_init_test_suite, 568 588 &drmm_connector_init_test_suite, 569 - &drm_get_tv_mode_from_name_test_suite 589 + &drm_get_tv_mode_from_name_test_suite, 590 + &drm_hdmi_connector_get_output_format_name_test_suite 570 591 ); 571 592 572 593 MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
+32
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
··· 349 349 static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = { 350 350 KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed), 351 351 KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed), 352 + /* 353 + * TODO: We should have tests to check that a change in the 354 + * format triggers a CRTC mode change just like we do for the 355 + * RGB Quantization and BPC. 356 + * 357 + * However, we don't have any way to control which format gets 358 + * picked up aside from changing the BPC or mode which would 359 + * already trigger a mode change. 360 + */ 352 361 { } 353 362 }; 354 363 ··· 438 429 KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0); 439 430 } 440 431 432 + /* 433 + * Test that the value of the output format property out of reset is set 434 + * to RGB, even if the driver supports more than that. 435 + */ 436 + static void drm_test_check_format_value(struct kunit *test) 437 + { 438 + struct drm_atomic_helper_connector_hdmi_priv *priv; 439 + struct drm_connector_state *conn_state; 440 + struct drm_connector *conn; 441 + 442 + priv = drm_atomic_helper_connector_hdmi_init(test, 443 + BIT(HDMI_COLORSPACE_RGB) | 444 + BIT(HDMI_COLORSPACE_YUV422) | 445 + BIT(HDMI_COLORSPACE_YUV444), 446 + 8); 447 + KUNIT_ASSERT_NOT_NULL(test, priv); 448 + 449 + conn = &priv->connector; 450 + conn_state = conn->state; 451 + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB); 452 + } 453 + 441 454 static struct kunit_case drm_atomic_helper_connector_hdmi_reset_tests[] = { 442 455 KUNIT_CASE(drm_test_check_bpc_8_value), 443 456 KUNIT_CASE(drm_test_check_bpc_10_value), 444 457 KUNIT_CASE(drm_test_check_bpc_12_value), 458 + KUNIT_CASE(drm_test_check_format_value), 445 459 { } 446 460 }; 447 461