|
3 | 3 | #ifndef DRM_KUNIT_HELPERS_H_
|
4 | 4 | #define DRM_KUNIT_HELPERS_H_
|
5 | 5 |
|
| 6 | +#include <kunit/test.h> |
| 7 | + |
6 | 8 | struct drm_device;
|
7 | 9 | struct kunit;
|
8 | 10 |
|
9 | 11 | struct device *drm_kunit_helper_alloc_device(struct kunit *test);
|
10 | 12 | void drm_kunit_helper_free_device(struct kunit *test, struct device *dev);
|
11 | 13 |
|
12 | 14 | struct drm_device *
|
13 |
| -__drm_kunit_helper_alloc_drm_device(struct kunit *test, struct device *dev, |
| 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 | + |
| 46 | +static inline struct drm_device * |
| 47 | +__drm_kunit_helper_alloc_drm_device(struct kunit *test, |
| 48 | + struct device *dev, |
14 | 49 | size_t size, size_t offset,
|
15 |
| - u32 features); |
| 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 | +} |
16 | 63 |
|
17 | 64 | /**
|
18 | 65 | * drm_kunit_helper_alloc_drm_device - Allocates a mock DRM device for KUnit tests
|
|
0 commit comments