Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp387336imn; Fri, 29 Jul 2022 09:52:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WXPU171maGrAKO93lnXywg7Ffn8X/FGSbU98uqRcUDAq/o844xaBizPchSTd+au3ouZnh X-Received: by 2002:a17:90b:1bc7:b0:1f0:34e2:5c86 with SMTP id oa7-20020a17090b1bc700b001f034e25c86mr5024896pjb.136.1659113549200; Fri, 29 Jul 2022 09:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659113549; cv=none; d=google.com; s=arc-20160816; b=WM2nS1PIjl/DHZhguJe8rzB7BhVbb/+lSo1yjRY+nrJBtvm4X6hURw5PnBdkUazlDC orm9F/6OJzMZBazk+E7Dv83hmVEQpJF/e5qCtYNPJiEC65rZiVmNDUit4r/OSajIpEWn b13vlTNZw8URTy7Cn6lRUByb6OeIDJcplqhl3ydybsq2FtxGkRgHuRylwQcnOIxL3Wiq /KgpWWRgRSPvEKdYT+M+OG4ktIEWvc9VxKoVOCO7iCx21I+ndelvBRZM29iRLWxkmqDA FYF4Wz4i5jcBmtA68IH3DtAzr8ykkfSL2ZH0RmUh6QvU0xqlgaNOQ4z3JkjLIkYfui4X QMrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=rionF70mGt2ReIu0+bybNfVGogwhxNfWtTjJc6I+c/U=; b=Z8poKkGzyu7SGBvA1XckabBvJ6jPUMA75tvuniDXSer0EOvdVjnuvieGXXIiCX4sj1 r6Dzu5/ahYTx9k8KvmCLKkRhsDmv7W73JcXO5LWw75lcASO3TRVYPKxm3/ZIxiHVOmvK hqj0dtP2Hc6zeNktwhAM8K6t6j64GqxfmKI817/p2YRhxmp2Xz1Kb0+QbsBkgQKqV9wU /7HQ3+/HP6gunvJw7J434ps9OJB460A60fWlZ3bbBstucTMdHx0TPDI4piXu0KtMWUjx A4PllC1FOQxynDuEKRESKkb1NTOO183Tgm6WqngHla88pID4YtVst/gtrWZRY4N4eok3 zI6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=EC0Jsk6Q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=l9oqZjQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170903244e00b0016d3108ca6asi4951972pls.109.2022.07.29.09.52.14; Fri, 29 Jul 2022 09:52:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=EC0Jsk6Q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=l9oqZjQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238101AbiG2QqI (ORCPT + 99 others); Fri, 29 Jul 2022 12:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238129AbiG2Qpt (ORCPT ); Fri, 29 Jul 2022 12:45:49 -0400 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0503388F2E for ; Fri, 29 Jul 2022 09:45:47 -0700 (PDT) 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=20Tr=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 Content-Type: text/plain; charset="utf-8" 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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"); -- b4 0.10.0-dev-49460