From patchwork Fri Mar 17 14:41:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13179123 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 50B52C74A5B for ; Fri, 17 Mar 2023 14:41:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6997610E38B; Fri, 17 Mar 2023 14:41:46 +0000 (UTC) Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 095AC10E38B for ; Fri, 17 Mar 2023 14:41:45 +0000 (UTC) Received: by mail-lf1-x12d.google.com with SMTP id x17so6767926lfu.5 for ; Fri, 17 Mar 2023 07:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679064103; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=voAKQ3WGCeTkXYK2HgOGiBs7zBasJeDeL3Ew5RR80Fo=; b=dmHVDP7L4ERSg8EX1AnfG1RtU7LykXB8+MYj1A6GJvnhbd6nlvGI12KndfuPvM96Vm 6IndSgb/TPB+NWJYVOsQygy7QOrEpOPCKXY4CXzRuRqbbP5/1vm9u51hop11TG6LwKjY W+KGpRLXdB7aCIgBJ8NAonMgCsYU2sEHiPrR8OZwPVeK2okMl9PE8oMfZaX88ajUUDIJ jMXyGWqP0qB/af+LIWtwcu2evJLu2cs9K8tyHyTuwy5KN1VvyfMZAAltPF2zvC2PJE7v GicRTK1Wjs31qQ0XiEhjtd9KLM0aPdh48Yn4a/kHnvLN3l9k/C04Ysg0okJzCRg2Z+ml UMjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679064103; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=voAKQ3WGCeTkXYK2HgOGiBs7zBasJeDeL3Ew5RR80Fo=; b=l9Le3ykU/SVZa8isfE9b7dZOMD2Ve3bRrVhWNqESvNdELlyTfB8FMQcgVa1uySDw4X EO3u1pKJixmD2tGzxvBRVkMsFdWLr90SySFqUKqy/LPCnU4SzY0GAVCmeNCOWD+Kp69d bduFyqrkYarID4gUY97b10eX84uxwDwHddWEtl1iFP6TAO0xKecnJeOfwQjIYit8Xzxm slPHTgUJ8yV3iOJKANNXnxP8RxpFq2pTHy8a4Qci6cLCeEc6A93feebv1hE17bhPBNNd 1rxcbeYCKRj+dQLDKRDHtHEzt/PyoLUTT74e6yihtjEGsliiiiTP+mfqgcCBGT3+b0Q9 NyhA== X-Gm-Message-State: AO0yUKUcILMjINx4Zca2rBcjPM9s8Vj+1aWoO3eo8JdB9jP8wvjWqEL+ TwCasC55N2Fgk72mZpa7vDI= X-Google-Smtp-Source: AK7set/5DKeTmhFYs98YUxLBeNsjnzd1MIj3hXD8RQV2Z+qSvpfMCNIfzT1xMkNzROt3mV0YQISvXg== X-Received: by 2002:ac2:446f:0:b0:4b0:1305:6e02 with SMTP id y15-20020ac2446f000000b004b013056e02mr4026129lfl.8.1679064103061; Fri, 17 Mar 2023 07:41:43 -0700 (PDT) Received: from fedora ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id b6-20020a056512218600b004e8452972a2sm391958lft.247.2023.03.17.07.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 07:41:42 -0700 (PDT) Date: Fri, 17 Mar 2023 16:41:26 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Subject: [PATCH v4 1/8] drm/tests: helpers: rename generic helpers Message-ID: <15d07e799f7c7fddc91030b16266d4a8bbaf1cc1.1679062529.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: Thomas Zimmermann , Emma Anholt , Matti Vaittinen , Stephen Boyd , =?iso-8859-1?q?Ma=EDra?= Canal , Javier Martinez Canillas , linux-kernel@vger.kernel.org, Noralf =?iso-8859-1?q?Tr=F8nnes?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The creation of a dummy device in order to test managed interfaces is a generally useful test feature. The drm test helpers drm_kunit_helper_alloc_device() and drm_kunit_helper_free_device() are doing exactly this. It makes no sense that each and every component which intends to be testing managed interfaces will create similar helpers so rename these to more generic format. Signed-off-by: Matti Vaittinen --- drivers/gpu/drm/tests/drm_client_modeset_test.c | 4 ++-- drivers/gpu/drm/tests/drm_kunit_helpers.c | 16 ++++++++-------- drivers/gpu/drm/tests/drm_managed_test.c | 4 ++-- drivers/gpu/drm/tests/drm_modes_test.c | 4 ++-- drivers/gpu/drm/tests/drm_probe_helper_test.c | 4 ++-- drivers/gpu/drm/vc4/tests/vc4_mock.c | 2 +- drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 8 ++++---- include/drm/drm_kunit_helpers.h | 8 ++++---- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c index 416a279b6dae..27ab03d1c518 100644 --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -60,7 +60,7 @@ static int drm_client_modeset_test_init(struct kunit *test) test->priv = priv; - priv->dev = drm_kunit_helper_alloc_device(test); + priv->dev = test_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev, @@ -86,7 +86,7 @@ static void drm_client_modeset_test_exit(struct kunit *test) { struct drm_client_modeset_test_priv *priv = test->priv; - drm_kunit_helper_free_device(test, priv->dev); + test_kunit_helper_free_device(test, priv->dev); } static void drm_test_pick_cmdline_res_1920_1080_60(struct kunit *test) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index e98b4150f556..ec93b0300f03 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -33,7 +33,7 @@ static struct platform_driver fake_platform_driver = { }; /** - * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test + * test_kunit_helper_alloc_device - Allocate a mock device for a KUnit test * @test: The test context object * * This allocates a fake struct &device to create a mock for a KUnit @@ -41,13 +41,13 @@ 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 + * Callers need to make sure test_kunit_helper_free_device() on the * device when done. * * Returns: * A pointer to the new device, or an ERR_PTR() otherwise. */ -struct device *drm_kunit_helper_alloc_device(struct kunit *test) +struct device *test_kunit_helper_alloc_device(struct kunit *test) { struct platform_device *pdev; int ret; @@ -63,23 +63,23 @@ struct device *drm_kunit_helper_alloc_device(struct kunit *test) return &pdev->dev; } -EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device); +EXPORT_SYMBOL_GPL(test_kunit_helper_alloc_device); /** - * drm_kunit_helper_free_device - Frees a mock device + * test_kunit_helper_free_device - Frees a mock device * @test: The test context object * @dev: The device to free * - * Frees a device allocated with drm_kunit_helper_alloc_device(). + * Frees a device allocated with test_kunit_helper_alloc_device(). */ -void drm_kunit_helper_free_device(struct kunit *test, struct device *dev) +void test_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); } -EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device); +EXPORT_SYMBOL_GPL(test_kunit_helper_free_device); struct drm_device * __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c index 1652dca11d30..53f870493577 100644 --- a/drivers/gpu/drm/tests/drm_managed_test.c +++ b/drivers/gpu/drm/tests/drm_managed_test.c @@ -35,7 +35,7 @@ static void drm_test_managed_run_action(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); init_waitqueue_head(&priv->action_wq); - dev = drm_kunit_helper_alloc_device(test); + dev = test_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET); @@ -48,7 +48,7 @@ static void drm_test_managed_run_action(struct kunit *test) KUNIT_ASSERT_EQ(test, ret, 0); drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, dev); + test_kunit_helper_free_device(test, dev); ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done, msecs_to_jiffies(TEST_TIMEOUT_MS)); diff --git a/drivers/gpu/drm/tests/drm_modes_test.c b/drivers/gpu/drm/tests/drm_modes_test.c index bc4aa2ce78be..1bd8540086e9 100644 --- a/drivers/gpu/drm/tests/drm_modes_test.c +++ b/drivers/gpu/drm/tests/drm_modes_test.c @@ -23,7 +23,7 @@ static int drm_test_modes_init(struct kunit *test) priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); KUNIT_ASSERT_NOT_NULL(test, priv); - priv->dev = drm_kunit_helper_alloc_device(test); + priv->dev = test_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev, @@ -40,7 +40,7 @@ static void drm_test_modes_exit(struct kunit *test) { struct drm_test_modes_priv *priv = test->priv; - drm_kunit_helper_free_device(test, priv->dev); + test_kunit_helper_free_device(test, priv->dev); } static void drm_test_modes_analog_tv_ntsc_480i(struct kunit *test) diff --git a/drivers/gpu/drm/tests/drm_probe_helper_test.c b/drivers/gpu/drm/tests/drm_probe_helper_test.c index 0ee65828623e..bc4b271bec09 100644 --- a/drivers/gpu/drm/tests/drm_probe_helper_test.c +++ b/drivers/gpu/drm/tests/drm_probe_helper_test.c @@ -40,7 +40,7 @@ static int drm_probe_helper_test_init(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, priv); test->priv = priv; - priv->dev = drm_kunit_helper_alloc_device(test); + priv->dev = test_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev, @@ -64,7 +64,7 @@ static void drm_probe_helper_test_exit(struct kunit *test) { struct drm_probe_helper_test_priv *priv = test->priv; - drm_kunit_helper_free_device(test, priv->dev); + test_kunit_helper_free_device(test, priv->dev); } typedef struct drm_display_mode *(*expected_mode_func_t)(struct drm_device *); diff --git a/drivers/gpu/drm/vc4/tests/vc4_mock.c b/drivers/gpu/drm/vc4/tests/vc4_mock.c index a4bed26af32f..5bb1fa828a3f 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_mock.c +++ b/drivers/gpu/drm/vc4/tests/vc4_mock.c @@ -162,7 +162,7 @@ static struct vc4_dev *__mock_device(struct kunit *test, bool is_vc5) struct device *dev; int ret; - dev = drm_kunit_helper_alloc_device(test); + dev = test_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); vc4 = drm_kunit_helper_alloc_drm_device_with_driver(test, dev, diff --git a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c index ae0bd0f81698..8b373fa76d6f 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c +++ b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c @@ -762,7 +762,7 @@ static void vc4_pv_muxing_test_exit(struct kunit *test) drm_modeset_drop_locks(&priv->ctx); drm_modeset_acquire_fini(&priv->ctx); drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, vc4->dev); + test_kunit_helper_free_device(test, vc4->dev); } static struct kunit_case vc4_pv_muxing_tests[] = { @@ -873,7 +873,7 @@ static void drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable(struct kunit *tes drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, vc4->dev); + test_kunit_helper_free_device(test, vc4->dev); } static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test) @@ -963,7 +963,7 @@ static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test) drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, vc4->dev); + test_kunit_helper_free_device(test, vc4->dev); } static void @@ -1017,7 +1017,7 @@ drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state(struct ku drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, vc4->dev); + test_kunit_helper_free_device(test, vc4->dev); } static struct kunit_case vc5_pv_muxing_bugs_tests[] = { diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index ed013fdcc1ff..8e3aae6a5ed5 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -8,8 +8,8 @@ struct drm_device; struct kunit; -struct device *drm_kunit_helper_alloc_device(struct kunit *test); -void drm_kunit_helper_free_device(struct kunit *test, struct device *dev); +struct device *test_kunit_helper_alloc_device(struct kunit *test); +void test_kunit_helper_free_device(struct kunit *test, struct device *dev); struct drm_device * __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, @@ -27,7 +27,7 @@ __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, * * This function creates a struct &drm_device from @_dev and @_drv. * - * @_dev should be allocated using drm_kunit_helper_alloc_device(). + * @_dev should be allocated using test_kunit_helper_alloc_device(). * * The driver is tied to the @_test context and will get cleaned at the * end of the test. The drm_device is allocated through @@ -72,7 +72,7 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test, * This function creates a struct &drm_driver and will create a struct * &drm_device from @_dev and that driver. * - * @_dev should be allocated using drm_kunit_helper_alloc_device(). + * @_dev should be allocated using test_kunit_helper_alloc_device(). * * The driver is tied to the @_test context and will get cleaned at the * end of the test. The drm_device is allocated through From patchwork Fri Mar 17 14:42:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13179124 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 3EC5AC6FD1D for ; Fri, 17 Mar 2023 14:42:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 55BAA10E39C; Fri, 17 Mar 2023 14:42:42 +0000 (UTC) Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by gabe.freedesktop.org (Postfix) with ESMTPS id 673A610E39C for ; Fri, 17 Mar 2023 14:42:40 +0000 (UTC) Received: by mail-lj1-x231.google.com with SMTP id x36so5328520ljq.7 for ; Fri, 17 Mar 2023 07:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679064158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=UGy7oNS94ufYKednhkXhlJ35f2xeVGrjXtmL/TmdAmU=; b=UGEIY1Truue6z82ReZqcgi14hxPvGrZO5KlhxsHlIX6C1wTBXMm2obt2RCu4mK5BiD V9YDocoX8kwS0N2Ob6lozTqfoKLxuBSvOhP9AnvnVwq1k+AwqvK2Q+zYfP5KdXKVgC8w q5FSfwkdW8zPo3Owai1Voz1u/gDO8sJ2PZOxe53V3b+9uNVgxo/xggHe1XmqUfxHq+vF fQ26riHH/IX5JnZAHKJMq/SlqRAG/pvv1Yjp8KK8FVTmo348bo0N6burD62msiM6qUXO fg5hRWjVAJg3xPElpIIXmoiVG7XtaUMq/NXoeyqjBlu6X4N4Q46nxiJnwNprHezKlw2n SBDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679064158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UGy7oNS94ufYKednhkXhlJ35f2xeVGrjXtmL/TmdAmU=; b=ABiL+H2qFUyN+CE9PTKnFJjzhyx2KjnNUVjt0g6LFYe4o8VhCE4wu0KQwIIe9H3uli hCP6OH1OtR2gTJ74U5ZoXGj2ah1Ou3p3BCi3I7VnbZLcQOu127d897gzDmXt+yPYtHKf LvkVZap0gviaFQnZWStwRfw7T8i1fp9PLU1DcjmmkKXQGpY528b45DHMUkfs3zKzZygN XvlF+J3ZmoTuwravG9C7p0f3yEWY32g8nn3iR4RXNgMYErvhGwez5DzUY9pHQegoZBEZ 0Y4mm6mZOM7Lm6OYw1ILraKdS3TsMcEQI8eNxo66QV7N/Jmz5CulAXfdmBvlQEprUIOV CDMg== X-Gm-Message-State: AO0yUKWFwlWCEfWySk+7kIhZal2hTdNljc0E/2ffMdNkSk8DwMOyeBtu YH6v+Rbf6GAEbPqDix/lLvk= X-Google-Smtp-Source: AK7set9S6DHfGamLo7j9AmtJ+HWLFQ3IYF0aIIPJRIhXyv/QP/zTwC+8n4viSNWjbSlMUZwZdnCtOg== X-Received: by 2002:a05:651c:19a7:b0:298:a124:dd8c with SMTP id bx39-20020a05651c19a700b00298a124dd8cmr4534321ljb.38.1679064158295; Fri, 17 Mar 2023 07:42:38 -0700 (PDT) Received: from fedora ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id c14-20020a2e680e000000b00295735991edsm438209lja.38.2023.03.17.07.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 07:42:37 -0700 (PDT) Date: Fri, 17 Mar 2023 16:42:25 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Subject: [PATCH v4 2/8] kunit: drm/tests: move generic helpers Message-ID: <1abd47784b08939ff08ff03d3d4f60449e87625f.1679062529.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: Heikki Krogerus , Emma Anholt , "Rafael J. Wysocki" , Stephen Boyd , Greg Kroah-Hartman , Matti Vaittinen , Javier Martinez Canillas , linux-kernel@vger.kernel.org, =?iso-8859-1?q?Ma=EDra?= Canal , Noralf =?iso-8859-1?q?T?= =?iso-8859-1?q?r=F8nnes?= , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Andy Shevchenko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The creation of a dummy device in order to test managed interfaces is a generally useful test feature. The drm test helpers test_kunit_helper_alloc_device() and test_kunit_helper_free_device() are doing exactly this. It makes no sense that each and every component which intends to be testing managed interfaces will create similar helpers. Move these functions to place where it is more obvious they can be used also by other subsystems but drm. Signed-off-by: Matti Vaittinen --- Please note that there's something similat ongoing in the CCF: https://lore.kernel.org/all/20230302013822.1808711-1-sboyd@kernel.org/ I do like the simplicity of these DRM-originated helpers so I think they're worth. I do equally like the Stephen's idea of having the "dummy platform device" related helpers under drivers/base and the header being in include/kunit/platform_device.h which is similar to real platform device under include/linux/platform_device.h - so, in the end of the day I hope Stephen's changes as well as the changes this patch introduces to end up in those files. This, however, will require some co-operation to avoid conflicts. --- drivers/base/test/Kconfig | 5 ++ drivers/base/test/Makefile | 2 + drivers/base/test/test_kunit_device.c | 83 +++++++++++++++++++ drivers/gpu/drm/Kconfig | 2 + .../gpu/drm/tests/drm_client_modeset_test.c | 1 + drivers/gpu/drm/tests/drm_kunit_helpers.c | 69 --------------- drivers/gpu/drm/tests/drm_managed_test.c | 1 + drivers/gpu/drm/tests/drm_modes_test.c | 1 + drivers/gpu/drm/tests/drm_probe_helper_test.c | 1 + drivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/tests/vc4_mock.c | 1 + .../gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 1 + include/drm/drm_kunit_helpers.h | 3 - 13 files changed, 99 insertions(+), 72 deletions(-) create mode 100644 drivers/base/test/test_kunit_device.c diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig index 610a1ba7a467..642b5b183c10 100644 --- a/drivers/base/test/Kconfig +++ b/drivers/base/test/Kconfig @@ -1,4 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 + +config TEST_KUNIT_DEVICE_HELPERS + depends on KUNIT + tristate + config TEST_ASYNC_DRIVER_PROBE tristate "Build kernel module to test asynchronous driver probing" depends on m diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile index 7f76fee6f989..49926524ec6f 100644 --- a/drivers/base/test/Makefile +++ b/drivers/base/test/Makefile @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o +obj-$(CONFIG_TEST_KUNIT_DEVICE_HELPERS) += test_kunit_device.o + obj-$(CONFIG_DRIVER_PE_KUNIT_TEST) += property-entry-test.o CFLAGS_property-entry-test.o += $(DISABLE_STRUCTLEAK_PLUGIN) diff --git a/drivers/base/test/test_kunit_device.c b/drivers/base/test/test_kunit_device.c new file mode 100644 index 000000000000..75790e15b85c --- /dev/null +++ b/drivers/base/test/test_kunit_device.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * These helpers have been extracted from drm test code at + * drm_kunit_helpers.c which was authored by + * Maxime Ripard + */ + +#include +#include + +#include + +#define KUNIT_DEVICE_NAME "test-kunit-mock-device" + +static int fake_probe(struct platform_device *pdev) +{ + return 0; +} + +static int fake_remove(struct platform_device *pdev) +{ + return 0; +} + +static struct platform_driver fake_platform_driver = { + .probe = fake_probe, + .remove = fake_remove, + .driver = { + .name = KUNIT_DEVICE_NAME, + }, +}; + +/** + * test_kunit_helper_alloc_device - Allocate a mock device for a KUnit test + * @test: The test context object + * + * This allocates a fake struct &device to create a mock for a KUnit + * test. The device will also be bound to a fake driver. It will thus be + * able to leverage the usual infrastructure and most notably the + * device-managed resources just like a "real" device. + * + * Callers need to make sure test_kunit_helper_free_device() on the + * device when done. + * + * Returns: + * A pointer to the new device, or an ERR_PTR() otherwise. + */ +struct device *test_kunit_helper_alloc_device(struct kunit *test) +{ + struct platform_device *pdev; + int ret; + + ret = platform_driver_register(&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 = platform_device_add(pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + + return &pdev->dev; +} +EXPORT_SYMBOL_GPL(test_kunit_helper_alloc_device); + +/** + * test_kunit_helper_free_device - Frees a mock device + * @test: The test context object + * @dev: The device to free + * + * Frees a device allocated with test_kunit_helper_alloc_device(). + */ +void test_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); +} +EXPORT_SYMBOL_GPL(test_kunit_helper_free_device); + +MODULE_AUTHOR("Matti Vaittinen "); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index dc0f94f02a82..0ee8ebe64f57 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -66,6 +66,7 @@ config DRM_USE_DYNAMIC_DEBUG config DRM_KUNIT_TEST_HELPERS tristate depends on DRM && KUNIT + select TEST_KUNIT_DEVICE_HELPERS help KUnit Helpers for KMS drivers. @@ -80,6 +81,7 @@ config DRM_KUNIT_TEST select DRM_BUDDY select DRM_EXPORT_FOR_TESTS if m select DRM_KUNIT_TEST_HELPERS + select TEST_KUNIT_DEVICE_HELPERS default KUNIT_ALL_TESTS help This builds unit tests for DRM. This option is not useful for diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c index 27ab03d1c518..d7eaa0938eb4 100644 --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -3,6 +3,7 @@ * Copyright (c) 2022 Maxime Ripard */ +#include #include #include diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index ec93b0300f03..ae84d0ed8744 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -9,78 +9,9 @@ #include #include -#define KUNIT_DEVICE_NAME "drm-kunit-mock-device" - static const struct drm_mode_config_funcs drm_mode_config_funcs = { }; -static int fake_probe(struct platform_device *pdev) -{ - return 0; -} - -static int fake_remove(struct platform_device *pdev) -{ - return 0; -} - -static struct platform_driver fake_platform_driver = { - .probe = fake_probe, - .remove = fake_remove, - .driver = { - .name = KUNIT_DEVICE_NAME, - }, -}; - -/** - * test_kunit_helper_alloc_device - Allocate a mock device for a KUnit test - * @test: The test context object - * - * This allocates a fake struct &device to create a mock for a KUnit - * test. The device will also be bound to a fake driver. It will thus be - * able to leverage the usual infrastructure and most notably the - * device-managed resources just like a "real" device. - * - * Callers need to make sure test_kunit_helper_free_device() on the - * device when done. - * - * Returns: - * A pointer to the new device, or an ERR_PTR() otherwise. - */ -struct device *test_kunit_helper_alloc_device(struct kunit *test) -{ - struct platform_device *pdev; - int ret; - - ret = platform_driver_register(&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 = platform_device_add(pdev); - KUNIT_ASSERT_EQ(test, ret, 0); - - return &pdev->dev; -} -EXPORT_SYMBOL_GPL(test_kunit_helper_alloc_device); - -/** - * test_kunit_helper_free_device - Frees a mock device - * @test: The test context object - * @dev: The device to free - * - * Frees a device allocated with test_kunit_helper_alloc_device(). - */ -void test_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); -} -EXPORT_SYMBOL_GPL(test_kunit_helper_free_device); - struct drm_device * __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, struct device *dev, diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c index 53f870493577..6b39d2cde164 100644 --- a/drivers/gpu/drm/tests/drm_managed_test.c +++ b/drivers/gpu/drm/tests/drm_managed_test.c @@ -4,6 +4,7 @@ #include #include +#include #include #include diff --git a/drivers/gpu/drm/tests/drm_modes_test.c b/drivers/gpu/drm/tests/drm_modes_test.c index 1bd8540086e9..addc4d923a26 100644 --- a/drivers/gpu/drm/tests/drm_modes_test.c +++ b/drivers/gpu/drm/tests/drm_modes_test.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/drivers/gpu/drm/tests/drm_probe_helper_test.c b/drivers/gpu/drm/tests/drm_probe_helper_test.c index bc4b271bec09..f23213464d34 100644 --- a/drivers/gpu/drm/tests/drm_probe_helper_test.c +++ b/drivers/gpu/drm/tests/drm_probe_helper_test.c @@ -13,6 +13,7 @@ #include #include +#include #include struct drm_probe_helper_test_priv { diff --git a/drivers/gpu/drm/vc4/Kconfig b/drivers/gpu/drm/vc4/Kconfig index 91dcf8d174d6..a4bd96445315 100644 --- a/drivers/gpu/drm/vc4/Kconfig +++ b/drivers/gpu/drm/vc4/Kconfig @@ -39,6 +39,7 @@ config DRM_VC4_KUNIT_TEST tristate "KUnit tests for VC4" if !KUNIT_ALL_TESTS depends on DRM_VC4 && KUNIT select DRM_KUNIT_TEST_HELPERS + select TEST_KUNIT_DEVICE_HELPERS default KUNIT_ALL_TESTS help This builds unit tests for the VC4 DRM/KMS driver. This option is diff --git a/drivers/gpu/drm/vc4/tests/vc4_mock.c b/drivers/gpu/drm/vc4/tests/vc4_mock.c index 5bb1fa828a3f..29eb045b0db1 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_mock.c +++ b/drivers/gpu/drm/vc4/tests/vc4_mock.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "vc4_mock.h" diff --git a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c index 8b373fa76d6f..64b90e2e3706 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c +++ b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c @@ -12,6 +12,7 @@ #include #include +#include #include #include "../vc4_drv.h" diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index 8e3aae6a5ed5..ab438d97aed3 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -8,9 +8,6 @@ struct drm_device; struct kunit; -struct device *test_kunit_helper_alloc_device(struct kunit *test); -void test_kunit_helper_free_device(struct kunit *test, struct device *dev); - struct drm_device * __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, struct device *dev,