From patchwork Fri Jul 28 09:06:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13331511 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 98DE4C0015E for ; Fri, 28 Jul 2023 09:06:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F11A10E6A7; Fri, 28 Jul 2023 09:06:29 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 721AD10E6A7 for ; Fri, 28 Jul 2023 09:06:25 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E645762085; Fri, 28 Jul 2023 09:06:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0080BC433C8; Fri, 28 Jul 2023 09:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690535184; bh=g19Qr7lTEX4DQpW0gKyuC8KKuGZXXC9l7fQhhK+dJSE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CEFjL9Sx7KXL8EOMQcOXjK4yr3X1qxzElzF8P4uksXp3+8MUkFd7QM63SW0KNshB/ m7gnmqXLfNlJZFywCPGZpam1rw4l0RJuxim36RooRckxbCOEw9sagO8irzYnnlaAMp WZxp3PTYVG1l2IsOb1jgLdoEu+OFYB+B91c2mMAs5cEN8cYMV1A6lCgNfdO6T79GLC 71j3bkf5xTdATo85I4CZhwPJbQFsa94KBFasLpfP7saMSomaUH9nZkKEN5Tq3e0eyv +FVr1az/HIC1vR57CQKMDWjdEpColFwVqhc9UdvYklCc1aso1xdBDsWR7/AiCuHVaO tOU73Z/hFWwAA== From: Maxime Ripard Date: Fri, 28 Jul 2023 11:06:14 +0200 Subject: [PATCH v3 01/11] drm/tests: helpers: Switch to kunit actions MIME-Version: 1.0 Message-Id: <20230728-kms-kunit-actions-rework-v3-1-952565ccccfe@kernel.org> References: <20230728-kms-kunit-actions-rework-v3-0-952565ccccfe@kernel.org> In-Reply-To: <20230728-kms-kunit-actions-rework-v3-0-952565ccccfe@kernel.org> To: David Airlie , Daniel Vetter , Maarten Lankhorst , Thomas Zimmermann , Emma Anholt X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3170; i=mripard@kernel.org; h=from:subject:message-id; bh=g19Qr7lTEX4DQpW0gKyuC8KKuGZXXC9l7fQhhK+dJSE=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCmHW7kcFk19LujtYX7eSdTX7/TqrR+97EXLLwSc2hr1S TRXj/NIRykLgxgXg6yYIkuMsPmSuFOzXney8c2DmcPKBDKEgYtTACZSrs7IcHmx6o5blq+msj01 ONnBYfAkyXbS2dgdaytVPfbu8ygzcWH4n1X35O6vUOGVjhvuhn6zk/qXqvn1R9CbnIk5K7KXWEy 4xgcA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kselftest@vger.kernel.org, Brendan Higgins , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= , Maxime Ripard , David Gow , kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Reviewed-by: Javier Martinez Canillas Reviewed-by: MaĆ­ra Canal Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 54 ++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 4df47071dc88..cdf35421e641 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -26,6 +26,28 @@ static struct platform_driver fake_platform_driver = { }, }; +static void kunit_action_platform_driver_unregister(void *ptr) +{ + struct platform_driver *drv = ptr; + + platform_driver_unregister(drv); + +} + +static void kunit_action_platform_device_put(void *ptr) +{ + struct platform_device *pdev = ptr; + + platform_device_put(pdev); +} + +static void kunit_action_platform_device_del(void *ptr) +{ + struct platform_device *pdev = ptr; + + platform_device_del(pdev); +} + /** * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test * @test: The test context object @@ -35,8 +57,8 @@ static struct platform_driver fake_platform_driver = { * able to leverage the usual infrastructure and most notably the * device-managed resources just like a "real" device. * - * Callers need to make sure drm_kunit_helper_free_device() on the - * device when done. + * Resources will be cleaned up automatically, but the removal can be + * forced using @drm_kunit_helper_free_device. * * Returns: * A pointer to the new device, or an ERR_PTR() otherwise. @@ -49,12 +71,27 @@ struct device *drm_kunit_helper_alloc_device(struct kunit *test) ret = platform_driver_register(&fake_platform_driver); KUNIT_ASSERT_EQ(test, ret, 0); + ret = kunit_add_action_or_reset(test, + kunit_action_platform_driver_unregister, + &fake_platform_driver); + KUNIT_ASSERT_EQ(test, ret, 0); + pdev = platform_device_alloc(KUNIT_DEVICE_NAME, PLATFORM_DEVID_NONE); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); + ret = kunit_add_action_or_reset(test, + kunit_action_platform_device_put, + pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + ret = platform_device_add(pdev); KUNIT_ASSERT_EQ(test, ret, 0); + ret = kunit_add_action_or_reset(test, + kunit_action_platform_device_del, + pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + return &pdev->dev; } EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device); @@ -70,8 +107,17 @@ void drm_kunit_helper_free_device(struct kunit *test, struct device *dev) { struct platform_device *pdev = to_platform_device(dev); - platform_device_unregister(pdev); - platform_driver_unregister(&fake_platform_driver); + kunit_release_action(test, + kunit_action_platform_device_del, + pdev); + + kunit_release_action(test, + kunit_action_platform_device_put, + pdev); + + kunit_release_action(test, + kunit_action_platform_driver_unregister, + pdev); } EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);