Merge tag 'vfs/v6.4-rc1/pipe' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs
[linux-block.git] / include / drm / drm_kunit_helpers.h
CommitLineData
35c3a2d0
MR
1// SPDX-License-Identifier: GPL-2.0
2
44a39283
MR
3#ifndef DRM_KUNIT_HELPERS_H_
4#define DRM_KUNIT_HELPERS_H_
5
d9878031
MR
6#include <kunit/test.h>
7
44a39283
MR
8struct drm_device;
9struct kunit;
10
9ecd8045
MR
11struct device *drm_kunit_helper_alloc_device(struct kunit *test);
12void drm_kunit_helper_free_device(struct kunit *test, struct device *dev);
13
83ee69a8 14struct drm_device *
d9878031
MR
15__drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test,
16 struct device *dev,
17 size_t size, size_t offset,
18 const struct drm_driver *driver);
19
20/**
21 * drm_kunit_helper_alloc_drm_device_with_driver - Allocates a mock DRM device for KUnit tests
22 * @_test: The test context object
23 * @_dev: The parent device object
24 * @_type: the type of the struct which contains struct &drm_device
25 * @_member: the name of the &drm_device within @_type.
26 * @_drv: Mocked DRM device driver features
27 *
28 * This function creates a struct &drm_device from @_dev and @_drv.
29 *
30 * @_dev should be allocated using drm_kunit_helper_alloc_device().
31 *
32 * The driver is tied to the @_test context and will get cleaned at the
33 * end of the test. The drm_device is allocated through
34 * devm_drm_dev_alloc() and will thus be freed through a device-managed
35 * resource.
36 *
37 * Returns:
38 * A pointer to the new drm_device, or an ERR_PTR() otherwise.
39 */
40#define drm_kunit_helper_alloc_drm_device_with_driver(_test, _dev, _type, _member, _drv) \
41 ((_type *)__drm_kunit_helper_alloc_drm_device_with_driver(_test, _dev, \
42 sizeof(_type), \
43 offsetof(_type, _member), \
44 _drv))
45
46static inline struct drm_device *
47__drm_kunit_helper_alloc_drm_device(struct kunit *test,
48 struct device *dev,
a9143c58 49 size_t size, size_t offset,
d9878031
MR
50 u32 features)
51{
52 struct drm_driver *driver;
53
54 driver = kunit_kzalloc(test, sizeof(*driver), GFP_KERNEL);
55 KUNIT_ASSERT_NOT_NULL(test, driver);
56
57 driver->driver_features = features;
58
59 return __drm_kunit_helper_alloc_drm_device_with_driver(test, dev,
60 size, offset,
61 driver);
62}
a9143c58
MR
63
64/**
65 * drm_kunit_helper_alloc_drm_device - Allocates a mock DRM device for KUnit tests
66 * @_test: The test context object
67 * @_dev: The parent device object
68 * @_type: the type of the struct which contains struct &drm_device
69 * @_member: the name of the &drm_device within @_type.
70 * @_features: Mocked DRM device driver features
71 *
72 * This function creates a struct &drm_driver and will create a struct
73 * &drm_device from @_dev and that driver.
74 *
75 * @_dev should be allocated using drm_kunit_helper_alloc_device().
76 *
77 * The driver is tied to the @_test context and will get cleaned at the
78 * end of the test. The drm_device is allocated through
79 * devm_drm_dev_alloc() and will thus be freed through a device-managed
80 * resource.
81 *
82 * Returns:
83 * A pointer to the new drm_device, or an ERR_PTR() otherwise.
84 */
85#define drm_kunit_helper_alloc_drm_device(_test, _dev, _type, _member, _feat) \
86 ((_type *)__drm_kunit_helper_alloc_drm_device(_test, _dev, \
87 sizeof(_type), \
88 offsetof(_type, _member), \
89 _feat))
44a39283
MR
90
91#endif // DRM_KUNIT_HELPERS_H_