[Piglit] [v6 03/12] framework: automatic drm authentication for dma buffer support
Topi Pohjolainen
topi.pohjolainen at intel.com
Thu May 16 02:51:16 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 (Topi): refactored into its own patch and allowing the dma
buffer support to be compiled even without this
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
tests/util/CMakeLists.txt | 15 +++++++
.../util/piglit-framework-gl/piglit_drm_dma_buf.c | 48 ++++++++++++++++++++++
2 files changed, 63 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 21add02..3cdf1dd 100644
--- a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
+++ b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
@@ -31,6 +31,8 @@
#include <fcntl.h>
#include <string.h>
#include <xf86drm.h>
+#include <xcb/dri2.h>
+#include <drm.h>
static const char *drm_device_filename = "/dev/dri/card0";
@@ -72,6 +74,47 @@ piglit_drm_device_get(void)
return fd;
}
+#ifdef HAVE_XCB_DRI2
+static int
+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 -1;
+ }
+
+ ret = drmGetMagic(piglit_drm_device_get(), &magic);
+ if (ret) {
+ printf("piglit: failed to get DRM magic\n");
+ return -1;
+ }
+
+ 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 -1;
+ }
+ free(auth_reply);
+
+ return 0;
+}
+#endif /* HAVE_XCB_DRI2 */
+
#ifdef HAVE_LIBDRM_INTEL
static drm_intel_bufmgr *
piglit_intel_bufmgr_get(void)
@@ -85,6 +128,11 @@ piglit_intel_bufmgr_get(void)
if (!piglit_drm_device_get())
return NULL;
+#ifdef HAVE_XCB_DRI2
+ if (piglit_drm_x11_authenticate() < 0)
+ return NULL;
+#endif /* HAVE_XCB_DRI2 */
+
mgr = intel_bufmgr_gem_init(piglit_drm_device_get(), batch_sz);
return mgr;
--
1.8.1.2
More information about the Piglit
mailing list