diff options
author | Daniel Stone <daniels@collabora.com> | 2024-01-22 15:39:52 +0000 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-04-17 12:58:37 +0000 |
commit | f7ece74a107a2f99b2f494d978c84f8d51faa703 (patch) | |
tree | 150ef9e668bedc6232933284944a0d9d49987eb1 | |
parent | fd4a6c521c6c16ee9edac78e5f22a2551d62df9b (diff) |
tests/gbm: Add gbm_device_get_fd() test
Make sure that GBM doesn't dup() the FD from under us, as users rely on
this being the case.
Part-of: <https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/865>
-rw-r--r-- | tests/gbm/CMakeLists.no_api.txt | 4 | ||||
-rw-r--r-- | tests/gbm/gbm-device.c | 50 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/gbm/CMakeLists.no_api.txt b/tests/gbm/CMakeLists.no_api.txt index c1fd99c66..57c750d2e 100644 --- a/tests/gbm/CMakeLists.no_api.txt +++ b/tests/gbm/CMakeLists.no_api.txt @@ -11,4 +11,8 @@ if(PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE AND LIBDRM_FOUND) piglit_add_executable(gbm-multi-plane gbm-multi-plane.c) endif() +if(PIGLIT_HAS_GBM) + piglit_add_executable(gbm-device gbm-device.c) +endif() + # vim: ft=cmake: diff --git a/tests/gbm/gbm-device.c b/tests/gbm/gbm-device.c new file mode 100644 index 000000000..8e1a82fde --- /dev/null +++ b/tests/gbm/gbm-device.c @@ -0,0 +1,50 @@ +/* Copyright (c) 2024 Collabora Ltd + * SPDX-License-Identifier: MIT + */ + +/** + * \file + * \brief Tests for libgbm. + */ + +#include <errno.h> +#include <fcntl.h> +#include <unistd.h> +#include <gbm.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include "piglit-util.h" + +int +main(int argc, char **argv) +{ + int drm_fd; + char *nodename; + struct gbm_device *gbm; + + /* Strip common piglit args. */ + piglit_strip_arg(&argc, argv, "-fbo"); + piglit_strip_arg(&argc, argv, "-auto"); + + nodename = getenv("WAFFLE_GBM_DEVICE"); + if (!nodename) + nodename = "/dev/dri/renderD128"; + drm_fd = open(nodename, O_RDWR); + if (drm_fd == -1) { + perror("Error opening render node"); + piglit_report_result(PIGLIT_SKIP); + } + + gbm = gbm_create_device(drm_fd); + if (!gbm) + piglit_report_result(PIGLIT_FAIL); + + if (gbm_device_get_fd(gbm) != drm_fd) + piglit_report_result(PIGLIT_FAIL); + + gbm_device_destroy(gbm); + close(drm_fd); + + piglit_report_result(PIGLIT_PASS); +} |