From patchwork Fri Jul 29 16:34:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12932641 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 6DA8CC00144 for ; Fri, 29 Jul 2022 16:42:25 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xSxd+iwPmuL4M71k5v0D4az9m+xVV8sO6GMqg6WsLwE=; b=4BiwBlJ/WRUQpZ H1Wx5IX6W+tpIc+s4XvcQOV9fwmCMclypgvdC71Mdc24cUUCtUBGQQLsH2oYSZJuCpfdful9MI11/ HmPPV73FUdtE+FRAmzqs1AGFi04uy3xq+md3Vlf7G4rHV82nelhNnogpasiRZ6dy5boWg/oNG0kl1 H0A4uMr1vkQQKZORMqL3AcVRy3ZBKeX14GbdpHk4um2r7A2YK9JUxUwEA3nLEnwKiU3Ajz6vIVT3c i/V7biOiSY7uVTlQtMchK1OWuWUeO7YQa8qG2x69LIudMw3Rg5VTQJZlCrYzNvJSLQEgmXdpYmCla gYDVqppzcaWeTxkhTOXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHT34-006VSt-2f; Fri, 29 Jul 2022 16:41:14 +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 1oHSxy-006S4G-4p; Fri, 29 Jul 2022 16:36:00 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id 65A1A580937; Fri, 29 Jul 2022 12:35:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 29 Jul 2022 12:35:57 -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=1659112557; x= 1659119757; bh=rionF70mGt2ReIu0+bybNfVGogwhxNfWtTjJc6I+c/U=; b=E C0Jsk6QNxiRXyGDpwM1XIRCrDQ6YCr5BX3Z4GDmWNY5jN0GN8sZT+OMHlM3kBOd1 lFxtLRax6yoIIB/I/Z/oDfOT06zkc4IcS/0uUfwSQv/aJSECvWj/Yfglh5u2KHP/ eQXwezEHwq5oB5Ghwv1118/OZI4/xHzSZNOijQOXeTLRsQ/PKruo0dWZtKficp8B x/xrMJnJcPnTO5NtO5h2OrqDRIntrGBM9Q+gEH18VeBIePPy9Hy8cjkM4gaCbI5p qbqw13Zr9PWXRPtPu4cQyo2JUG1BxNihjmsnwvB2leGM2idfSILzYnb/H9bYc/G3 Ub+AJoI/c81/hUe6dcPSA== 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=fm3; t=1659112557; x= 1659119757; bh=rionF70mGt2ReIu0+bybNfVGogwhxNfWtTjJc6I+c/U=; b=l 9oqZjQ5poGXwVuOA0Mmp6Nm0azNePHQHe20vqO2d1RagSz/EvXTMQFxzhxdrd0o3 Ibcwsk/Hdg1jLQlGBvAcGx9EYl4NeGO3gyMJhuwccFgumKPVwFmonvKpboU5IJhZ MPCSycH4tolRHj27AAK5kF04f9qGnYAp1bWbUxgUO90hYjP03VtUL0DNOD2KCz1Y lf4zNqVNToHTAFcQPnVbsGOxjuXfmacRCwdjs1Yhw6wnFpV4A+6KK2jZxrX8N+4H MHQ3fs2mJCFnWy+r0/JHn4aRth2uNRn34KmCEnhmiy5nulQprwGcvLFXcAM3Qu5R +bBfoHcd90pbcXqiz+0Ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddujedguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfgggtoffgsehtkeertdertdejnecuhfhrohhmpefo rgigihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecugg ftrfgrthhtvghrnhepgfffgfetffduudelhfevieffffduleevgfegkeeutefgffejheel leekjeefhfejnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrh homhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Jul 2022 12:35:56 -0400 (EDT) From: Maxime Ripard To: Jernej Skrabec , Martin Blumenstingl , Chen-Yu Tsai , Philipp Zabel , Jerome Brunet , Samuel Holland , Thomas Zimmermann , Daniel Vetter , Emma Anholt , David Airlie , Maarten Lankhorst , =?utf-8?q?Noralf_Tr?= =?utf-8?q?=C3=B8nnes?= , Kevin Hilman , Neil Armstrong , Maxime Ripard Cc: Maxime Ripard , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Phil Elwell , Mateusz Kwiatkowski , linux-arm-kernel@lists.infradead.org, Geert Uytterhoeven , Dave Stevenson , linux-amlogic@lists.infradead.org, dri-devel@lists.freedesktop.org, Dom Cobley Subject: [PATCH v1 08/35] drm/client: Add some tests for drm_connector_pick_cmdline_mode() Date: Fri, 29 Jul 2022 18:34:51 +0200 Message-Id: <20220728-rpi-analog-tv-properties-v1-8-3d53ae722097@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> References: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> MIME-Version: 1.0 X-Mailer: b4 0.10.0-dev-49460 X-Developer-Signature: v=1; a=openpgp-sha256; l=4539; i=maxime@cerno.tech; h=from:subject:message-id; bh=c3kjQmHh3y8Jr/+VF2HLpBy12BonihyM9gV7vCEOTV4=; b=owGbwMvMwCHc4XzqmfnC7acZT6slMSQ94VHymlT7KT+mWLC/hc24PK+0oWUuP3OxGktWTOa9yNvd 16I7SlkYhDkYZMUUWa4LvrXjC4tyi+D5sBlmDisTyBAGLk4BmMiCyQz/zC8yd2ezNG/fXbIyQTvpuu CDbTOO3a/e8mKhgtaMlnkGbAz/Sw10PmYaaykYMD+0ej/ft1pgW4Viy/WHfrkci/ivxHA7AgA= 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-20220729_093558_308066_FD2B231D X-CRM114-Status: GOOD ( 12.39 ) 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 diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c index bbc535cc50dd..ee6b8f193c24 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_mode_test.c" +#endif diff --git a/drivers/gpu/drm/tests/drm_mode_test.c b/drivers/gpu/drm/tests/drm_mode_test.c new file mode 100644 index 000000000000..0f71519788a7 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_mode_test.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Maxime Ripard + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +struct drm_mode_test_priv { + struct device *dev; + struct drm_device *drm; + struct drm_connector connector; +}; + +static const struct drm_mode_config_funcs drm_mode_config_funcs = { +}; + +static const struct drm_driver drm_mode_driver = { +}; + +static int drm_mode_connector_get_modes(struct drm_connector *connector) +{ + struct drm_display_mode *mode; + int ret; + + ret = drm_add_modes_noedid(connector, 1920, 1200); + if (ret) + return ret; + + return 0; +} + +static const struct drm_connector_helper_funcs drm_mode_connector_helper_funcs = { + .get_modes = drm_mode_connector_get_modes, +}; + +static const struct drm_connector_funcs drm_mode_connector_funcs = { +}; + +static int drm_mode_test_init(struct kunit *test) +{ + struct drm_mode_test_priv *priv; + int ret; + + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + test->priv = priv; + + priv->dev = root_device_register("drm-mode-test"); + if (IS_ERR(priv->dev)) + return PTR_ERR(priv->dev); + + priv->drm = drm_dev_alloc(&drm_mode_driver, priv->dev); + if (IS_ERR(priv->drm)) + return PTR_ERR(priv->drm); + priv->drm->mode_config.funcs = &drm_mode_config_funcs; + + ret = drmm_mode_config_init(priv->drm); + if (ret) + return ret; + + ret = drmm_connector_init(priv->drm, &priv->connector, + &drm_mode_connector_funcs, + DRM_MODE_CONNECTOR_Unknown, + NULL); + if (ret) + return ret; + drm_connector_helper_add(&priv->connector, &drm_mode_connector_helper_funcs); + + return 0; +} + +static void drm_mode_test_exit(struct kunit *test) +{ + struct drm_mode_test_priv *priv = test->priv; + + drm_dev_put(priv->drm); + root_device_unregister(priv->dev); +} + +static void drm_mode_res_1920_1080_60(struct kunit *test) +{ + struct drm_mode_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_mode_tests[] = { + KUNIT_CASE(drm_mode_res_1920_1080_60), + {} +}; + +static struct kunit_suite drm_mode_test_suite = { + .name = "drm_mode", + .init = drm_mode_test_init, + .exit = drm_mode_test_exit, + .test_cases = drm_mode_tests +}; + +kunit_test_suite(drm_mode_test_suite); +MODULE_AUTHOR("Maxime Ripard "); +MODULE_LICENSE("GPL");