From afeeafd6d7d2d4507e6890e5fb151c99046f8f98 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 9 Feb 2023 10:38:03 +0100 Subject: [PATCH] test: add basic test for candidate planes --- test/meson.build | 3 ++ test/test_candidate.c | 98 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/test_candidate.c diff --git a/test/meson.build b/test/meson.build index a6cacb4..71dfb54 100644 --- a/test/meson.build +++ b/test/meson.build @@ -79,6 +79,9 @@ tests = { 'unmatched', 'unset', ], + 'candidate': [ + 'basic', + ], } foreach test_name, subtests : tests diff --git a/test/test_candidate.c b/test/test_candidate.c new file mode 100644 index 0000000..64b8816 --- /dev/null +++ b/test/test_candidate.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include "libdrm_mock.h" + +static struct liftoff_layer * +add_layer(struct liftoff_output *output, int x, int y, int width, int height) +{ + uint32_t fb_id; + struct liftoff_layer *layer; + + layer = liftoff_layer_create(output); + fb_id = liftoff_mock_drm_create_fb(layer); + liftoff_layer_set_property(layer, "FB_ID", fb_id); + liftoff_layer_set_property(layer, "CRTC_X", x); + liftoff_layer_set_property(layer, "CRTC_Y", y); + liftoff_layer_set_property(layer, "CRTC_W", width); + liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "SRC_X", 0); + liftoff_layer_set_property(layer, "SRC_Y", 0); + liftoff_layer_set_property(layer, "SRC_W", width << 16); + liftoff_layer_set_property(layer, "SRC_H", height << 16); + + return layer; +} + +static void +test_basic(void) +{ + struct liftoff_mock_plane *mock_plane_ok, *mock_plane_ko; + int drm_fd; + struct liftoff_device *device; + struct liftoff_output *output; + struct liftoff_layer *layer; + struct liftoff_plane *plane_ok, *plane_ko; + drmModeAtomicReq *req; + drmModePropertyRes prop = {0}; + int ret; + + mock_plane_ok = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_OVERLAY); + mock_plane_ko = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_OVERLAY); + + /* Only add the COLOR_RANGE property to mock_plane_ok only. libliftoff + * should mark that one as a possible candidate, but not the other + * one. */ + strncpy(prop.name, "COLOR_RANGE", sizeof(prop.name) - 1); + liftoff_mock_plane_add_property(mock_plane_ok, &prop); + + drm_fd = liftoff_mock_drm_open(); + device = liftoff_device_create(drm_fd); + assert(device != NULL); + + plane_ok = liftoff_plane_create(device, liftoff_mock_plane_get_id(mock_plane_ok)); + plane_ko = liftoff_plane_create(device, liftoff_mock_plane_get_id(mock_plane_ko)); + + output = liftoff_output_create(device, liftoff_mock_drm_crtc_id); + layer = add_layer(output, 0, 0, 1920, 1080); + liftoff_layer_set_property(layer, "COLOR_RANGE", 0); + + req = drmModeAtomicAlloc(); + ret = liftoff_output_apply(output, req, 0); + assert(ret == 0); + ret = drmModeAtomicCommit(drm_fd, req, 0, NULL); + assert(ret == 0); + assert(liftoff_mock_plane_get_layer(mock_plane_ok) == NULL); + assert(liftoff_mock_plane_get_layer(mock_plane_ko) == NULL); + assert(liftoff_layer_is_candidate_plane(layer, plane_ok)); + assert(!liftoff_layer_is_candidate_plane(layer, plane_ko)); + drmModeAtomicFree(req); + + liftoff_device_destroy(device); + close(drm_fd); +} + +int +main(int argc, char *argv[]) +{ + const char *test_name; + + liftoff_log_set_priority(LIFTOFF_DEBUG); + + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + test_name = argv[1]; + + if (strcmp(test_name, "basic") == 0) { + test_basic(); + } else { + fprintf(stderr, "no such test: %s\n", test_name); + return 1; + } + + return 0; +}