From patchwork Mon Feb 12 13:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 199758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2420715dyd; Mon, 12 Feb 2024 05:19:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYkaXWUeKCdM7iXiSMFlAafST/Kf8ff4s7oQCxnO0HPJoZXHCrCVtpkU3yneJjhJ0Of2px X-Received: by 2002:a05:6a21:1789:b0:19f:c0d3:43d8 with SMTP id nx9-20020a056a21178900b0019fc0d343d8mr2104998pzb.11.1707743949256; Mon, 12 Feb 2024 05:19:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707743949; cv=pass; d=google.com; s=arc-20160816; b=zgGGwoVar+CbsUXtklWRjmvLP/qiGc0BHAHgOQ42j4n9qgwevvjZXKy4Zki1jgSnUg y4q+GoGHc10zSlpcWdMMjjOla3cI9Mdm6Xsl0/SdqP4i7iR9ExoXlKzIjEZXRTtNhbkk 7cL785eryZN1h8/nUlY4EtU3t2s3aCjcBliaUhg9YA9313XNvfcBzNyZtzUFEibYt9Ik xzAc4/tO+ykJixceru/5xXmqt3omS0w1UyG6imzBoAy/d6xmodMf/5pnR1/47x2kBAXx g3sJkuyzbHsiE3ht3fl//AGunv4Cn3wf7d5ARqmBCHQfPReLmIxjEpVglM1JwoqRgYLm i3qw== 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=29OHmR7rJlcZ6xJfRikNnYFtl8Oa6/u/uDVm2p6QEe4=; fh=EraIltnAIBOubH0JRY8AMR/LUnAQzXv4sREX6SXzTS8=; b=qMpAS0Po8On9rXTqR62QYlehYevZgEdz1Ru56iLGrlVMLg2aXlCk3BMFWno6pvGvqi 22DdWCpYIwtF9xrQ0XhGoAGDT+84dt7aUAla66zwmVMkzNdjmjsRYlPdHE5N5wv3qPmZ 4AnIRPWrnqqm36L3/ZjLy+j+UZq91Z516NUS9sgQmGLuMadb6hvRiHgN4EaBCIz4xt8r usV/aYDPVgqDrOlxzC4lb4bQxohs+6UZnWOfEGRqz61oQzjWovjE6YGdxJ/WdcrJtk+O /FhTSR6fJzYrMxUrrOk4wI9fcuMZDUUsE3lOF3WKHhU+1MBCnr1dzxXYB/ocYBHO/RKk BE/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nnYMWO6u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61630-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61630-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWptzelpivyMuX6PFJbywywZnllgmmfaNBjcy9FDASZdkOw8XWpzadBZO2gXRLtI/D75uNoj+KkdkS/FH71Bbx5SRoKGQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x37-20020a056a0018a500b006e04369998fsi5055874pfh.15.2024.02.12.05.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:19:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61630-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nnYMWO6u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61630-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61630-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0605E28144A for ; Mon, 12 Feb 2024 13:19:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BDC33F9EF; Mon, 12 Feb 2024 13:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nnYMWO6u" 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 264583F8C3; Mon, 12 Feb 2024 13:14:13 +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=1707743654; cv=none; b=K2SAse1d8hhrQVs+hbx6P2+KWa6kPwVc0EQD1sE01XVfkTXI/yrFN0mOWz1Jg6BGmPLv0yz9enEaaUZ0XvwBvF0/mplVZhWts8hAYOi9ETaJKohExyf5T1pVRpKVSrIUO44+MuC1CRDKn8iWuZplLGXWTyPkujN7c522TDPDzlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743654; c=relaxed/simple; bh=hVvd4FnVrnc0ueFHR5k8VbMr8WUIf39Lt6E/xNOlkQA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qFON4Brin5T9FpMk38rTwwVTq+lOY0lQCtAuv/Ad2sQfgdJLBXKHhmCNNc5uPySPnXaFRtrYHmXctZXVnLXLOA4V0+y6l5jFf13BAGCyRST3DZnxI6lsOxy4LVpfOUszCUPS4fH5eaj5wZw6l0hUaLMbtHzXWgiQ2w+dkh3mtjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnYMWO6u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 511F0C433B1; Mon, 12 Feb 2024 13:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707743653; bh=hVvd4FnVrnc0ueFHR5k8VbMr8WUIf39Lt6E/xNOlkQA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nnYMWO6uMryz6GAC5/40GnLMZ6rY49rA8EJBub3YBhEt40DtA6HD6cofH4S9bXciq DjsDi//2V/UDwFvGYklqLJIYCRW3Jljr3mouNccB56EGamos5Dbzqc+pGi/gIxUcx/ jGGXQyvdTqAJMkTbhepo1FDE5U6FPzY7FZUKifJUn5La+NDHPdMsLbZAyudgmmglNZ gCe9QiSqmPCaoxkTbNeZAQBpeClQr0TyW6IV2jR7HtjpiHWL80S/HsczOGP+QJ+wiX 5YrTUYMlOHaPTZSAoYosui6nY3M5dzirCsBY0PeOhhuZvDRDtWRtsaaUcZgs/8+b83 OQ1TL6/uQyEww== From: Maxime Ripard Date: Mon, 12 Feb 2024 14:12:59 +0100 Subject: [PATCH v6 16/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: <20240212-kms-hdmi-connector-state-v6-16-f4bcdc979e6f@kernel.org> References: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> In-Reply-To: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , 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=7427; i=mripard@kernel.org; h=from:subject:message-id; bh=hVvd4FnVrnc0ueFHR5k8VbMr8WUIf39Lt6E/xNOlkQA=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmnJDNC2fp7UnK4ui+c1DrWdjlZgCU8wH1uBPPvXqYnk cs5LJ93lLAwiHExyIopssQImy+JOzXrdScb3zyYOaxMIEMYuDgFYCIRuxh+3OKQVOhfcFc7oVGz p70iS9JeZeeq18LvD1/VfqTpNH8WI8ND3w6/YO4Sucfyy3VXOLa2anR4373YIH3w+8aO4osvmbk A X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790699318921437103 X-GMAIL-MSGID: 1790699318921437103 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 a5cba3e63f99..4e2ec436987b 100644 --- a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c +++ b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c @@ -824,6 +824,15 @@ static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = { KUNIT_CASE(drm_test_check_broadcast_rgb_crtc_mode_not_changed), 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. + */ { } }; @@ -924,11 +933,34 @@ 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_broadcast_rgb_value), 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 9c5ce7e81d01..fa6fe8084107 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), @@ -567,6 +605,64 @@ static struct kunit_suite drm_hdmi_connector_get_broadcast_rgb_name_test_suite = .test_cases = drm_hdmi_connector_get_broadcast_rgb_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, +}; + static void drm_test_drm_connector_attach_broadcast_rgb_property(struct kunit *test) { struct drm_connector_init_priv *priv = test->priv; @@ -628,7 +724,8 @@ kunit_test_suites( &drmm_connector_init_test_suite, &drm_connector_attach_broadcast_rgb_property_test_suite, &drm_get_tv_mode_from_name_test_suite, - &drm_hdmi_connector_get_broadcast_rgb_name_test_suite + &drm_hdmi_connector_get_broadcast_rgb_name_test_suite, + &drm_hdmi_connector_get_output_format_name_test_suite ); MODULE_AUTHOR("Maxime Ripard ");