From patchwork Thu Feb 22 18:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp131181dyb; Thu, 22 Feb 2024 10:31:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX7a+jkDIhC/2dds3rqdTdWmBJ1XfQsl9YNPBioMXLN1p9Gy2lrM6vW5mU7VuxOtdIBLRTQhQGOhhND+HNppjkYvLctZQ== X-Google-Smtp-Source: AGHT+IG5/sNRhyVbSfCpQlclt5u9ND3g/7JfiDH1iVNNPRKKCb7XArf6DVY4Wh7Q/Hntm7+5yDAH X-Received: by 2002:a05:6358:d26:b0:17b:570c:7eb7 with SMTP id v38-20020a0563580d2600b0017b570c7eb7mr7695803rwj.11.1708626702965; Thu, 22 Feb 2024 10:31:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626702; cv=pass; d=google.com; s=arc-20160816; b=MyeU9knPNRvuQwewdDEaTVcEAjvfTFp6K0DOrWW6m0XEPyXGUz/wDaGepR33t02lex kJeemR9qAnfGKjujqUQiqfxyC60K4btIfyQuBCuqBlzaDYpArWJYQfu8ZFNbGcTBd8lB ckhStpWnBiUKKsW9zHj1wRLRZEX0L26OMdzBGXpgWnsYUxs0WyKGLWTd7mbFqiHFNsls 2Qudlf4qGBR4ez7wXkbfnX7hY4v7PzfpSPlidz4goOaLam+HGWNnsOemIg9HB7nRCbLv 03W0BnPhVDu3j8AYcJc9ZKmGgAeMarT8rGh+CBBtP+/FYQJk3VK+94FK6iwm9ftY0Dqf hHkw== 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=gujZOU2pwvxo+dyJ8DOtVEZvw7pjQXhi2g7E92ndXhw=; fh=8wcoxKk21hICD+6obVirG13fsSSMhKa/pufykSf87d0=; b=v+kIUMXs4EOYiaMCkab4oiv/MTzZ5zX6qHDmnoBx8CIRt9p8Hu+MAHu/ThUJMhoOen KanRoXzvgW80cnS0YtvD5LHMZi2MJHLzcTi2RdZjXRemoSXRd0vPRA5emwc36ANWJxY0 3lG+2IX68mjQqk8B7T/r1RRSKeorxjhuHQAANs9csF1Br5SjwkbV+yp4vokt1fhuwddV Zgt24FjtTSfDgIvrdnnfwV1lFXjT9ARoZw41dIKyssGY+QLbhE66UGugD0M+cOGaDYcJ TsXb8I1AHOeqQNyrbPk3Mwf4vTniMN1A4wTALZ4jT3eZo+2ogUZQ6iNnwuPMO1cDQHbx 9Yjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o3rLDusK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77089-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77089-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fk1-20020a056a003a8100b006e476b6392bsi6039604pfb.287.2024.02.22.10.31.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:31:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77089-ouuuleilei=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=o3rLDusK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77089-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77089-ouuuleilei=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 471E9B250F2 for ; Thu, 22 Feb 2024 18:23:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB727137914; Thu, 22 Feb 2024 18:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o3rLDusK" 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 94E7B73F1C; Thu, 22 Feb 2024 18:15:02 +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=1708625702; cv=none; b=uOr+oQhASNwiOMrgmrzc/XzTH3J3NDcHx1m1Si0EUO+IVR94I3QVAogChsP5XK6+zEAhKL9mzNl0dY2ac6a91sEuDLfCP5dqMlO0BpaDisZszrL5BJ7oxQ5ROlWJL6b8ypreAZj1MSPrdGxisQAFeFgtIynr2IeVrQlD6E1ZDNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625702; c=relaxed/simple; bh=35dEQopjUt6A2W23PQkFev/rOQ1owYxpUGVppcAXPW8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S31slbDrtuqPvPwpnvS+8x5zD/CoWFVczkdZX1GT8+Y+mv6ltXr3U6CMxsa+xFABQgElK8ZTQHk3Mgrk2AOGNfAh3Tz2/jgU48mt/daN9jCRlnPwWhh5699TRYukFuKFC3pi6ycz/NT1QcchJhN5PiMzpIugl2HSkDgGbYBnKNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o3rLDusK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 179C3C433F1; Thu, 22 Feb 2024 18:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625702; bh=35dEQopjUt6A2W23PQkFev/rOQ1owYxpUGVppcAXPW8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=o3rLDusK1Vw0bjrO7qrIF4iJhbGDg6FozAm37wlI3AQmiuDM+fhZG/H0OLsrCBKpf tZA618Fds6vgfNxYnNBDhULGM98xbvKCbsrEoiHHPH4Psu2/yuFiGyHfKGYW9l0+Xi pqnFHKUjnMpSXxjmJvoQH2VebiaDN14iL0B+WFogkGHkJakkD+6/r/w3UNok18r3fH UeFsZN6/NVvbJQmK85+UspdD4daU35QqqkxLOhi6EvVgW6xPTXi+KM0A1ysI0QOcyK XJfXQFHlOZkgW30Oh0xK6oUZIEAEedT8hknOjurXc/f37ynF3QnJx5HK0yvz9DTqiP 4AL66vAYjgGlQ== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:13:58 +0100 Subject: [PATCH v7 12/36] 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 Message-Id: <20240222-kms-hdmi-connector-state-v7-12-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@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 Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , 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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7105; i=mripard@kernel.org; h=from:subject:message-id; bh=35dEQopjUt6A2W23PQkFev/rOQ1owYxpUGVppcAXPW8=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+z7oCuXVxn849X/rxa/77958NnPOD/nqxveX/rdzT JhzlP/D7Y5SFgYxLgZZMUWWGGHzJXGnZr3uZOObBzOHlQlkCAMXpwBMxN6A4Q+HQc3NaV4KAbWT w5Vk1c73LdwVVnXsfX6T3oxXzj3FTGUM//NzLl42vJhwqpdTTsq1kHF/cxnbKhPtwu5LCpF8Iq/ kGQE= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624954018095485 X-GMAIL-MSGID: 1791624954018095485 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 --- .../gpu/drm/tests/drm_atomic_state_helper_test.c | 32 +++++++ drivers/gpu/drm/tests/drm_connector_test.c | 99 +++++++++++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c index a129ea5f014c..1c3dd8a98fb0 100644 --- a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c +++ b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c @@ -347,6 +347,15 @@ 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. + */ { } }; @@ -427,10 +436,33 @@ static void drm_test_check_bpc_12_value(struct kunit *test) 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), { } }; diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c index a9a57cb23235..5bff67fbed87 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -348,6 +348,42 @@ static void drm_test_connector_hdmi_init_bpc_12(struct kunit *test) 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. @@ -433,6 +469,8 @@ static struct kunit_case drmm_connector_hdmi_init_tests[] = { 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), @@ -510,10 +548,69 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { .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 ");