diff options
-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); +} |