aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.com>2021-01-22 08:54:32 +0100
committerMarge Bot <eric+marge@anholt.net>2021-03-24 08:12:35 +0000
commit5751f7d8f9c4972a5ec9dfa47188f6e8a283cbde (patch)
tree0748545bb79a7e964465cd174f6d5813b040536d
parent61650d12481f9d73168191cbe50e25da5c2f3356 (diff)
downloadpiglit-5751f7d8f9c4972a5ec9dfa47188f6e8a283cbde.tar.gz
gbm: Add test for multi-planar GBM BOs
Do some basic checking of the API that deals with multi-planar BOs. v2: - Fix code style (Simon) - Drop USE_SCANOUT (Simon) - Correctly test for fcntl errors (Simon) - Acknowledge WAFFLE_GBM_DEVICE (Simon) - Use perror (Simon) v3: - Error out if we cannot open WAFFLE_GBM_DEVICE (Simon) - Check that the FD returned with gbm_bo_get_fd_for_plane refers to the right GEM BO (Simon) v4: - Check for the handle value before releasing the BO (Simon and Michel) Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Reviewed-by: Simon Ser <contact@emersion.fr> Part-of: <https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/461>
-rw-r--r--CMakeLists.txt4
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/gbm/CMakeLists.no_api.txt10
-rw-r--r--tests/gbm/CMakeLists.txt1
-rw-r--r--tests/gbm/gbm-multi-plane.c130
5 files changed, 146 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23f65b9c5..05a0ef467 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,6 +148,10 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if (PIGLIT_HAS_GBM_BO_MAP)
add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
endif()
+ CHECK_FUNCTION_EXISTS(gbm_bo_get_fd_for_plane PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
+ if (PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
+ add_definitions(-DPIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
+ endif()
endif(GBM_FOUND)
pkg_check_modules(WAYLAND QUIET wayland-client)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 488f70ab7..844699ffd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -10,6 +10,7 @@ endif()
add_subdirectory (util)
add_subdirectory (fbo)
+add_subdirectory (gbm)
add_subdirectory (general)
add_subdirectory (glx)
add_subdirectory (glslparsertest)
diff --git a/tests/gbm/CMakeLists.no_api.txt b/tests/gbm/CMakeLists.no_api.txt
new file mode 100644
index 000000000..fb8a1d8c2
--- /dev/null
+++ b/tests/gbm/CMakeLists.no_api.txt
@@ -0,0 +1,10 @@
+link_libraries (
+ ${GBM_LDFLAGS}
+ piglitutil
+)
+
+if(PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
+ piglit_add_executable(gbm-multi-plane gbm-multi-plane.c)
+endif()
+
+# vim: ft=cmake:
diff --git a/tests/gbm/CMakeLists.txt b/tests/gbm/CMakeLists.txt
new file mode 100644
index 000000000..144a306f4
--- /dev/null
+++ b/tests/gbm/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/gbm/gbm-multi-plane.c b/tests/gbm/gbm-multi-plane.c
new file mode 100644
index 000000000..1debd60b6
--- /dev/null
+++ b/tests/gbm/gbm-multi-plane.c
@@ -0,0 +1,130 @@
+/* Copyright (c) 2021 Collabora Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * \file
+ * \brief Tests for libgbm.
+ */
+
+#include <drm_fourcc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <gbm.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "piglit-util.h"
+
+#define NUM_PLANES 3
+#define WIDTH 512
+#define HEIGHT 512
+#define FORMAT GBM_FORMAT_R8
+
+static bool
+gem_handles_match(struct gbm_device *gbm, int fd, int old_handle)
+{
+ bool match;
+ struct gbm_import_fd_data import = {
+ .width = WIDTH,
+ .height = HEIGHT,
+ .format = FORMAT,
+ .fd = fd,
+ };
+ struct gbm_bo *bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &import, 0);
+ if (!bo)
+ piglit_report_result(PIGLIT_FAIL);
+
+ match = gbm_bo_get_handle(bo).u32 == old_handle;
+ gbm_bo_destroy(bo);
+
+ return match;
+}
+
+int
+main(int argc, char **argv)
+{
+ int drm_fd;
+ char *nodename;
+ struct gbm_device *gbm;
+ struct gbm_bo *bos[NUM_PLANES];
+ struct gbm_bo *multi_plane_bo;
+ struct gbm_import_fd_modifier_data import_mod = {
+ .width = WIDTH,
+ .height = HEIGHT,
+ .format = GBM_FORMAT_YUV420,
+ .num_fds = NUM_PLANES,
+ .modifier = DRM_FORMAT_MOD_LINEAR,
+ };
+
+ /* 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_FAIL);
+ }
+
+ gbm = gbm_create_device(drm_fd);
+ if (!gbm)
+ piglit_report_result(PIGLIT_FAIL);
+
+ for (int i = 0; i < NUM_PLANES; i++) {
+ bos[i] = gbm_bo_create(gbm, WIDTH, HEIGHT, FORMAT,
+ GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
+ if (!bos[i])
+ piglit_report_result(PIGLIT_FAIL);
+
+ import_mod.fds[i] = gbm_bo_get_fd(bos[i]);
+ import_mod.strides[i] = gbm_bo_get_stride(bos[i]);
+ import_mod.offsets[i] = gbm_bo_get_offset(bos[i], 0);
+ }
+
+ multi_plane_bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD_MODIFIER,
+ &import_mod, 0);
+ if (!multi_plane_bo)
+ piglit_report_result(PIGLIT_FAIL);
+
+ for (int i = 0; i < NUM_PLANES; i++) {
+ int fd = gbm_bo_get_fd_for_plane(multi_plane_bo, i);
+ if (fd < 0)
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (fcntl(fd, F_GETFL) == -1 && errno == EBADF)
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (!gem_handles_match(gbm, fd, gbm_bo_get_handle(bos[i]).u32))
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (import_mod.strides[i] != gbm_bo_get_stride_for_plane(multi_plane_bo, i))
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (import_mod.offsets[i] != gbm_bo_get_offset(multi_plane_bo, i))
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ piglit_report_result(PIGLIT_PASS);
+}