Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/tests: Add Kunit Helpers

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.

Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
Link: https://lore.kernel.org/r/20220728-rpi-analog-tv-properties-v9-2-24b168e5bcd5@cerno.tech
Signed-off-by: Maxime Ripard <maxime@cerno.tech>

+74
+1
drivers/gpu/drm/tests/Makefile
··· 8 8 drm_format_helper_test.o \ 9 9 drm_format_test.o \ 10 10 drm_framebuffer_test.o \ 11 + drm_kunit_helpers.o \ 11 12 drm_mm_test.o \ 12 13 drm_plane_helper_test.o \ 13 14 drm_rect_test.o
+64
drivers/gpu/drm/tests/drm_kunit_helpers.c
··· 1 + #include <drm/drm_drv.h> 2 + #include <drm/drm_managed.h> 3 + 4 + #include <kunit/resource.h> 5 + 6 + #include <linux/device.h> 7 + 8 + struct kunit_dev { 9 + struct drm_device base; 10 + }; 11 + 12 + static const struct drm_mode_config_funcs drm_mode_config_funcs = { 13 + }; 14 + 15 + static int dev_init(struct kunit_resource *res, void *ptr) 16 + { 17 + char *name = ptr; 18 + struct device *dev; 19 + 20 + dev = root_device_register(name); 21 + if (IS_ERR(dev)) 22 + return PTR_ERR(dev); 23 + 24 + res->data = dev; 25 + return 0; 26 + } 27 + 28 + static void dev_free(struct kunit_resource *res) 29 + { 30 + struct device *dev = res->data; 31 + 32 + root_device_unregister(dev); 33 + } 34 + 35 + struct drm_device *drm_kunit_device_init(struct kunit *test, u32 features, char *name) 36 + { 37 + struct kunit_dev *kdev; 38 + struct drm_device *drm; 39 + struct drm_driver *driver; 40 + struct device *dev; 41 + int ret; 42 + 43 + dev = kunit_alloc_resource(test, dev_init, dev_free, GFP_KERNEL, name); 44 + if (!dev) 45 + return ERR_PTR(-ENOMEM); 46 + 47 + driver = kunit_kzalloc(test, sizeof(*driver), GFP_KERNEL); 48 + if (!driver) 49 + return ERR_PTR(-ENOMEM); 50 + 51 + driver->driver_features = features; 52 + kdev = devm_drm_dev_alloc(dev, driver, struct kunit_dev, base); 53 + if (IS_ERR(kdev)) 54 + return ERR_CAST(kdev); 55 + 56 + drm = &kdev->base; 57 + drm->mode_config.funcs = &drm_mode_config_funcs; 58 + 59 + ret = drmm_mode_config_init(drm); 60 + if (ret) 61 + return ERR_PTR(ret); 62 + 63 + return drm; 64 + }
+9
drivers/gpu/drm/tests/drm_kunit_helpers.h
··· 1 + #ifndef DRM_KUNIT_HELPERS_H_ 2 + #define DRM_KUNIT_HELPERS_H_ 3 + 4 + struct drm_device; 5 + struct kunit; 6 + 7 + struct drm_device *drm_kunit_device_init(struct kunit *test, u32 features, char *name); 8 + 9 + #endif // DRM_KUNIT_HELPERS_H_