From 71200724c5087ffa08fb71a0bb9faedfab6c54b4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 19 Dec 2019 17:41:32 +0100 Subject: [PATCH] test: add a test with a layer without any prop set Makes sure libliftoff doesn't allocate a plane for the layer and doesn't crash. References: 799f69458799 ("Fix segfault when FB_ID isn't set") References: 53a7bfebc952 ("Don't allocate planes for layers without a FB") --- test/meson.build | 1 + test/test_alloc.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/test/meson.build b/test/meson.build index 62e4b15..dcee590 100644 --- a/test/meson.build +++ b/test/meson.build @@ -24,6 +24,7 @@ bench_exe = executable( tests = { 'alloc': [ 'basic', + 'no-props', 'empty', 'simple-1x', 'simple-1x-fail', diff --git a/test/test_alloc.c b/test/test_alloc.c index c7a03fc..1090a20 100644 --- a/test/test_alloc.c +++ b/test/test_alloc.c @@ -712,6 +712,39 @@ static void test_basic(void) close(drm_fd); } +/* Checks the library doesn't segfault when a layer is added without any + * property set. */ +static void test_no_props(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; + + 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 = liftoff_layer_create(output); + + liftoff_mock_plane_add_compatible_layer(mock_plane, layer); + + req = drmModeAtomicAlloc(); + ok = liftoff_output_apply(output, req); + assert(liftoff_mock_plane_get_layer(mock_plane, req) == NULL); + assert(ok); + drmModeAtomicFree(req); + + liftoff_device_destroy(device); + close(drm_fd); +} + int main(int argc, char *argv[]) { const char *test_name; size_t i; @@ -727,6 +760,9 @@ int main(int argc, char *argv[]) { if (strcmp(test_name, "basic") == 0) { test_basic(); return 0; + } else if (strcmp(test_name, "no-props") == 0) { + test_no_props(); + return 0; } for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {