From patchwork Thu Feb 22 18:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp123574dyb; Thu, 22 Feb 2024 10:19:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXM2ZpsFKONauFOUYj4iwyKevxDSevskjjxjkQApt7GLBl5C3xWgZl4+HCdx4SGEOm2AiQ+ex6tCHOp6OuQ4EidOnQClg== X-Google-Smtp-Source: AGHT+IELsZj0x/70blujoDz3q7n4aappBjIsPCAThbHEkwT+UzJ7nm4/TpnF/IJwEstX6446MopB X-Received: by 2002:a25:7903:0:b0:dc7:3165:2db1 with SMTP id u3-20020a257903000000b00dc731652db1mr3002498ybc.49.1708625941912; Thu, 22 Feb 2024 10:19:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708625941; cv=pass; d=google.com; s=arc-20160816; b=kZEc7EmGhbsywe2nWbOVVfDua5oYK7Xv4JF0OVWLYNl/uMR5W9I1enWwRplzNynV76 ErQKcAL2sSUFOWgmbgAlwbRB4/aTilCoQmxexDXPXwqn5u8Qdqzct/k3HgWeCCjk6AbR w8Zho7esMHgG6iQREURF9iIhkCdz/ikwjpymyR2mmy90rNfmRXVgpFZK/DX2XRUqf+5r GdiDtFClLvo646GLaIFxzHvbP0ATopen45FuWs7j30s48OQGa4p0Y6YtfZDW/qkWzahu zYvkfUxeFJPeA1DLAJvqD7y32MxZdCHD0milOlJ3b+7hAgo1tWC2PHaN3TWYyBGadbOJ 5TZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=ZxYKgETjTQKKiJVl7CnttRo2Ctq/C9ls9VGtsqIbLZU=; fh=7mnR4/DMo6zaWtUGaVI9DND4TR+QGflpVaaXOChu5h0=; b=xUbXbv8yiYBq2fdnuewXrz2cb3Fh2uBOxgvyISwIB4XRJjyz4SEP7wipMMA1rKLR8g doIpX4/HwhGuWHnt0ilY9wAdgCx96pT8EmgLPXy2hYp37F6Tj1hKAX74Zj/0JR/pPP2o TQ1LgrUHRSqLahvJpg61dY1xSgXdZEMIfyftQKrTlCVusCo9K0TShL8UdcziuptnZ8lE 7sBXBK6tKl6OfgfE1mSY+EOnVn+qjOvZeO23u24de0V8PfpHMGFfLfL++Yo6j+O8MZ3/ eaQ+DOhrq59Ic5hqub9FoMLJCpspcFYU1IKgW16neDwxGK1UOQlwH/zsR+X1jgskVAYU fvFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jfIZQKjx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77072-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77072-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v11-20020a05620a440b00b00787953a68e6si2907461qkp.30.2024.02.22.10.19.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:19:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77072-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jfIZQKjx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77072-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77072-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A0E8D1C214F4 for ; Thu, 22 Feb 2024 18:19:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 758F315E5A1; Thu, 22 Feb 2024 18:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jfIZQKjx" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2417215D5AF; Thu, 22 Feb 2024 18:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625683; cv=none; b=R19ila7JUIkbhot9ASj+ma8iTOhgDU8FV8wXeVq8N+ffAgeJ+qViwl+rFegdTdYzEnEM1pYuA2gkdDYBXMVIBF7SLvNtVzroHDhs//mVvtwV2FKBvEYfqCwOXKFZ3mgL8dQL9nZK3KC702NG1oXjVpU9An2aNZUCyGzI1DNGwRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625683; c=relaxed/simple; bh=CpWPwPjnSG0Utx4KGltVz+v8L6+sya4K3NyhwxON/7g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tnxWs4CF4BbCJ1+IfKpFS0bH1NFNGw17gc/OfEnNvnSW2ImLbdjzYamNUjtWajCB8/k93YuzBZBpXFOTxhAqfK1uGo35BF9GsD9Mr130TnNtLscBNEfRWEVhkPxCFnZL9QnOE2KG3/p0ihw60Wm5RRE/Yl8xM8bR3WepM+TFD0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jfIZQKjx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3786FC43399; Thu, 22 Feb 2024 18:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625682; bh=CpWPwPjnSG0Utx4KGltVz+v8L6+sya4K3NyhwxON/7g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jfIZQKjxM+/Wb0t5zKKKALeXw/nhaRsVzBRU6GZk8FyDmQaShLaE6WtdGTg2RAoaW d/Cs1GCNAsrMTzbk+rsivGwPHkHU/tZYoCmqSYuGqGObO2TFm7hYtDVfeFtu2avs2h wyBG274/LogrYE6wFA+SdpvLSWhPWpYieAKIXvKE5V/eXEzHQX/YEE9sRC+Qekz5jR X2olI5f/QaOGaxFgqcSwtSw4YvJ6kxR2yEMlCLx308/KnVMI3E6MsLKG1TWZDNWpIU ej6WPth/zz/X2SZyp2I0JWf3tIKolg93mD+4oucb6v858BUqYZ9fG+Lsp+n/6j4LcA ImfzNNuh9cnAQ== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:13:51 +0100 Subject: [PATCH v7 05/36] drm/tests: connector: Add tests for drmm_connector_init Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240222-kms-hdmi-connector-state-v7-5-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , 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=5901; i=mripard@kernel.org; h=from:subject:message-id; bh=CpWPwPjnSG0Utx4KGltVz+v8L6+sya4K3NyhwxON/7g=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+97YfJyb9Pnqp/ivArO2POGYBZSwZ3jcGb9tX/paa 7/Xfz93lLIwiHExyIopssQImy+JOzXrdScb3zyYOaxMIEMYuDgFYCLKGxgZHq5vX97Zs0oy/aGb e9/hNTtr7s5qcSi22ev6PFgl+nOrE8M/DfFEs9ktK9mXLnuYFT9P9Hh+7FbZi3GenYITb9RvCap nAwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624155606518496 X-GMAIL-MSGID: 1791624155606518496 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 Reviewed-by: MaĆ­ra Canal --- drivers/gpu/drm/tests/drm_connector_test.c | 170 ++++++++++++++++++++++++++++- 1 file changed, 169 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..a268847be8d1 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -3,10 +3,175 @@ * 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 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_ddc), + 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 +235,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");