[PATCH i-g-t v2 13/66] tests/xe_eudebug: Exercise read_event ioctl
Christoph Manszewski
christoph.manszewski at intel.com
Tue Jul 30 11:44:30 UTC 2024
From: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Introduce synchronous test, which validates eu debugger read_event
ioctl.
Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Christoph Manszewski <christoph.manszewski at intel.com>
---
tests/intel/xe_eudebug.c | 109 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 108 insertions(+), 1 deletion(-)
diff --git a/tests/intel/xe_eudebug.c b/tests/intel/xe_eudebug.c
index 7ca0138a2..0cef652e2 100644
--- a/tests/intel/xe_eudebug.c
+++ b/tests/intel/xe_eudebug.c
@@ -12,6 +12,9 @@
* Test category: functionality test
*/
+#include <poll.h>
+#include <sys/ioctl.h>
+
#include "igt.h"
#include "xe/xe_eudebug.h"
@@ -23,6 +26,45 @@ static void run_basic_client(struct xe_eudebug_client *c)
xe_eudebug_client_close_driver(c, fd);
}
+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 __read_event(int debugfd, struct drm_xe_eudebug_event *event)
+{
+ int ret;
+
+ ret = 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)
{
int ret = 0;
@@ -124,6 +166,69 @@ static void test_close(int fd)
close(debug_fd1);
}
+/**
+ * SUBTEST: basic-read-event
+ * Description:
+ * Synchronously exercise eu debugger event polling and reading.
+ */
+#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;
+
+ event = malloc(MAX_EVENT_SIZE);
+ igt_assert(event);
+ memset(event, 0, sizeof(*event));
+
+ c = xe_eudebug_client_create(fd, run_basic_client, 0, NULL);
+ d = xe_eudebug_debugger_create(fd, 0, NULL);
+
+ igt_assert_eq(xe_eudebug_debugger_attach(d, c), 0);
+ igt_assert_eq(poll_event(d->fd, 500), 0);
+
+ event->len = 1;
+ event->type = DRM_XE_EUDEBUG_EVENT_NONE;
+ igt_assert_eq(read_event(d->fd, event), -EINVAL);
+
+ event->len = 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->len = MAX_EVENT_SIZE;
+ event->flags = 0;
+ event->type = DRM_XE_EUDEBUG_EVENT_READ;
+ igt_assert_eq(read_event(d->fd, event), 0);
+
+ fcntl(d->fd, F_SETFL, fcntl(d->fd, F_GETFL) | O_NONBLOCK);
+ igt_assert(fcntl(d->fd, F_GETFL) & O_NONBLOCK);
+
+ igt_assert_eq(poll_event(d->fd, 500), 0);
+ event->len = MAX_EVENT_SIZE;
+ event->flags = 0;
+ event->type = DRM_XE_EUDEBUG_EVENT_READ;
+ igt_assert_eq(__read_event(d->fd, event), -EAGAIN);
+
+ 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), -EAGAIN);
+
+ xe_eudebug_debugger_destroy(d);
+ xe_eudebug_client_destroy(c);
+
+ free(event);
+}
+
/**
* SUBTEST: basic-client
* Description:
@@ -134,7 +239,6 @@ static void test_close(int fd)
* Simultaneously attach many debuggers to many processes.
* Each process opens and closes xe drm client.
*/
-
static void test_basic_sessions(int fd, unsigned int flags, int count)
{
struct xe_eudebug_session **s;
@@ -171,6 +275,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