[PATCH 28/66] tests/xe_eudebug: Add basic-client-th test

Christoph Manszewski christoph.manszewski at intel.com
Mon Jul 29 16:01:21 UTC 2024


From: Pawel Sikora <pawel.sikora at intel.com>

Add basic-client-th test which is a multithreaded version of basic-client.

Create random number of VMs in random number of threads.

Signed-off-by: Pawel Sikora <pawel.sikora at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
 tests/intel/xe_eudebug.c | 78 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/tests/intel/xe_eudebug.c b/tests/intel/xe_eudebug.c
index 37b4f4e27..022b39f1f 100644
--- a/tests/intel/xe_eudebug.c
+++ b/tests/intel/xe_eudebug.c
@@ -13,6 +13,7 @@
  */
 
 #include <poll.h>
+#include <pthread.h>
 #include <sys/ioctl.h>
 
 #include "igt.h"
@@ -640,6 +641,10 @@ static void test_read_event(int fd)
  * Description:
  *	Attach the debugger to process which opens and closes xe drm client.
  *
+ * SUBTEST: basic-client-th
+ * Description:
+ *	Create client basic resources (vms) in multiple threads
+ *
  * SUBTEST: multiple-sessions
  * Description:
  *	Simultaneously attach many debuggers to many processes.
@@ -669,6 +674,7 @@ static void test_read_event(int fd)
  * @vms: vms
  * @exec-queues: exec queues
  */
+
 static void test_basic_sessions(int fd, unsigned int flags, int count, bool match_opposite)
 {
 	struct xe_eudebug_session **s;
@@ -1056,6 +1062,75 @@ static void test_client_with_trigger(int fd, unsigned int flags, int count,
 		xe_eudebug_session_destroy(s[i]);
 }
 
+struct thread_fn_args {
+	struct xe_eudebug_client *client;
+	int fd;
+};
+
+static void *basic_client_th(void *data)
+{
+	struct thread_fn_args *f = data;
+	struct xe_eudebug_client *c = f->client;
+	uint32_t *vms;
+	int fd, i, num_vms;
+
+	fd = f->fd;
+	igt_assert(fd);
+
+	xe_device_get(fd);
+
+	num_vms = 2 + rand() % 16;
+	vms = calloc(num_vms, sizeof(*vms));
+	igt_assert(vms);
+	igt_debug("Create %d client vms\n", num_vms);
+
+	for (i = 0; i < num_vms; i++)
+		vms[i] = xe_eudebug_client_vm_create(c, fd, DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE, 0);
+
+	for (i = 0; i < num_vms; i++)
+		xe_eudebug_client_vm_destroy(c, fd, vms[i]);
+
+	xe_device_put(fd);
+	free(vms);
+
+	return NULL;
+}
+
+static void run_basic_client_th(struct xe_eudebug_client *c)
+{
+	struct thread_fn_args *args;
+	int i, num_threads, fd;
+	pthread_t *threads;
+
+	args = calloc(1, sizeof(*args));
+	igt_assert(args);
+
+	num_threads = 2 + random() % 16;
+	igt_debug("Run on %d threads\n", num_threads);
+	threads = calloc(num_threads, sizeof(*threads));
+	igt_assert(threads);
+
+	fd = xe_eudebug_client_open_driver(c);
+	args->client = c;
+	args->fd = fd;
+
+	for (i = 0; i < num_threads; i++)
+		pthread_create(&threads[i], NULL, basic_client_th, args);
+
+	for (i = 0; i < num_threads; i++)
+		pthread_join(threads[i], NULL);
+
+	xe_eudebug_client_close_driver(c, fd);
+	free(args);
+	free(threads);
+}
+
+static void test_basic_sessions_th(int fd, unsigned int flags, int num_clients, bool match_opposite)
+{
+	test_client_with_trigger(fd, flags, num_clients, run_basic_client_th,
+					 0, NULL, NULL, match_opposite, 0);
+}
+
 static void vm_access_client(struct xe_eudebug_client *c)
 {
 	struct drm_xe_sync sync = {
@@ -1468,6 +1543,9 @@ igt_main
 	igt_subtest("basic-client")
 		test_basic_sessions(fd, 0, 1, true);
 
+	igt_subtest("basic-client-th")
+		test_basic_sessions_th(fd, 0, 1, true);
+
 	igt_subtest("basic-vm-access")
 		test_vm_access(fd, 0, 1);
 
-- 
2.34.1



More information about the igt-dev mailing list