Re: [PATCH v2 6/7] drm/tests: hdmi: Add limited range tests for YUV420 mode

Maxime Ripard
2025-03-11T16:17:11Z

[-- Attachment #1: Type: text/plain, Size: 4538 bytes --]

On Tue, Mar 11, 2025 at 12:57:38PM +0200, Cristian Ciocaltea wrote:
> Provide tests to verify that drm_atomic_helper_connector_hdmi_check()
> helper behaviour when using YUV420 output format is to always set the
> limited RGB quantization range to 'limited', no matter what the value of
> Broadcast RGB property is.
>
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> ---
> drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 89 +++++++++++++++-
> drivers/gpu/drm/tests/drm_kunit_edid.h | 112 +++++++++++++++++++++
> 2 files changed, 196 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c b/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
> index a3f7f3ce31c73335c2c2643bdc5395b6ceb6f071..1df12c0b7768e4f85f4c943840d9b4dcb6e079e0 100644
> --- a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
> @@ -227,6 +227,8 @@ connector_hdmi_init_funcs_set_edid(struct kunit *test,
> enc->possible_crtcs = drm_crtc_mask(priv->crtc);
>
> conn = &priv->connector;
> + conn->ycbcr_420_allowed = !!(formats & BIT(HDMI_COLORSPACE_YUV420));
> +
> ret = drmm_connector_hdmi_init(drm, conn,
> "Vendor", "Product",
> &dummy_connector_funcs,
> @@ -751,6 +753,86 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode_vic_1(struct kunit *te
> drm_modeset_acquire_fini(&ctx);
> }
>
> +/*
> + * Test that for an HDMI connector, with an HDMI monitor, we will
> + * get a limited RGB Quantization Range with a YUV420 mode, no
> + * matter what the value of the Broadcast RGB property is set to.
> + */
> +static void drm_test_check_broadcast_rgb_cea_mode_yuv420(struct kunit *test)
> +{
> + struct drm_atomic_helper_connector_hdmi_priv *priv;
> + enum drm_hdmi_broadcast_rgb broadcast_rgb;
> + struct drm_modeset_acquire_ctx ctx;
> + struct drm_connector_state *conn_state;
> + struct drm_atomic_state *state;
> + struct drm_display_mode *mode;
> + struct drm_connector *conn;
> + struct drm_device *drm;
> + struct drm_crtc *crtc;
> + int ret;
> +
> + broadcast_rgb = *(enum drm_hdmi_broadcast_rgb *)test->param_value;
> +
> + priv = drm_kunit_helper_connector_hdmi_init_set_edid(test,
> + BIT(HDMI_COLORSPACE_RGB) |
> + BIT(HDMI_COLORSPACE_YUV420),
> + 8,
> + test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
> + KUNIT_ASSERT_NOT_NULL(test, priv);
> +
> + drm = &priv->drm;
> + crtc = priv->crtc;
> + conn = &priv->connector;
> + KUNIT_ASSERT_TRUE(test, conn->display_info.is_hdmi);
> +
> + mode = drm_kunit_display_mode_from_cea_vic(test, drm, 95);
> + KUNIT_ASSERT_NOT_NULL(test, mode);
> +
> + drm_modeset_acquire_init(&ctx, 0);
> +
> + ret = light_up_connector(test, drm, crtc, conn, mode, &ctx);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
> +
> + conn_state = drm_atomic_get_connector_state(state, conn);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state);
> +
> + conn_state->hdmi.broadcast_rgb = broadcast_rgb;
> +
> + ret = drm_atomic_check_only(state);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + conn_state = drm_atomic_get_connector_state(state, conn);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, conn_state);
> +
> + KUNIT_ASSERT_EQ(test, conn_state->hdmi.broadcast_rgb, broadcast_rgb);
> + KUNIT_ASSERT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_YUV420);
> +
> + KUNIT_EXPECT_TRUE(test, conn_state->hdmi.is_limited_range);
> +
> + drm_modeset_drop_locks(&ctx);
> + drm_modeset_acquire_fini(&ctx);
> +}
> +
> +static const enum drm_hdmi_broadcast_rgb check_broadcast_rgb_cea_mode_yuv420_tests[] = {
> + DRM_HDMI_BROADCAST_RGB_AUTO,
> + DRM_HDMI_BROADCAST_RGB_FULL,
> + DRM_HDMI_BROADCAST_RGB_LIMITED,
> +};
> +
> +static void
> +check_broadcast_rgb_cea_mode_yuv420_desc(const enum drm_hdmi_broadcast_rgb *broadcast_rgb,
> + char *desc)
> +{
> + sprintf(desc, "%s", drm_hdmi_connector_get_broadcast_rgb_name(*broadcast_rgb));
> +}
> +
> +KUNIT_ARRAY_PARAM(check_broadcast_rgb_cea_mode_yuv420,
> + check_broadcast_rgb_cea_mode_yuv420_tests,
> + check_broadcast_rgb_cea_mode_yuv420_desc);
> +

We need more tests than that to test the various combinations, whether
the fallback to YUV420 should work or not depending on the EDID, the
driver capabilities, YUV420-only vs YUV420-also, etc.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]