Provide test to verify a forced fallback to YUV420 output cannot succeed
when driver doesn't advertise YUV420 support.

Signed-off-by: Cristian Ciocaltea <cristian.ciocal...@collabora.com>
---
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

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 
99bedb2d6f555b3b140256000dfa7491d2a8f515..c2976b42aa2aacd2a68a871bffe97e795ca713d4
 100644
--- a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
@@ -1493,6 +1493,51 @@ static void 
drm_test_check_max_tmds_rate_format_fallback_yuv420(struct kunit *te
        drm_modeset_acquire_fini(&ctx);
 }
 
+/*
+ * Test that if a driver supports only RGB, but the chosen mode can be
+ * supported by the screen only in YUV420 output format, we end up with
+ * an unsuccessful forced fallback attempt.
+ */
+static void drm_test_check_driver_unsupported_fallback_yuv420(struct kunit 
*test)
+{
+       struct drm_atomic_helper_connector_hdmi_priv *priv;
+       struct drm_modeset_acquire_ctx ctx;
+       struct drm_display_info *info;
+       struct drm_display_mode *yuv420_only_mode;
+       struct drm_connector *conn;
+       struct drm_device *drm;
+       struct drm_crtc *crtc;
+       int ret;
+
+       priv = drm_kunit_helper_connector_hdmi_init_with_edid(test,
+                               BIT(HDMI_COLORSPACE_RGB),
+                               12,
+                               
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;
+       info = &conn->display_info;
+       KUNIT_ASSERT_TRUE(test, info->is_hdmi);
+       KUNIT_ASSERT_FALSE(test, conn->ycbcr_420_allowed);
+
+       yuv420_only_mode = drm_kunit_display_mode_from_cea_vic(test, drm, 95);
+       KUNIT_ASSERT_NOT_NULL(test, yuv420_only_mode);
+       KUNIT_ASSERT_TRUE(test, drm_mode_is_420_only(info, yuv420_only_mode));
+
+       drm_modeset_acquire_init(&ctx, 0);
+
+       ret = drm_kunit_helper_enable_crtc_connector(test, drm,
+                                                    crtc, conn,
+                                                    yuv420_only_mode,
+                                                    &ctx);
+       KUNIT_EXPECT_LT(test, ret, 0);
+
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
+}
+
 /*
  * Test that if a driver and screen supports RGB and YUV formats, and we
  * try to set the VIC 1 mode, we end up with 8bpc RGB even if we could
@@ -1884,6 +1929,7 @@ static struct kunit_case 
drm_atomic_helper_connector_hdmi_check_tests[] = {
        KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_yuv420),
        KUNIT_CASE(drm_test_check_max_tmds_rate_format_fallback_yuv422),
        KUNIT_CASE(drm_test_check_max_tmds_rate_format_fallback_yuv420),
+       KUNIT_CASE(drm_test_check_driver_unsupported_fallback_yuv420),
        KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed),
        KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed),
        KUNIT_CASE(drm_test_check_output_bpc_dvi),

-- 
2.49.0

Reply via email to