From b0042828ad3a3371853072a57c225f474d747ef9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 26 May 2020 21:30:31 +0200 Subject: [PATCH] test: add test with fully transparent layer --- test/meson.build | 5 +-- test/test_prop.c | 79 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/test/meson.build b/test/meson.build index 7d8f35c..10c997d 100644 --- a/test/meson.build +++ b/test/meson.build @@ -57,8 +57,9 @@ tests = { #'basic', ], 'prop': [ - 'alpha', - 'rotation', + 'default-alpha', + 'default-rotation', + 'ignore-alpha', ], } diff --git a/test/test_prop.c b/test/test_prop.c index 53f9bb8..33d0156 100644 --- a/test/test_prop.c +++ b/test/test_prop.c @@ -26,8 +26,8 @@ static struct liftoff_layer *add_layer(struct liftoff_output *output, return layer; } -int main(int argc, char *argv[]) { - const char *test_name; +static int test_prop_default(const char *prop_name) +{ struct liftoff_mock_plane *mock_plane_with_prop, *mock_plane_without_prop; int drm_fd; @@ -40,12 +40,6 @@ int main(int argc, char *argv[]) { liftoff_log_init(LIFTOFF_DEBUG, NULL); - if (argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); - return 1; - } - test_name = argv[1]; - mock_plane_without_prop = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_OVERLAY); mock_plane_with_prop = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_OVERLAY); @@ -53,21 +47,21 @@ int main(int argc, char *argv[]) { uint64_t require_prop_value; /* Value that doesn't require the prop to be present */ uint64_t default_value; - if (strcmp(test_name, "alpha") == 0) { + if (strcmp(prop_name, "alpha") == 0) { require_prop_value = (uint16_t)(0.5 * 0xFFFF); default_value = 0xFFFF; /* opaque */ - } else if (strcmp(test_name, "rotation") == 0) { + } else if (strcmp(prop_name, "rotation") == 0) { require_prop_value = DRM_MODE_ROTATE_180; default_value = DRM_MODE_ROTATE_0; } else { - fprintf(stderr, "no such test: %s\n", test_name); + fprintf(stderr, "no such test: default-%s\n", prop_name); return 1; } /* We need to setup mock plane properties before creating the liftoff * device */ drmModePropertyRes prop = {0}; - strncpy(prop.name, test_name, sizeof(prop.name) - 1); + strncpy(prop.name, prop_name, sizeof(prop.name) - 1); liftoff_mock_plane_add_property(mock_plane_with_prop, &prop); drm_fd = liftoff_mock_drm_open(); @@ -128,3 +122,64 @@ int main(int argc, char *argv[]) { return 0; } + +/* Checks that a fully transparent layer is ignored. */ +static int test_ignore_alpha(void) +{ + struct liftoff_mock_plane *mock_plane; + int drm_fd; + struct liftoff_device *device; + struct liftoff_output *output; + struct liftoff_layer *layer; + drmModeAtomicReq *req; + bool ok; + int ret; + + mock_plane = liftoff_mock_drm_create_plane(DRM_PLANE_TYPE_PRIMARY); + + drm_fd = liftoff_mock_drm_open(); + device = liftoff_device_create(drm_fd); + assert(device != NULL); + + output = liftoff_output_create(device, liftoff_mock_drm_crtc_id); + layer = add_layer(output, 0, 0, 1920, 1080); + liftoff_layer_set_property(layer, "alpha", 0); /* fully transparent */ + + liftoff_mock_plane_add_compatible_layer(mock_plane, layer); + + req = drmModeAtomicAlloc(); + ok = liftoff_output_apply(output, req); + assert(ok); + ret = drmModeAtomicCommit(drm_fd, req, 0, NULL); + assert(ret == 0); + assert(liftoff_mock_plane_get_layer(mock_plane) == NULL); + drmModeAtomicFree(req); + + liftoff_device_destroy(device); + close(drm_fd); + + return 0; +} + +int main(int argc, char *argv[]) { + const char *test_name; + + liftoff_log_init(LIFTOFF_DEBUG, NULL); + + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + test_name = argv[1]; + + const char default_test_prefix[] = "default-"; + if (strncmp(test_name, default_test_prefix, + strlen(default_test_prefix)) == 0) { + return test_prop_default(test_name + strlen(default_test_prefix)); + } else if (strcmp(test_name, "ignore-alpha") == 0) { + return test_ignore_alpha(); + } else { + fprintf(stderr, "no such test: %s\n", test_name); + return 1; + } +}