[Piglit] [v10 05/13] framework: automatic drm authentication for dma buffer support
Topi Pohjolainen
topi.pohjolainen at intel.com
Tue Aug 20 03:16:25 PDT 2013
From: Chad Versace <chad.versace at linux.intel.com>
Fix tests to work as non-root user. Get DRM authentication before
calling intel_bufmgr_gem_init().
v2: refactored into its own patch and allowing the dma buffer
support to be compiled even without this (change by Topi)
v3: use 'bool' instead of "zero for success, negative for failure"
(review by Eric, change by Topi)
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
tests/util/CMakeLists.txt | 15 +++++++
.../util/piglit-framework-gl/piglit_drm_dma_buf.c | 50 ++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index 77b6fc5..8f1420c 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -52,6 +52,7 @@ set(UTIL_GL_LIBS
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
pkg_check_modules(LIBDRM_INTEL QUIET libdrm_intel)
+ pkg_check_modules(XCB_DRI2 QUIET xcb-dri2)
# One needs to have at least one hardware driver present, otherwise
# there is no point compiling just the dispatcher.
@@ -77,6 +78,20 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
${LIBDRM_INTEL_LDFLAGS}
)
endif()
+
+ # xcb-dri2 is used to gain DRM authentication.
+ if(XCB_DRI2_FOUND)
+ add_definitions(-DHAVE_XCB_DRI2)
+
+ list(APPEND UTIL_GL_LIBS
+ ${XCB_DRI2_LDFLAGS}
+ )
+
+ list(APPEND UTIL_GL_INCLUDES
+ ${XCB_DRI2_INCLUDE_DIRS}
+ )
+ endif()
+
endif()
set(UTIL_GL_LIBS
diff --git a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
index cdfc7f1..9a7ff3b 100644
--- a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
+++ b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
@@ -32,6 +32,10 @@
#include <string.h>
#include <xf86drm.h>
#include <stdbool.h>
+#ifdef HAVE_XCB_DRI2
+#include <xcb/dri2.h>
+#include <drm.h>
+#endif
static const char *drm_device_filename = "/dev/dri/card0";
@@ -73,6 +77,47 @@ piglit_drm_device_get(void)
return fd;
}
+#ifdef HAVE_XCB_DRI2
+static bool
+piglit_drm_x11_authenticate(void)
+{
+ drm_magic_t magic;
+ xcb_connection_t *conn;
+ int screen;
+ xcb_screen_iterator_t screen_iter;
+ xcb_dri2_authenticate_cookie_t auth_cookie;
+ xcb_dri2_authenticate_reply_t *auth_reply;
+ int ret = 0;
+
+ conn = xcb_connect(NULL, &screen);
+ if (!conn) {
+ printf("piglit: failed to connect to X server for DRI2 "
+ "authentication\n");
+ return false;
+ }
+
+ ret = drmGetMagic(piglit_drm_device_get(), &magic);
+ if (ret) {
+ printf("piglit: failed to get DRM magic\n");
+ return false;
+ }
+
+ screen_iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
+ auth_cookie = xcb_dri2_authenticate_unchecked(conn,
+ screen_iter.data->root,
+ magic);
+ auth_reply = xcb_dri2_authenticate_reply(conn, auth_cookie, NULL);
+
+ if (auth_reply == NULL || !auth_reply->authenticated) {
+ printf("piglit: failed to authenticate with DRI2\n");
+ return false;
+ }
+ free(auth_reply);
+
+ return true;
+}
+#endif /* HAVE_XCB_DRI2 */
+
#ifdef HAVE_LIBDRM_INTEL
static drm_intel_bufmgr *
piglit_intel_bufmgr_get(void)
@@ -86,6 +131,11 @@ piglit_intel_bufmgr_get(void)
if (!piglit_drm_device_get())
return NULL;
+#ifdef HAVE_XCB_DRI2
+ if (!piglit_drm_x11_authenticate())
+ return NULL;
+#endif /* HAVE_XCB_DRI2 */
+
mgr = intel_bufmgr_gem_init(piglit_drm_device_get(), batch_sz);
return mgr;
--
1.8.3.1
More information about the Piglit
mailing list