From patchwork Thu Nov 10 11:07:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13038647 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 B520DC4332F for ; Thu, 10 Nov 2022 11:11:24 +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=gvQgEdz5H2yM/U7zilHtrjgbvu0NCXlfxacTbhjxHOs=; b=CBRu2wNhsJeitY ikEAUJslQKpO0HY6tAndh0UMyKOAHWJBAUbXqw5Z9nTt2J4jgA+e4+V771S8ZNPujBhSZFqtBgmrm ZgRNCgiTgjssV7HDvJUJ8nuia36susko8g1inZzMetTvKyTXUbx+wfO+xu5GMMbPHnDDjoVKDNbUB wi7Sj+6h8YoHNzyBSRjHC8fO57Dpm6TMnIt2WBFI4QsLTK640m9uyQTxPQfv02uAGyeoNDTjbAdxf lUZH4vJirpANnDji5fFZzfrAw5TDSkEh9URbjpEfkbmpt99R1dR+sMOSOaM0wq8CjRopfJseytqy/ UPfaOEX3Csn/u7UIxFSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ot5Rj-005F2P-3Y; Thu, 10 Nov 2022 11:10:11 +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 1ot5PC-005DjG-1g for linux-arm-kernel@lists.infradead.org; Thu, 10 Nov 2022 11:07:35 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id 6F6FF580304; Thu, 10 Nov 2022 06:07:33 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 10 Nov 2022 06:07:33 -0500 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=1668078453; x= 1668085653; bh=JFH60TjLhF4X2cG8BsEbpMtUQgyvSuOsjoB880SrFRc=; b=V Bf1fhEeXj7Ne9d7eugUCqsa+xVCB2taWzEo+9I9PuCWAYMIhXzWULg43XPgCtEi7 ZNX2BC36IkrlLryqBYzl66joDuXwtyMcMsI/sYw7am1VOh4tZUHa4SGsqSSEAxt5 CfCVBAepIpXSFE1rQWyEuIblrPZSIMBnujckJi5OoUfeCSi2Ipb+rqf9yHYaiAoU D1PQ1f7xQsTtlm4JIT27btufwgV3IPECftcLm4D3Uf1ntYoJLylseSrl5wopi4wy f88J37+EZGEFeWMYZ2DYh2YFmoNegogwDteEOefkBHlLHSdibpAtmO4R67f0daa6 870mLf7nhgUxOYqsMt9+Q== 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=fm1; t=1668078453; x= 1668085653; bh=JFH60TjLhF4X2cG8BsEbpMtUQgyvSuOsjoB880SrFRc=; b=E heqtUJybT8TCMa1+6gx+ca1LjdFlO5Je1rNxok5Eue6PuAHHCtVI4gpm4gvZzBVg /R8FxYj5LzZ03871fXy2A8dZvQGcECLlIjDSsfGym3ivJHDsShxKhdr6JBxucmgS R6omtFj2+GNZIBb5zqeOGWsKF/ZrkESKP9KKMVSu518eifh4gdM9kLwtQynj2azL cAfmoTN5MiYLY+WasVBMVrxMF7ny6oKcgTIu+KycqKAiavVPddPjcrXq3u0S8t67 qxN4JRRQB3766/aVyx1nejCGTe858WhKS1QCtgfdwirzbkMzWLdiWTinxVQB9Bkp mdL4qhezRajvqv85GFAqA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeeggddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhfffuggfgtgfkfhgjvfevofesthekredtredtjeenucfhrhhomhepofgrgihi mhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrg htthgvrhhnpedvgfevjefhtdetveevhfelieeuueetgfdvgeevkeegudejffegfffgtedt leelhfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 10 Nov 2022 06:07:32 -0500 (EST) From: Maxime Ripard Date: Thu, 10 Nov 2022 12:07:19 +0100 Subject: [PATCH v8 07/24] drm/client: Add some tests for drm_connector_pick_cmdline_mode() MIME-Version: 1.0 Message-Id: <20220728-rpi-analog-tv-properties-v8-7-09ce1466967c@cerno.tech> References: <20220728-rpi-analog-tv-properties-v8-0-09ce1466967c@cerno.tech> In-Reply-To: <20220728-rpi-analog-tv-properties-v8-0-09ce1466967c@cerno.tech> To: Maarten Lankhorst , Chen-Yu Tsai , Maxime Ripard , Jernej Skrabec , Karol Herbst , Jani Nikula , Daniel Vetter , Lyude Paul , Samuel Holland , Joonas Lahtinen , Thomas Zimmermann , Emma Anholt , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Ben Skeggs Cc: =?unknown-8bit?q?nouveau=40lists=2Efreedesktop=2Eorg=2C_Noralf_Tr=C3=B8n?= =?unknown-8bit?q?nes_=3Cnoralf=40tronnes=2Eorg=3E=2C_Dom_Cobley_=3Cdom=40ra?= =?unknown-8bit?q?spberrypi=2Ecom=3E=2C?= =?unknown-8bit?q?_intel-gfx=40lists=2Efreedesktop=2Eorg=2C_Phil_Elwell_=3Cph?= =?unknown-8bit?q?il=40raspberrypi=2Ecom=3E=2C_linux-sunxi=40lists=2Elinux?= =?unknown-8bit?q?=2Edev=2C?= =?unknown-8bit?q?_Mateusz_Kwiatkowski_=3Ckfyatek+publicgit=40gmail=2Ecom=3E?= =?unknown-8bit?q?=2C_Hans_de_Goede_=3Chdegoede=40redhat=2Ecom=3E=2C_linux-k?= =?unknown-8bit?q?ernel=40vger=2Ekernel=2Eorg=2C?= =?unknown-8bit?q?_Maxime_Ripard_=3Cmaxime=40cerno=2Etech=3E=2C_Dave_Stevenso?= =?unknown-8bit?q?n_=3Cdave=2Estevenson=40raspberrypi=2Ecom=3E=2C_dri-devel?= =?unknown-8bit?q?=40lists=2Efreedesktop=2Eorg=2C?= =?unknown-8bit?q?_linux-arm-kernel=40lists=2Einfradead=2Eorg=2C_Geert_Uytter?= =?unknown-8bit?q?hoeven_=3Cgeert=40linux-m68k=2Eorg=3E?= X-Mailer: b4 0.11.0-dev-99e3a X-Developer-Signature: v=1; a=openpgp-sha256; l=4676; i=maxime@cerno.tech; h=from:subject:message-id; bh=yVx2uVA5vIWOQWcegjDOinr/nkkAcg+x4eleT1mV5LI=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMk5t1M0zsQXHfgR8+aS2nvvtVntvoectvtNueKytqIv9NXp A4EiHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZjIs10M/52D9llny30p7Ky+tO3gUf l91lM4G9atZX/J+c/n0haOwmSG/66f2KQTV+1m7Am1Uk59tmxpe8gMy98Lu/9XyM443s5ZzggA 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-20221110_030734_196893_C9FD6C19 X-CRM114-Status: GOOD ( 15.25 ) 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. Acked-by: Noralf Trønnes Tested-by: Mateusz Kwiatkowski Signed-off-by: Maxime Ripard --- Changes in v6: - Rename tests to be consistent with DRM tests naming convention Changes in v5: - Removed useless (for now) count and modes intermediate variables in get_modes - Switched to kunit assertions in test init, and to KUNIT_ASSERT_NOT_NULL instead of KUNIT_ASSERT_PTR_NE(..., NULL) Changes in v4: - Removed MODULE macros --- drivers/gpu/drm/drm_client_modeset.c | 4 + drivers/gpu/drm/tests/drm_client_modeset_test.c | 100 ++++++++++++++++++++++++ 2 files changed, 104 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..558c098b0384 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -0,0 +1,100 @@ +// 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) +{ + return drm_add_modes_noedid(connector, 1920, 1200); +} + +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); + KUNIT_ASSERT_NOT_NULL(test, priv); + + test->priv = priv; + + priv->drm = drm_kunit_device_init(test, DRIVER_MODESET, "drm-client-modeset-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm); + + ret = drmm_connector_init(priv->drm, &priv->connector, + &drm_client_modeset_connector_funcs, + DRM_MODE_CONNECTOR_Unknown, + NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + + drm_connector_helper_add(&priv->connector, &drm_client_modeset_connector_helper_funcs); + + return 0; + +} + +static void drm_test_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_NOT_NULL(test, expected_mode); + + 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_NOT_NULL(test, mode); + + KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected_mode, mode)); +} + + +static struct kunit_case drm_test_pick_cmdline_tests[] = { + KUNIT_CASE(drm_test_pick_cmdline_res_1920_1080_60), + {} +}; + +static struct kunit_suite drm_test_pick_cmdline_test_suite = { + .name = "drm_test_pick_cmdline", + .init = drm_client_modeset_test_init, + .test_cases = drm_test_pick_cmdline_tests +}; + +kunit_test_suite(drm_test_pick_cmdline_test_suite);