diff mbox series

[v4,5/5] drm/tests: Switch to kunit devices

Message ID 20231215-kunit_bus-v4-5-4f5160e2f95e@google.com (mailing list archive)
State Mainlined
Commit d393acce7b3f046a1086362317a05f2cac01fa89
Headers show
Series kunit: Add helpers for creating test-managed devices | expand

Commit Message

David Gow Dec. 15, 2023, 7:39 a.m. UTC
From: Maxime Ripard <mripard@kernel.org>

Kunit recently gained helpers to create test managed devices. This means
that we no longer have to roll our own helpers in KMS and we can reuse
them.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
Tested-by: David Gow <davidgow@google.com>
Signed-off-by: David Gow <davidgow@google.com>
---
 drivers/gpu/drm/tests/drm_kunit_helpers.c | 66 ++-----------------------------
 1 file changed, 3 insertions(+), 63 deletions(-)

Comments

Rae Moar Dec. 15, 2023, 10:48 p.m. UTC | #1
On Fri, Dec 15, 2023 at 2:39 AM <davidgow@google.com> wrote:
>
> From: Maxime Ripard <mripard@kernel.org>
>
> Kunit recently gained helpers to create test managed devices. This means
> that we no longer have to roll our own helpers in KMS and we can reuse
> them.

Hello!

This looks good to me. Thanks!

Reviewed-by: Rae Moar <rmoar@google.com>

-Rae

>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> Tested-by: David Gow <davidgow@google.com>
> Signed-off-by: David Gow <davidgow@google.com>
> ---
>  drivers/gpu/drm/tests/drm_kunit_helpers.c | 66 ++-----------------------------
>  1 file changed, 3 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c
> index c251e6b34de0..ca4f8e4c5d5d 100644
> --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
> +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
> @@ -5,6 +5,7 @@
>  #include <drm/drm_kunit_helpers.h>
>  #include <drm/drm_managed.h>
>
> +#include <kunit/device.h>
>  #include <kunit/resource.h>
>
>  #include <linux/device.h>
> @@ -15,28 +16,6 @@
>  static const struct drm_mode_config_funcs drm_mode_config_funcs = {
>  };
>
> -static int fake_probe(struct platform_device *pdev)
> -{
> -       return 0;
> -}
> -
> -static struct platform_driver fake_platform_driver = {
> -       .probe  = fake_probe,
> -       .driver = {
> -               .name   = KUNIT_DEVICE_NAME,
> -       },
> -};
> -
> -KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_driver_unregister,
> -                           platform_driver_unregister,
> -                           struct platform_driver *);
> -KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_put,
> -                           platform_device_put,
> -                           struct platform_device *);
> -KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del,
> -                           platform_device_del,
> -                           struct platform_device *);
> -
>  /**
>   * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
>   * @test: The test context object
> @@ -54,34 +33,7 @@ KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del,
>   */
>  struct device *drm_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);
> -
> -       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;
> +       return kunit_device_register(test, KUNIT_DEVICE_NAME);
>  }
>  EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
>
> @@ -94,19 +46,7 @@ EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
>   */
>  void drm_kunit_helper_free_device(struct kunit *test, struct device *dev)
>  {
> -       struct platform_device *pdev = to_platform_device(dev);
> -
> -       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,
> -                            &fake_platform_driver);
> +       kunit_device_unregister(test, dev);
>  }
>  EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);
>
>
> --
> 2.43.0.472.g3155946c3a-goog
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c
index c251e6b34de0..ca4f8e4c5d5d 100644
--- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
+++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
@@ -5,6 +5,7 @@ 
 #include <drm/drm_kunit_helpers.h>
 #include <drm/drm_managed.h>
 
+#include <kunit/device.h>
 #include <kunit/resource.h>
 
 #include <linux/device.h>
@@ -15,28 +16,6 @@ 
 static const struct drm_mode_config_funcs drm_mode_config_funcs = {
 };
 
-static int fake_probe(struct platform_device *pdev)
-{
-	return 0;
-}
-
-static struct platform_driver fake_platform_driver = {
-	.probe	= fake_probe,
-	.driver = {
-		.name	= KUNIT_DEVICE_NAME,
-	},
-};
-
-KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_driver_unregister,
-			    platform_driver_unregister,
-			    struct platform_driver *);
-KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_put,
-			    platform_device_put,
-			    struct platform_device *);
-KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del,
-			    platform_device_del,
-			    struct platform_device *);
-
 /**
  * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
  * @test: The test context object
@@ -54,34 +33,7 @@  KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del,
  */
 struct device *drm_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);
-
-	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;
+	return kunit_device_register(test, KUNIT_DEVICE_NAME);
 }
 EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
 
@@ -94,19 +46,7 @@  EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
  */
 void drm_kunit_helper_free_device(struct kunit *test, struct device *dev)
 {
-	struct platform_device *pdev = to_platform_device(dev);
-
-	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,
-			     &fake_platform_driver);
+	kunit_device_unregister(test, dev);
 }
 EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);