From patchwork Thu Sep 29 16:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12994438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62D4FC433F5 for ; Thu, 29 Sep 2022 16:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8/46T/I6EDIP8iImNdrktE6nhCr4uBYvkF6m+b+67uQ=; b=17twz3DKyCp1K/ YDIc5h+cKcoeO/nSPla0HdhBcxBCsPXJu3yHJ0bSlccDnNeKvWPZYGh2CimSWFv5qWRiUMEP6v09L 6ngxQc2YsgdZAVqd9qRm1PZ6ocF9nb4rYcrYKF99hA/XACV4gJRKF/gspYfuvN2WlLYu3yVDrxq9v A7tWP7DGNzEBERlg198PgmRTN/glaOBFgDSAaNaPHsMQ3tsgPTgT2ZyKMr1fWuAqs9UZT5CRBp+dU jApViKWkz+TCn0JOClOYj85wiNl7lG8HBOSXHQUFQOZMZnYauoW7rpGD3fBNcCQuiX1Eo7bmJrVjT ytHb8o2uDq6f4vuqyy7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1odwcE-004H4o-TW; Thu, 29 Sep 2022 16:42:27 +0000 Received: from new4-smtp.messagingengine.com ([66.111.4.230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1odwRq-004Bza-M9 for linux-arm-kernel@lists.infradead.org; Thu, 29 Sep 2022 16:31:45 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id F18CB580804; Thu, 29 Sep 2022 12:31:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 29 Sep 2022 12:31:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1664469101; x= 1664476301; bh=fXgOJN1LW1amnuPPnCvibAr43dTYe2jjNHrV/PnQNmU=; b=X NtuRRSz3cJ+jd/pOsX3B7ZLpBKkexM2x5PSgVl/VBWgGM7vL0gMrvnc8bypoXSqN f7L4XtRqva0r9QK1q53DfXnIqhaEYmxbqJ69xOv40o+luqedSsQTDdUyct9b2Ae9 cnLFWZTDt3VkUGIMfpcZx2V2Mts/spvvfmioxO7H40f9uK1BxK/okKHxs5cWUDbs s82S4NXYh4k1T7HyuDSU7TgoNR7OrLhZT0xO8mZo9FqjqTaGEdcR28cctEMPLKsi Ts7XmsZBpSF3JLxtOAHNgMjyZPd6aVl7rWy5O7QKzA8OFjLSRdNyATB0r6QORbvK Fr6AwpQcyQN2yrCfE8ftA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1664469101; x= 1664476301; bh=fXgOJN1LW1amnuPPnCvibAr43dTYe2jjNHrV/PnQNmU=; b=G 8xXSVqEzTZSbi5pCKxd7jf+9jn53ZQ99FFQplRxgYmhbI7zPlVHq9LVcC5oDKNb/ HxYt7S6t+mCs/InpzpwCq1DWpPA5vyKnfFF533bAdVaA6K5NeAkDc70AMpmnZv/3 DL9c0djzxTmNrn5gttoqJT2ccThmOorUHSVxBzXoJDoobrtF2cwXI1qe9J/x8CgV NUtDmWF3jcyNl1i2yvIMM6SY/pMTypQv7FE8D1cwCc3NSefJIvdwVOeDj/HLZCZ9 OUZ43jgQZ+joZ5pMi19gqRsAgzViekQFp5DyW4WbENHmVn3DrqY84ZbgI1DXZWRn fk54hwhInlHprzUUoqMMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeehtddguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthekredtredtjeenucfhrhhomhepofgr gihimhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtf frrghtthgvrhhnpeduudduhfevjeetfeegvdffvdevvdejudegudekjeehtdelhfffveet hfejledtveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Sep 2022 12:31:41 -0400 (EDT) From: Maxime Ripard Date: Thu, 29 Sep 2022 18:31:08 +0200 Subject: [PATCH v4 14/30] drm/client: Add some tests for drm_connector_pick_cmdline_mode() MIME-Version: 1.0 Message-Id: <20220728-rpi-analog-tv-properties-v4-14-60d38873f782@cerno.tech> References: <20220728-rpi-analog-tv-properties-v4-0-60d38873f782@cerno.tech> In-Reply-To: <20220728-rpi-analog-tv-properties-v4-0-60d38873f782@cerno.tech> To: Jernej Skrabec , Chen-Yu Tsai , Karol Herbst , Samuel Holland , Lyude Paul , Jani Nikula , Daniel Vetter , Thomas Zimmermann , Emma Anholt , Joonas Lahtinen , Ben Skeggs , David Airlie , Rodrigo Vivi , Tvrtko Ursulin , Maarten Lankhorst , Maxime Ripard Cc: =?unknown-8bit?q?linux-arm-kernel=40lists=2Einfradead=2Eorg=2C_Maxime_Ri?= =?unknown-8bit?q?pard_=3Cmaxime=40cerno=2Etech=3E=2C_dri-devel=40lists=2Efr?= =?unknown-8bit?q?eedesktop=2Eorg=2C?= =?unknown-8bit?q?_Geert_Uytterhoeven_=3Cgeert=40linux-m68k=2Eorg=3E=2C_intel?= =?unknown-8bit?q?-gfx=40lists=2Efreedesktop=2Eorg=2C_linux-sunxi=40lists=2E?= =?unknown-8bit?q?linux=2Edev=2C?= =?unknown-8bit?q?_Hans_de_Goede_=3Chdegoede=40redhat=2Ecom=3E=2C_nouveau=40l?= =?unknown-8bit?q?ists=2Efreedesktop=2Eorg=2C_Noralf_Tr=C3=B8nnes_=3Cnoralf?= =?unknown-8bit?q?=40tronnes=2Eorg=3E=2C?= =?unknown-8bit?q?_Mateusz_Kwiatkowski_=3Ckfyatek+publicgit=40gmail=2Ecom=3E?= =?unknown-8bit?q?=2C_Dave_Stevenson_=3Cdave=2Estevenson=40raspberrypi=2Ecom?= =?unknown-8bit?q?=3E=2C?= =?unknown-8bit?q?_linux-kernel=40vger=2Ekernel=2Eorg=2C_Dom_Cobley_=3Cdom=40?= =?unknown-8bit?q?raspberrypi=2Ecom=3E=2C_Phil_Elwell_=3Cphil=40raspberrypi?= =?unknown-8bit?q?=2Ecom=3E?= X-Mailer: b4 0.11.0-dev-7da52 X-Developer-Signature: v=1; a=openpgp-sha256; l=4277; i=maxime@cerno.tech; h=from:subject:message-id; bh=7VyM4Pt4bZb5rC3DABT+LAl6SB4YL57S4Ca68AjYCgE=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMmmJ9z/Jh3Y+27xr/P7NqaUOzcelpkyId/R4K0N+6bfjMZG pyfadpSyMIhxMciKKbLECJsviTs163UnG988mDmsTCBDGLg4BWAi9p8Y/gps+atZL5bQc+uxi5mI6E SdP17mqf8cJjXevvRq8wGu2GxGhrdmC569Wrul94TWktC3z99qXFtyzveyvFn2uQQB+Vd5lQwA X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220929_093142_864262_322E10A1 X-CRM114-Status: GOOD ( 15.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org drm_connector_pick_cmdline_mode() is in charge of finding a proper drm_display_mode from the definition we got in the video= command line argument. Let's add some unit tests to make sure we're not getting any regressions there. Signed-off-by: Maxime Ripard --- Changes in v4: - Removed MODULE macros --- drivers/gpu/drm/drm_client_modeset.c | 4 + drivers/gpu/drm/tests/drm_client_modeset_test.c | 105 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c index bbc535cc50dd..d553e793e673 100644 --- a/drivers/gpu/drm/drm_client_modeset.c +++ b/drivers/gpu/drm/drm_client_modeset.c @@ -1237,3 +1237,7 @@ int drm_client_modeset_dpms(struct drm_client_dev *client, int mode) return ret; } EXPORT_SYMBOL(drm_client_modeset_dpms); + +#ifdef CONFIG_DRM_KUNIT_TEST +#include "tests/drm_client_modeset_test.c" +#endif diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c new file mode 100644 index 000000000000..09dc5acbbc42 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Maxime Ripard + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "drm_kunit_helpers.h" + +struct drm_client_modeset_test_priv { + struct drm_device *drm; + struct drm_connector connector; +}; + +static int drm_client_modeset_connector_get_modes(struct drm_connector *connector) +{ + struct drm_display_mode *mode; + int count; + + count = drm_add_modes_noedid(connector, 1920, 1200); + + return count; +} + +static const struct drm_connector_helper_funcs drm_client_modeset_connector_helper_funcs = { + .get_modes = drm_client_modeset_connector_get_modes, +}; + +static const struct drm_connector_funcs drm_client_modeset_connector_funcs = { +}; + +static int drm_client_modeset_test_init(struct kunit *test) +{ + struct drm_client_modeset_test_priv *priv; + int ret; + + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + test->priv = priv; + + priv->drm = drm_kunit_device_init(test, "drm-client-modeset-test"); + if (IS_ERR(priv->drm)) + return PTR_ERR(priv->drm); + + ret = drmm_connector_init(priv->drm, &priv->connector, + &drm_client_modeset_connector_funcs, + DRM_MODE_CONNECTOR_Unknown, + NULL); + if (ret) + return ret; + drm_connector_helper_add(&priv->connector, &drm_client_modeset_connector_helper_funcs); + + return 0; + +} + +static void drm_pick_cmdline_res_1920_1080_60(struct kunit *test) +{ + struct drm_client_modeset_test_priv *priv = test->priv; + struct drm_device *drm = priv->drm; + struct drm_connector *connector = &priv->connector; + struct drm_cmdline_mode *cmdline_mode = &connector->cmdline_mode; + struct drm_display_mode *expected_mode, *mode; + const char *cmdline = "1920x1080@60"; + int ret; + + expected_mode = drm_mode_find_dmt(priv->drm, 1920, 1080, 60, false); + KUNIT_ASSERT_PTR_NE(test, expected_mode, NULL); + + KUNIT_ASSERT_TRUE(test, + drm_mode_parse_command_line_for_connector(cmdline, + connector, + cmdline_mode)); + + mutex_lock(&drm->mode_config.mutex); + ret = drm_helper_probe_single_connector_modes(connector, 1920, 1080); + mutex_unlock(&drm->mode_config.mutex); + KUNIT_ASSERT_GT(test, ret, 0); + + mode = drm_connector_pick_cmdline_mode(connector); + KUNIT_ASSERT_PTR_NE(test, mode, NULL); + + KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected_mode, mode)); +} + +static struct kunit_case drm_pick_cmdline_tests[] = { + KUNIT_CASE(drm_pick_cmdline_res_1920_1080_60), + {} +}; + +static struct kunit_suite drm_pick_cmdline_test_suite = { + .name = "drm_pick_cmdline", + .init = drm_client_modeset_test_init, + .test_cases = drm_pick_cmdline_tests +}; + +kunit_test_suite(drm_pick_cmdline_test_suite);