[igt-dev] [PATCH i-g-t 5/8] xe/xe_eudebug: exercise read_event ioctl

Dominik Grzegorzek dominik.grzegorzek at intel.com
Tue May 16 15:44:31 UTC 2023


Introduce synchronous test, which validates eu debugger read_event
ioctl.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
 tests/xe/xe_eudebug.c | 81 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/tests/xe/xe_eudebug.c b/tests/xe/xe_eudebug.c
index cf49a4bd4..31f0f274d 100644
--- a/tests/xe/xe_eudebug.c
+++ b/tests/xe/xe_eudebug.c
@@ -2,6 +2,7 @@
 /*
  * Copyright © 2023 Intel Corporation
  */
+#include <poll.h>
 
 #include <xe_drm_tmp.h>
 #include "xe/xe_eudebug.h"
@@ -66,6 +67,34 @@ static void session_destroy(struct session *s)
 	xe_eudebug_client_destroy(s->c);
 }
 
+static int __read_event(int debugfd, struct drm_xe_eudebug_event *event)
+{
+	int ret;
+
+	ret = igt_ioctl(debugfd, DRM_XE_EUDEBUG_IOCTL_READ_EVENT, event);
+	if (ret < 0)
+		return -errno;
+
+	return ret;
+}
+
+static int poll_event(int fd, int timeout_ms)
+{
+	int ret;
+
+	struct pollfd p = {
+		.fd = fd,
+		.events = POLLIN,
+		.revents = 0,
+	};
+
+	ret = poll(&p, 1, timeout_ms);
+	if (ret == -1)
+		return -errno;
+
+	return ret == 1 && (p.revents & POLLIN);
+}
+
 static int __debug_connect(int fd, int *debugfd, struct drm_xe_eudebug_connect_param *param)
 {
 	int ret = 0;
@@ -174,6 +203,55 @@ static void test_close(int fd)
 	close(debug_fd1);
 }
 
+#define MAX_EVENT_SIZE (32 * 1024)
+static void test_read_event(int fd)
+{
+	struct drm_xe_eudebug_event event = {};
+	struct xe_eudebug_debugger *d;
+	struct xe_eudebug_client *c;
+
+	c = xe_eudebug_client_create(run_basic_client, 0);
+	d = xe_eudebug_debugger_create(fd, 0);
+
+	igt_assert_eq(xe_eudebug_debugger_attach(d, c->pid), 0);
+	igt_assert_eq(poll_event(d->fd, 500), 0);
+
+	event.size = 1;
+	event.type = DRM_XE_EUDEBUG_EVENT_NONE;
+	igt_assert_eq(__read_event(d->fd, &event), -EINVAL);
+
+	event.size = MAX_EVENT_SIZE;
+	event.type = DRM_XE_EUDEBUG_EVENT_NONE;
+	igt_assert_eq(__read_event(d->fd, &event), -EINVAL);
+
+	xe_eudebug_client_start(c);
+
+	igt_assert_eq(poll_event(d->fd, 500), 1);
+	event.type = DRM_XE_EUDEBUG_EVENT_READ;
+	igt_assert_eq(__read_event(d->fd, &event), 0);
+
+	igt_assert_eq(poll_event(d->fd, 500), 1);
+	event.size = MAX_EVENT_SIZE;
+	event.flags = 0;
+	event.type = DRM_XE_EUDEBUG_EVENT_READ;
+	igt_assert_eq(__read_event(d->fd, &event), 0);
+
+	igt_assert_eq(poll_event(d->fd, 500), 0);
+	event.size = MAX_EVENT_SIZE;
+	event.flags = 0;
+	event.type = DRM_XE_EUDEBUG_EVENT_READ;
+	igt_assert_eq(__read_event(d->fd, &event), -ENOENT);
+
+	xe_eudebug_client_wait_done(c);
+	xe_eudebug_client_stop(c);
+
+	igt_assert_eq(poll_event(d->fd, 500), 0);
+	igt_assert_eq(__read_event(d->fd, &event), -ENOENT);
+
+	xe_eudebug_debugger_destroy(d);
+	xe_eudebug_client_destroy(c);
+}
+
 static void test_basic_sessions(int fd, unsigned int flags, int count)
 {
 	struct session **s;
@@ -210,6 +288,9 @@ igt_main
 	igt_subtest("basic-close")
 		test_close(fd);
 
+	igt_subtest("basic-read-event")
+		test_read_event(fd);
+
 	igt_subtest("basic-client")
 		test_basic_sessions(fd, 0, 1);
 
-- 
2.34.1



More information about the igt-dev mailing list