1 From 51e89f803856386ebecef22453ab34907a393954 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 21 Nov 2022 13:18:29 +0100
4 Subject: [PATCH] drm/tests: helpers: Make sure the device is bound
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 The device managed resources are freed when the device is detached, so
10 it has to be bound in the first place.
12 Let's create a fake driver that we will bind to our fake device to
13 benefit from the device managed cleanups in our tests.
15 Reviewed-by: MaĆra Canal <mcanal@igalia.com>
16 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
18 drivers/gpu/drm/tests/drm_kunit_helpers.c | 26 ++++++++++++++++++++++-
19 1 file changed, 25 insertions(+), 1 deletion(-)
21 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
22 +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
23 @@ -18,12 +18,32 @@ struct kunit_dev {
24 static const struct drm_mode_config_funcs drm_mode_config_funcs = {
27 +static int fake_probe(struct platform_device *pdev)
32 +static int fake_remove(struct platform_device *pdev)
37 +static struct platform_driver fake_platform_driver = {
38 + .probe = fake_probe,
39 + .remove = fake_remove,
41 + .name = KUNIT_DEVICE_NAME,
46 * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
47 * @test: The test context object
49 * This allocates a fake struct &device to create a mock for a KUnit
51 + * test. The device will also be bound to a fake driver. It will thus be
52 + * able to leverage the usual infrastructure and most notably the
53 + * device-managed resources just like a "real" device.
55 * Callers need to make sure drm_kunit_helper_free_device() on the
57 @@ -36,6 +56,9 @@ struct device *drm_kunit_helper_alloc_de
58 struct platform_device *pdev;
61 + ret = platform_driver_register(&fake_platform_driver);
62 + KUNIT_ASSERT_EQ(test, ret, 0);
64 pdev = platform_device_alloc(KUNIT_DEVICE_NAME, PLATFORM_DEVID_NONE);
65 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
67 @@ -58,6 +81,7 @@ void drm_kunit_helper_free_device(struct
68 struct platform_device *pdev = to_platform_device(dev);
70 platform_device_unregister(pdev);
71 + platform_driver_unregister(&fake_platform_driver);
73 EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);