From f7ece74a107a2f99b2f494d978c84f8d51faa703 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Mon, 22 Jan 2024 15:39:52 +0000 Subject: 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: --- tests/gbm/CMakeLists.no_api.txt | 4 ++++ tests/gbm/gbm-device.c | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/gbm/gbm-device.c 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 +#include +#include +#include +#include +#include + +#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); +} -- cgit v1.2.3