From patchwork Mon Aug 29 13:11:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12957875 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 2AB5BECAAD5 for ; Mon, 29 Aug 2022 13:21:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CEFAB10F2D9; Mon, 29 Aug 2022 13:21:13 +0000 (UTC) Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0CD510F2CF; Mon, 29 Aug 2022 13:20:49 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.west.internal (Postfix) with ESMTP id 72EC62B05F9B; Mon, 29 Aug 2022 09:12:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 29 Aug 2022 09:12:18 -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=fm3; t=1661778734; x= 1661785934; bh=ELfkVxUr/la37A7msWR/2jnnu/mFwFNLuNnzkr6V0mg=; b=O 5gzqV7pYTkeD9LdWrNNZzPJ5npg15h0PMl0JEq/NEZwH5E5AFm5az6ZFcPLpToIb 5TjeWBhkrRrJNk2p0G6XUUV/0SOMr00N9NoQlffJrJRFh+MS1uSASARym+GT47OW esM33Tj8ZK6LII08ud8MjButKRh3DlQx98EnUzq0aeUEVeL1kmPAllng07KEKmWq Lmwy2eqsd/LAY2M20DeQxcMVaNgFF2escO1umOLxsxIOLlix9iDINm/m3WdpAOFd UPve3yeXAnbP3w90QobblR9uj3vLw4hZe/gGqn2/L0QRguVUSW9+6oM1szRTGl4e 5CDr2kqGGN0a4UWiR5EnQ== 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=1661778734; x= 1661785934; bh=ELfkVxUr/la37A7msWR/2jnnu/mFwFNLuNnzkr6V0mg=; b=G K0c86PPa4XUcKDqrVNDLDw+NEzkns7uXqzmwzJePQK2l17VlFmjoGwhzDFmeaSZK 4dKRPAHwsRIK6vAg3rnnrcFyZc3lPOQBRW8fc85VhLQfnibdRe4yVDL+weUyiSo8 vqeJtSIE6Z4JHifBsLQQagdUHyMMQLK/Q0XjP9jE2EwDTwMGy0KGE0UOj7TGKQpg 3Uvp5ZpaREBUFZOPgkKNbZ6guHd5k/Emn6ct3wgNpV2+lyHsrxpofY2SlqYhM09v PmpUxsze7vDLo0sd0K5/3dZ1TpLJW30JUiS4BbvetzA2SOks8Lc0b+Xi3BJBdP4O xahFOaMIq4nkEPF2xtowg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekuddgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfogfesthhqredtredtjeenucfhrhhomhepofgr gihimhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtf frrghtthgvrhhnpeefiedvfefggffgffehveejieffuddtgffhjefggeetieduvdeileet lefgveegtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Aug 2022 09:12:13 -0400 (EDT) From: Maxime Ripard To: Maxime Ripard , Ben Skeggs , David Airlie , Chen-Yu Tsai , Thomas Zimmermann , Jani Nikula , Lyude Paul , Philipp Zabel , Maarten Lankhorst , Rodrigo Vivi , Tvrtko Ursulin , Jernej Skrabec , Samuel Holland , Karol Herbst , =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Emma Anholt , Daniel Vetter , Joonas Lahtinen Date: Mon, 29 Aug 2022 15:11:16 +0200 Message-Id: <20220728-rpi-analog-tv-properties-v2-2-459522d653a7@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> References: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> MIME-Version: 1.0 X-Mailer: b4 0.10.0-dev-65ba7 X-Developer-Signature: v=1; a=openpgp-sha256; l=2642; i=maxime@cerno.tech; h=from:subject:message-id; bh=epeQixwNzn3d4RRhZr1OO6FT9bd6N3aHX8QjcYiaO/E=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMk8u+QXbWpvWW/meZV/YSi7V3O/Ofv3//lZt0IEMz9bz9t9 Lo+5o5SFQYyLQVZMkSVG2HxJ3KlZrzvZ+ObBzGFlAhnCwMUpABNZd5Dhf1r92Zv9Cuav0/P7mybwHA ldVZWw9bdPmkjD3d164mz5nxj+Rz1ZMF0lJ1S06Mg+q2PssQsu699Zt+hR3COJV3VTz/QbMQEA X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Subject: [Intel-gfx] [PATCH v2 02/41] drm/tests: Add Kunit Helpers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dom Cobley , Dave Stevenson , nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-sunxi@lists.linux.dev, Geert Uytterhoeven , Maxime Ripard , Mateusz Kwiatkowski , Phil Elwell , linux-arm-kernel@lists.infradead.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" As the number of kunit tests in KMS grows further, we start to have multiple test suites that, for example, need to register a mock DRM driver to interact with the KMS function they are supposed to test. Let's add a file meant to provide those kind of helpers to avoid duplication. Signed-off-by: Maxime Ripard diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile index 2d9f49b62ecb..b29ef1085cad 100644 --- a/drivers/gpu/drm/tests/Makefile +++ b/drivers/gpu/drm/tests/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ drm_format_helper_test.o \ drm_format_test.o \ drm_framebuffer_test.o \ + drm_kunit_helpers.o \ drm_mm_test.o \ drm_plane_helper_test.o \ drm_rect_test.o diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c new file mode 100644 index 000000000000..7ebd620481c1 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -0,0 +1,54 @@ +#include +#include + +#include + +static const struct drm_mode_config_funcs drm_mode_config_funcs = { +}; + +static const struct drm_driver drm_mode_driver = { +}; + +static void drm_kunit_free_device(struct drm_device *drm, void *ptr) +{ + struct device *dev = ptr; + + root_device_unregister(dev); +} + +struct drm_device *drm_kunit_device_init(const char *name) +{ + struct drm_device *drm; + struct device *dev; + int ret; + + dev = root_device_register(name); + if (IS_ERR(dev)) + return ERR_CAST(dev); + + drm = drm_dev_alloc(&drm_mode_driver, dev); + if (IS_ERR(drm)) { + root_device_unregister(dev); + return ERR_CAST(drm); + } + drm->mode_config.funcs = &drm_mode_config_funcs; + + ret = drmm_add_action_or_reset(drm, drm_kunit_free_device, dev); + if (ret) + goto err_put_device; + + ret = drmm_mode_config_init(drm); + if (ret) + return ERR_PTR(ret); + + return drm; + +err_put_device: + drm_dev_put(drm); + return ERR_PTR(ret); +} + +void drm_kunit_device_exit(struct drm_device *drm) +{ + drm_dev_put(drm); +} diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.h b/drivers/gpu/drm/tests/drm_kunit_helpers.h new file mode 100644 index 000000000000..5015a327a8c1 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.h @@ -0,0 +1,9 @@ +#ifndef DRM_KUNIT_HELPERS_H_ +#define DRM_KUNIT_HELPERS_H_ + +struct drm_device; + +struct drm_device *drm_kunit_device_init(const char *name); +void drm_kunit_device_exit(struct drm_device *drm); + +#endif // DRM_KUNIT_HELPERS_H_