From patchwork Tue Nov 28 10:24:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 170684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3813234vqx; Tue, 28 Nov 2023 02:25:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4IXf0LEbaq6sNqaYPCCoTdHeAXKHmTnZYKq/HqXszR1u087X3TLQU6AQlbX55vwAnI32S X-Received: by 2002:a17:902:7209:b0:1cf:d650:380a with SMTP id ba9-20020a170902720900b001cfd650380amr4616050plb.13.1701167114932; Tue, 28 Nov 2023 02:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701167114; cv=none; d=google.com; s=arc-20160816; b=mJgMvwtdOICPG+QKUA6MA+PAbSgBUcC84jPAGkJXvQnJon4d+6WSjSPh8ZdMU8Z7g7 orZzkE0qRa49lRpwhxRaCnZ9AW9XYAWjht2hUmS9oK9CVPaEq6ynz8eSbHVQPxC0rBt/ HGfGURngWsTQQ+A5Bedr8Ue7t9OMMbZnv6jj27u9F+pGh6g1FWVKwrYu9taoum0jRkbI c+xf45J1v+5MfmLDGxa7YhBmvILaOS7TJTHX2u/Jcb5ybPUl+2ZUGMCweHfybU4rGnJy l7wrFTqvYUcrZwxATE+qZfYfSlPXjP96xZSsCrinaiJ+yKXkKEfI6wIO55R2nckqk0lR tLIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=J5qRhEtZ5pfYzBq+vnBS8R00LAQYezDURN2JPg3P+xE=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=X7+WbSWfAIWHSTuPQp6Lxan0f6OozOUvB6qI4lkLfD1cp25kn56vKZh1H0RoWxwNmk CN9badpnLz8lK2nxVA/HbRSRdhqMXmpjC8vQ0VVyhX+MdA685x59PKx0v4aqF6hq8Zhz Niv3WoAzoHp9V/STj86BzyviCwBA1KbX0eKo35PZxtopLFw67KGkH9ABb/xrHjYJlTD8 SHTgOqZGE1MMDsAW7BswdINke4jCnkyiuXG7djrjJTBeXbLldFIH1Tdfw7zlMGCB+1bc GBfB9yE7roUY9wAcUWL9NL/CXyZSlzc7fYjCIbKtwm4yvU4UIrPuBRe3mtcFNq4yqE0h njgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fdMh5m/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id s13-20020a170902b18d00b001cc3473657bsi11502239plr.215.2023.11.28.02.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 02:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fdMh5m/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 00BFA8078679; Tue, 28 Nov 2023 02:25:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344306AbjK1KZB (ORCPT + 99 others); Tue, 28 Nov 2023 05:25:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234816AbjK1KYm (ORCPT ); Tue, 28 Nov 2023 05:24:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC97F19B4 for ; Tue, 28 Nov 2023 02:24:39 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E2EAC433C7; Tue, 28 Nov 2023 10:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701167079; bh=3X0my8D9PYgi7EcRYdh/ciCZnSzC7V4KrXKwBufu/RU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fdMh5m/wf1os2Twf7x9R3y/oESAVctil6OOi0TD8uMJqzgm2ucDNofyTTaqSkHupD YSnLuC2ECniJbZZHj7YtntwJ2DpmWicxvNFJo+/wtvXTX2T79ww9PHWPxfxGfyg01i pXoVueYoFt/fAFWChl6J3s0Q4lypDwqlEB4MM11ZqTPN2RXqXUGGfgvCy9/j0DQVMN ks9PX2Y5xpD2q+kS3Hty/oqBr2woV5uVyyVQk4CtdoZlaC4guFJ7l5qwV+SiEZlA3q ZuDItQ77sFqTI35wn96NlL1uKkwOkRoOxs0nAvVWKUQBzwsGvoEGJBFdazdxwPwjPQ FGzLhLfH8FPHA== From: Maxime Ripard Date: Tue, 28 Nov 2023 11:24:17 +0100 Subject: [PATCH v4 06/45] drm/tests: connector: Add tests for drmm_connector_init MIME-Version: 1.0 Message-Id: <20231128-kms-hdmi-connector-state-v4-6-c7602158306e@kernel.org> References: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> In-Reply-To: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@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 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7273; i=mripard@kernel.org; h=from:subject:message-id; bh=3X0my8D9PYgi7EcRYdh/ciCZnSzC7V4KrXKwBufu/RU=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmp+y+WV9joJ/mFc+6fInpil2zk3YA9xl3yXgukNSNrW i/rpi3uKGVhEONikBVTZIkRNl8Sd2rW6042vnkwc1iZQIYwcHEKwESEtjIy/GN3fJF6asbkBW0/ t/98+WJ14YKDT/R6nbIrrvQlXf5zZinDP4XH06U/6K0tnNn9wsf8vabUV2/xS2nMKYrnU+9/7BS YyAoA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 28 Nov 2023 02:25:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783803008578526728 X-GMAIL-MSGID: 1783803008578526728 drmm_connector_init is the preferred function to initialize a drm_connector structure. Let's add a bunch of unit tests for it. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_connector_test.c | 219 ++++++++++++++++++++++++++++- 1 file changed, 218 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c index c66aa2dc8d9d..4951b5b121a2 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -3,10 +3,224 @@ * Kunit test for drm_modes functions */ +#include + +#include #include +#include +#include #include +struct drm_connector_init_priv { + struct drm_device drm; + struct drm_connector connector; + struct i2c_adapter ddc; +}; + +static const struct drm_connector_funcs dummy_funcs = { + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .reset = drm_atomic_helper_connector_reset, +}; + +static int dummy_ddc_xfer(struct i2c_adapter *adapter, + struct i2c_msg *msgs, int num) +{ + return num; +} + +static u32 dummy_ddc_func(struct i2c_adapter *adapter) +{ + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; +} + +static const struct i2c_algorithm dummy_ddc_algorithm = { + .master_xfer = dummy_ddc_xfer, + .functionality = dummy_ddc_func, +}; + +static void i2c_del_adapter_wrapper(void *ptr) +{ + struct i2c_adapter *adap = ptr; + + i2c_del_adapter(adap); +} + +static int drm_test_connector_init(struct kunit *test) +{ + struct drm_connector_init_priv *priv; + struct device *dev; + int ret; + + dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + + priv = drm_kunit_helper_alloc_drm_device(test, dev, + struct drm_connector_init_priv, drm, + DRIVER_MODESET | DRIVER_ATOMIC); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); + + strscpy(priv->ddc.name, "dummy-connector-ddc", sizeof(priv->ddc.name)); + priv->ddc.owner = THIS_MODULE; + priv->ddc.algo = &dummy_ddc_algorithm; + priv->ddc.dev.parent = dev; + + ret = i2c_add_adapter(&priv->ddc); + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = kunit_add_action_or_reset(test, i2c_del_adapter_wrapper, &priv->ddc); + KUNIT_ASSERT_EQ(test, ret, 0); + + test->priv = priv; + return 0; +} + +/* + * Test that the registration of a bog standard connector works as + * expected and doesn't report any error. + */ +static void drm_test_drmm_connector_init(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_init(&priv->drm, &priv->connector, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc); + KUNIT_EXPECT_EQ(test, ret, 0); +} + +/* + * Test that the registration of a connector without a DDC adapter + * doesn't report any error. + */ +static void drm_test_drmm_connector_init_null_ddc(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_init(&priv->drm, &priv->connector, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + NULL); + KUNIT_EXPECT_EQ(test, ret, 0); +} + +/* + * Test that the registration of a connector without a DRM device fails. + */ +static void drm_test_drmm_connector_init_null_device(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_init(NULL, &priv->connector, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc); + KUNIT_EXPECT_LT(test, ret, 0); +} + +/* + * Test that the registration of a NULL connector fails. + */ +static void drm_test_drmm_connector_init_null_connector(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_init(&priv->drm, NULL, + &dummy_funcs, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc); + KUNIT_EXPECT_LT(test, ret, 0); +} + +/* + * Test that the registration of a connector without any callbacks + * fails. + */ +static void drm_test_drmm_connector_init_null_funcs(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + int ret; + + ret = drmm_connector_init(&priv->drm, &priv->connector, + NULL, + DRM_MODE_CONNECTOR_HDMIA, + &priv->ddc); + KUNIT_EXPECT_LT(test, ret, 0); +} + +/* + * Test that the registration of a connector succeeds for all possible + * connector types. + */ +static void drm_test_drmm_connector_init_type_valid(struct kunit *test) +{ + struct drm_connector_init_priv *priv = test->priv; + unsigned int connector_type = *(unsigned int *)test->param_value; + int ret; + + ret = drmm_connector_init(&priv->drm, &priv->connector, + &dummy_funcs, + connector_type, + &priv->ddc); + KUNIT_EXPECT_EQ(test, ret, 0); +} + +static const unsigned int drm_connector_init_type_valid_tests[] = { + DRM_MODE_CONNECTOR_Unknown, + DRM_MODE_CONNECTOR_VGA, + DRM_MODE_CONNECTOR_DVII, + DRM_MODE_CONNECTOR_DVID, + DRM_MODE_CONNECTOR_DVIA, + DRM_MODE_CONNECTOR_Composite, + DRM_MODE_CONNECTOR_SVIDEO, + DRM_MODE_CONNECTOR_LVDS, + DRM_MODE_CONNECTOR_Component, + DRM_MODE_CONNECTOR_9PinDIN, + DRM_MODE_CONNECTOR_DisplayPort, + DRM_MODE_CONNECTOR_HDMIA, + DRM_MODE_CONNECTOR_HDMIB, + DRM_MODE_CONNECTOR_TV, + DRM_MODE_CONNECTOR_eDP, + DRM_MODE_CONNECTOR_VIRTUAL, + DRM_MODE_CONNECTOR_DSI, + DRM_MODE_CONNECTOR_DPI, + DRM_MODE_CONNECTOR_WRITEBACK, + DRM_MODE_CONNECTOR_SPI, + DRM_MODE_CONNECTOR_USB, +}; + +static void drm_connector_init_type_desc(const unsigned int *type, char *desc) +{ + sprintf(desc, "%s", drm_get_connector_type_name(*type)); +} + +KUNIT_ARRAY_PARAM(drm_connector_init_type_valid, + drm_connector_init_type_valid_tests, + drm_connector_init_type_desc); + +static struct kunit_case drmm_connector_init_tests[] = { + KUNIT_CASE(drm_test_drmm_connector_init), + KUNIT_CASE(drm_test_drmm_connector_init_null_connector), + KUNIT_CASE(drm_test_drmm_connector_init_null_ddc), + KUNIT_CASE(drm_test_drmm_connector_init_null_device), + KUNIT_CASE(drm_test_drmm_connector_init_null_funcs), + KUNIT_CASE_PARAM(drm_test_drmm_connector_init_type_valid, + drm_connector_init_type_valid_gen_params), + { } +}; + +static struct kunit_suite drmm_connector_init_test_suite = { + .name = "drmm_connector_init", + .init = drm_test_connector_init, + .test_cases = drmm_connector_init_tests, +}; + struct drm_get_tv_mode_from_name_test { const char *name; enum drm_connector_tv_mode expected_mode; @@ -70,7 +284,10 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { .test_cases = drm_get_tv_mode_from_name_tests, }; -kunit_test_suite(drm_get_tv_mode_from_name_test_suite); +kunit_test_suites( + &drmm_connector_init_test_suite, + &drm_get_tv_mode_from_name_test_suite +); MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL");