[PATCH i-g-t v2 13/66] tests/xe_eudebug: Exercise read_event ioctl

Piatkowski, Dominik Karol dominik.karol.piatkowski at intel.com
Thu Aug 1 12:01:19 UTC 2024


Reviewed-by: Dominik Karol Piątkowski <dominik.karol.piatkowski at intel.com>

> -----Original Message-----
> From: Manszewski, Christoph <christoph.manszewski at intel.com>
> Sent: Tuesday, July 30, 2024 1:45 PM
> To: igt-dev at lists.freedesktop.org
> Cc: Kempczynski, Zbigniew <zbigniew.kempczynski at intel.com>; Kamil
> Konieczny <kamil.konieczny at linux.intel.com>; Grzegorzek, Dominik
> <dominik.grzegorzek at intel.com>; Patelczyk, Maciej
> <maciej.patelczyk at intel.com>; Piatkowski, Dominik Karol
> <dominik.karol.piatkowski at intel.com>; Sikora, Pawel
> <pawel.sikora at intel.com>; Hajda, Andrzej <andrzej.hajda at intel.com>;
> Kolanupaka Naveena <kolanupaka.naveena at intel.com>; Kuoppala, Mika
> <mika.kuoppala at intel.com>; Mun, Gwan-gyeong <gwan-
> gyeong.mun at intel.com>
> Subject: [PATCH i-g-t v2 13/66] tests/xe_eudebug: Exercise read_event ioctl
> 
> 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