Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2980358lqo; Tue, 21 May 2024 03:16:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJiEZCuqoOmZz7vfD2bG3ITFTSTz+GfhQcNb+ZYGzyKM6iOB5RVDzAB7bUTe8IiSx+DL+7kzLtsf58ZmPfivXiBET1mM0Ria2NXFv9ew== X-Google-Smtp-Source: AGHT+IHEMd+krKkvIiSkd9z4PJzO2TzT5SRzIN3tzuXbVA+8Bi+rdvxfrjPlAYesrMmFoez7fiLX X-Received: by 2002:a05:6870:d69c:b0:23b:f2d0:7b9c with SMTP id 586e51a60fabf-24172bdf92fmr35007048fac.24.1716286605046; Tue, 21 May 2024 03:16:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716286605; cv=pass; d=google.com; s=arc-20160816; b=VDFFdQvbrueXmbbndqa2RcgXgHaDKb+7xs9ckwKw5cwa+aueFVaTJgJltg5XbEMghz HlJOIbCYmpPlaBKlW0UdWp+m3U++C5DeAIqXKd6bIncQbBvbcfBL31QuyC0FsThiUnhd R/TN0KWoqqTttLrUasZKFyl17Y7ChPecVvCalwilR+wg2aPwUxlEX4dDifV5Fk+66DKn C4OrZTC6hzwUe+VaJHxnkc52hPM9JFvycxcFmVjT4/wuVsSkvr+JrkASOA9fd2JHolmn rgj4wsnVG47e0w7vVZSueOoTlWt7FKYZHjq+y7JS1PTRuHR09CLqFtNTEYis+7Wg82u6 3BCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Qvenv3VH+GfTiBZ9pQFYZ/9xmn3Olb/5mcAVSgst7TM=; fh=ufmwd8Wo0DI+kdMOJWC7ZXqsyLxoMBbO0En/E/GApYU=; b=CI0X1lGB76bKQVW1DcpeP1yzd5R2iF0GNV2x2jaj/PBHUOxN8M9PHhEUpOx3Ep9pmD rbNvBVCO7bfHp4L99Ucq0areR4DC2auDe5Dsb/KnX9PhFZFJnGo+ETpPP9c0hWPr36O9 ETHXQaey4BeRjgL/aZUFi83mmsTtYu7+XzXQnGtywzGTQc0kX6Xrabq7Wje0vH7PbP1G YNooKC5Yv61WQXu6Ezt3WeIggBKE2Gdw04StQ0eV641zk72Jt5ygnDmos4+5prZGnJAq /SlPWzFBBYGTFrjy0fD5rg22xnA+LWviuPI7NA/oVqQk0TAWiQtDHz5QJMhdFFohI0CP 4G2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LechKFBg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-65a8da4ad03si1139977a12.641.2024.05.21.03.16.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 03:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LechKFBg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 30CD6B22725 for ; Tue, 21 May 2024 10:16:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45AA477F32; Tue, 21 May 2024 10:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LechKFBg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F8237710C; Tue, 21 May 2024 10:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716286455; cv=none; b=Yo3GGEvEWThSgfnm67ykPDXYcI9TU9rrkZ4UBPKsEnddfw7Yzusp2yyc6ZhHn/hZuPqrzO8krE0EOEBmDKaUGUWTCMwH2htEkkn4AT3L/eEqRDGB7wgirYRd5h1ZDFxn665Mmdv9Ig+6z+TkXfpCSMnGES3HhfDY0DHC4GqkrA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716286455; c=relaxed/simple; bh=3hc6xccJubKkqL1r2eJQXdXTnAar50Miht9H8iOUArE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o8kuvfVDMZ8NSZ4QEig3wZLSiHIAcRuhI5I+G9/lQV9mb8KzC2Iyx17sFvIw26d+GHVmACzTRjjY56zWyLOofNg5gRHdnGyT/uPyPvYi3AQ7+NSNfWidFWr0yXrTy2tTLFoud2c6/CAxfIqaTghuuMWQNre2ZL7vUPP/Jz18TaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LechKFBg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F349C2BD11; Tue, 21 May 2024 10:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716286454; bh=3hc6xccJubKkqL1r2eJQXdXTnAar50Miht9H8iOUArE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LechKFBgu0tD6wBCQ7iMCxIAk1P0r9L1w/JHs0PYmvOzvMkHk7wC7vkIHJj2VZltz yPEuPb2pQo26isuqI2HSYQT1mC5lqyFPoINdYA+Tm3s2PTDyV40MZgjZgrUolcS0yw fv9xKKN2c1h1feEv8V9Gv19hMP8omWrP8LDaQt359PGcQBrkqPOka9ZPTuwdmhdSHn f1fmdsioJ2S6uhKxlh6FPwfmxWCmgM7oTNwSQ+Hcdf/rziQxKm1LD7u+xbW+6zbmmz D/TleH7YIKk6OGOenY5WYfqrHoySZhoJ+LE83ZHDy8Nmd+BlbLPpLEdymhziHSImX4 hhQc+2w43WJMg== From: Maxime Ripard Date: Tue, 21 May 2024 12:13:41 +0200 Subject: [PATCH v14 08/28] drm/tests: Add output formats tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240521-kms-hdmi-connector-state-v14-8-51950db4fedb@kernel.org> References: <20240521-kms-hdmi-connector-state-v14-0-51950db4fedb@kernel.org> In-Reply-To: <20240521-kms-hdmi-connector-state-v14-0-51950db4fedb@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andy Yan Cc: Hans Verkuil , Sebastian Wick , =?utf-8?q?Ville_Syrj=C3=A4l=C3=A4?= , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard , Dave Stevenson X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8024; i=mripard@kernel.org; h=from:subject:message-id; bh=3hc6xccJubKkqL1r2eJQXdXTnAar50Miht9H8iOUArE=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGk+xZeLuNZddy6zY2z/tevA0f3p73cq/LTlXcZ39/zpP LGOhvsXO6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEcooYGxaEMTuy9d9blPB0 +sxVXxp3BL6U9f/rtz18mde0tEfGcRwCt2P0yk9H71/64oMrh5xeLGN9PotcHJ8a78kcjtBgFgv JtgdMz37ZreTbFTxp1sOct3xxl0zmpTl3cDxs0PvyYA9f3VsA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_connector_test.c | 99 +++++++++++++++++++++- drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 32 +++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c index 9589867bdf7c..72f22ec951d6 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -346,10 +346,46 @@ static void drm_test_connector_hdmi_init_bpc_12(struct kunit *test) prop = priv->drm.mode_config.hdr_output_metadata_property; KUNIT_ASSERT_NOT_NULL(test, prop); KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); } +/* + * Test that the registration of an HDMI connector with no supported + * format fails. + */ +static void drm_test_connector_hdmi_init_formats_empty(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc, + 0, + 8); + KUNIT_EXPECT_LT(test, ret, 0); +} + +/* + * Test that the registration of an HDMI connector not listing RGB as a + * supported format fails. + */ +static void drm_test_connector_hdmi_init_formats_no_rgb(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc, + BIT(HDMI_COLORSPACE_YUV422), + 8); + KUNIT_EXPECT_LT(test, ret, 0); +} + /* * Test that the registration of an HDMI connector with an HDMI * connector type succeeds. */ static void drm_test_connector_hdmi_init_type_valid(struct kunit *test) @@ -431,10 +467,12 @@ static struct kunit_case drmm_connector_hdmi_init_tests[] = { KUNIT_CASE(drm_test_connector_hdmi_init_bpc_8), KUNIT_CASE(drm_test_connector_hdmi_init_bpc_10), KUNIT_CASE(drm_test_connector_hdmi_init_bpc_12), KUNIT_CASE(drm_test_connector_hdmi_init_bpc_invalid), KUNIT_CASE(drm_test_connector_hdmi_init_bpc_null), + KUNIT_CASE(drm_test_connector_hdmi_init_formats_empty), + KUNIT_CASE(drm_test_connector_hdmi_init_formats_no_rgb), KUNIT_CASE(drm_test_connector_hdmi_init_null_ddc), KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_valid, drm_connector_hdmi_init_type_valid_gen_params), KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_invalid, drm_connector_hdmi_init_type_invalid_gen_params), @@ -508,13 +546,72 @@ static struct kunit_case drm_get_tv_mode_from_name_tests[] = { static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { .name = "drm_get_tv_mode_from_name", .test_cases = drm_get_tv_mode_from_name_tests, }; +struct drm_hdmi_connector_get_output_format_name_test { + unsigned int kind; + const char *expected_name; +}; + +#define OUTPUT_FORMAT_TEST(_kind, _name) \ + { \ + .kind = _kind, \ + .expected_name = _name, \ + } + +static void drm_test_drm_hdmi_connector_get_output_format_name(struct kunit *test) +{ + const struct drm_hdmi_connector_get_output_format_name_test *params = + test->param_value; + + KUNIT_EXPECT_STREQ(test, + drm_hdmi_connector_get_output_format_name(params->kind), + params->expected_name); +} + +static const +struct drm_hdmi_connector_get_output_format_name_test +drm_hdmi_connector_get_output_format_name_valid_tests[] = { + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_RGB, "RGB"), + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV420, "YUV 4:2:0"), + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV422, "YUV 4:2:2"), + OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV444, "YUV 4:4:4"), +}; + +static void +drm_hdmi_connector_get_output_format_name_valid_desc(const struct drm_hdmi_connector_get_output_format_name_test *t, + char *desc) +{ + sprintf(desc, "%s", t->expected_name); +} + +KUNIT_ARRAY_PARAM(drm_hdmi_connector_get_output_format_name_valid, + drm_hdmi_connector_get_output_format_name_valid_tests, + drm_hdmi_connector_get_output_format_name_valid_desc); + +static void drm_test_drm_hdmi_connector_get_output_format_name_invalid(struct kunit *test) +{ + KUNIT_EXPECT_NULL(test, drm_hdmi_connector_get_output_format_name(4)); +}; + +static struct kunit_case drm_hdmi_connector_get_output_format_name_tests[] = { + KUNIT_CASE_PARAM(drm_test_drm_hdmi_connector_get_output_format_name, + drm_hdmi_connector_get_output_format_name_valid_gen_params), + KUNIT_CASE(drm_test_drm_hdmi_connector_get_output_format_name_invalid), + { } +}; + +static struct kunit_suite drm_hdmi_connector_get_output_format_name_test_suite = { + .name = "drm_hdmi_connector_get_output_format_name", + .test_cases = drm_hdmi_connector_get_output_format_name_tests, +}; + kunit_test_suites( &drmm_connector_hdmi_init_test_suite, &drmm_connector_init_test_suite, - &drm_get_tv_mode_from_name_test_suite + &drm_get_tv_mode_from_name_test_suite, + &drm_hdmi_connector_get_output_format_name_test_suite ); MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); 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 333c81b8cf4f..8bc1f9b0b12b 100644 --- a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +++ b/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c @@ -347,10 +347,19 @@ static void drm_test_check_output_bpc_crtc_mode_not_changed(struct kunit *test) } static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = { KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed), KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed), + /* + * TODO: We should have tests to check that a change in the + * format triggers a CRTC mode change just like we do for the + * RGB Quantization and BPC. + * + * However, we don't have any way to control which format gets + * picked up aside from changing the BPC or mode which would + * already trigger a mode change. + */ { } }; static struct kunit_suite drm_atomic_helper_connector_hdmi_check_test_suite = { .name = "drm_atomic_helper_connector_hdmi_check", @@ -427,14 +436,37 @@ static void drm_test_check_bpc_12_value(struct kunit *test) KUNIT_EXPECT_EQ(test, conn_state->max_bpc, 12); KUNIT_EXPECT_EQ(test, conn_state->max_requested_bpc, 12); KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0); } +/* + * Test that the value of the output format property out of reset is set + * to RGB, even if the driver supports more than that. + */ +static void drm_test_check_format_value(struct kunit *test) +{ + struct drm_atomic_helper_connector_hdmi_priv *priv; + struct drm_connector_state *conn_state; + struct drm_connector *conn; + + priv = drm_atomic_helper_connector_hdmi_init(test, + BIT(HDMI_COLORSPACE_RGB) | + BIT(HDMI_COLORSPACE_YUV422) | + BIT(HDMI_COLORSPACE_YUV444), + 8); + KUNIT_ASSERT_NOT_NULL(test, priv); + + conn = &priv->connector; + conn_state = conn->state; + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB); +} + static struct kunit_case drm_atomic_helper_connector_hdmi_reset_tests[] = { KUNIT_CASE(drm_test_check_bpc_8_value), KUNIT_CASE(drm_test_check_bpc_10_value), KUNIT_CASE(drm_test_check_bpc_12_value), + KUNIT_CASE(drm_test_check_format_value), { } }; static struct kunit_suite drm_atomic_helper_connector_hdmi_reset_test_suite = { .name = "drm_atomic_helper_connector_hdmi_reset", -- 2.45.0