Skip to content

Commit 51f9072

Browse files
committed
drm/tests: Add helper to create mock crtc
We're going to need a full-blown, functional, KMS device to test more components of the atomic modesetting infrastructure. Let's add a new helper to create a dumb, mocked, CRTC. By default it will create a CRTC relying only on the default helpers, but drivers are free to deviate from that. Reviewed-by: Maíra Canal <mcanal@igalia.com> Signed-off-by: Maxime Ripard <mripard@kernel.org> Link: https://patchwork.freedesktop.org/patch/msgid/20240222-kms-hdmi-connector-state-v7-4-8f4af575fce2@kernel.org
1 parent 7a48da0 commit 51f9072

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

drivers/gpu/drm/tests/drm_kunit_helpers.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,67 @@ drm_kunit_helper_create_primary_plane(struct kunit *test,
249249
}
250250
EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane);
251251

252+
static const struct drm_crtc_helper_funcs default_crtc_helper_funcs = {
253+
};
254+
255+
static const struct drm_crtc_funcs default_crtc_funcs = {
256+
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
257+
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
258+
.reset = drm_atomic_helper_crtc_reset,
259+
};
260+
261+
/**
262+
* drm_kunit_helper_create_crtc - Creates a mock CRTC for a KUnit test
263+
* @test: The test context object
264+
* @drm: The device to alloc the plane for
265+
* @primary: Primary plane for CRTC
266+
* @cursor: Cursor plane for CRTC. Optional.
267+
* @funcs: Callbacks for the new plane. Optional.
268+
* @helper_funcs: Helpers callbacks for the new plane. Optional.
269+
*
270+
* This allocates and initializes a mock struct &drm_crtc meant to be
271+
* part of a mock device for a KUnit test.
272+
*
273+
* Resources will be cleaned up automatically.
274+
*
275+
* @funcs will default to the default helpers implementations.
276+
* @helper_funcs will default to an empty implementation.
277+
*
278+
* Returns:
279+
* A pointer to the new CRTC, or an ERR_PTR() otherwise.
280+
*/
281+
struct drm_crtc *
282+
drm_kunit_helper_create_crtc(struct kunit *test,
283+
struct drm_device *drm,
284+
struct drm_plane *primary,
285+
struct drm_plane *cursor,
286+
const struct drm_crtc_funcs *funcs,
287+
const struct drm_crtc_helper_funcs *helper_funcs)
288+
{
289+
struct drm_crtc *crtc;
290+
int ret;
291+
292+
if (!funcs)
293+
funcs = &default_crtc_funcs;
294+
295+
if (!helper_funcs)
296+
helper_funcs = &default_crtc_helper_funcs;
297+
298+
crtc = drmm_kzalloc(drm, sizeof(*crtc), GFP_KERNEL);
299+
KUNIT_ASSERT_NOT_NULL(test, crtc);
300+
301+
ret = drmm_crtc_init_with_planes(drm, crtc,
302+
primary,
303+
cursor,
304+
funcs,
305+
NULL);
306+
KUNIT_ASSERT_EQ(test, ret, 0);
307+
308+
drm_crtc_helper_add(crtc, helper_funcs);
309+
310+
return crtc;
311+
}
312+
EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc);
313+
252314
MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
253315
MODULE_LICENSE("GPL");

include/drm/drm_kunit_helpers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <kunit/test.h>
1111

12+
struct drm_crtc_funcs;
13+
struct drm_crtc_helper_funcs;
1214
struct drm_device;
1315
struct drm_plane_funcs;
1416
struct drm_plane_helper_funcs;
@@ -110,4 +112,12 @@ drm_kunit_helper_create_primary_plane(struct kunit *test,
110112
unsigned int num_formats,
111113
const uint64_t *modifiers);
112114

115+
struct drm_crtc *
116+
drm_kunit_helper_create_crtc(struct kunit *test,
117+
struct drm_device *drm,
118+
struct drm_plane *primary,
119+
struct drm_plane *cursor,
120+
const struct drm_crtc_funcs *funcs,
121+
const struct drm_crtc_helper_funcs *helper_funcs);
122+
113123
#endif // DRM_KUNIT_HELPERS_H_

0 commit comments

Comments
 (0)