Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: nakshtra.goyal@intel.com
To: igt-dev@lists.freedesktop.org, ramadevi.gandi@intel.com
Cc: francois.dugast@intel.com
Subject: [PATCH i-g-t] tests/intel/xe_fault_injection: Inject errors during observation IOCTL
Date: Thu, 27 Feb 2025 04:50:55 +0530	[thread overview]
Message-ID: <20250226232055.2835226-1-nakshtra.goyal@intel.com> (raw)

From: Nakshtra Goyal <nakshtra.goyal@intel.com>

Use the fault injection infrastructure to make targeted internal KMD
functions fail when executing xe_observation_ioctl()
so that more code paths are tested, such as error handling and unwinding.

Signed-off-by: Nakshtra Goyal <nakshtra.goyal@intel.com>
---
 tests/intel/xe_fault_injection.c | 54 +++++++++++++++++++++++++++++++-
 tests/meson.build                |  1 +
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c
index ede483535..09792bc34 100644
--- a/tests/intel/xe_fault_injection.c
+++ b/tests/intel/xe_fault_injection.c
@@ -20,6 +20,7 @@
 #include "lib/igt_syncobj.h"
 #include "lib/intel_pat.h"
 #include "xe/xe_ioctl.h"
+#include "xe/xe_oa.h"
 #include "xe/xe_query.h"
 
 #define INJECT_ERRNO	-ENOMEM
@@ -281,9 +282,49 @@ vm_bind_fail(int fd, const char function_name[])
 	igt_assert_eq(simple_vm_bind(fd, vm), 0);
 }
 
+/**
+ * SUBTEST: oa-add-config-fail-%s
+ * Description: inject an error in function %arg[1] used in oa add config IOCTL to make it fail
+ * Functionality: fault
+ *
+ * arg[1]:
+ * @xe_oa_alloc_regs:		xe_oa_alloc_regs
+ */
+static void
+oa_add_config_fail(int fd, int sysfs, int devid, const char function_name[])
+{
+	char path[512];
+	uint64_t config_id;
+#define SAMPLE_MUX_REG (intel_graphics_ver(devid) >= IP_VER(20, 0) ?	\
+			0x13000 /* PES* */ : 0x9888 /* NOA_WRITE */)
+
+	uint32_t mux_regs[] = { SAMPLE_MUX_REG, 0x0 };
+	struct drm_xe_oa_config config;
+	const char *uuid = "01234567-0123-0123-0123-0123456789ab";
+
+	memset(&config, 0, sizeof(config));
+	memcpy(config.uuid, uuid, sizeof(config.uuid));
+	config.n_regs = 1;
+	config.regs_ptr = to_user_pointer(mux_regs);
+	snprintf(path, sizeof(path), "metrics/%s/id", uuid);
+
+	igt_assert_lt(0, intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_ADD_CONFIG, &config));
+	if (igt_sysfs_scanf(sysfs, path, "%"PRIu64, &config_id) == 1)
+		igt_assert_eq(intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_REMOVE_CONFIG, &config_id), 0);
+
+	ignore_faults_in_dmesg(function_name);
+	injection_list_do(INJECTION_LIST_ADD, function_name);
+	set_retval(function_name, INJECT_ERRNO);
+	igt_assert_lt(intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_ADD_CONFIG, &config), 0);
+	injection_list_do(INJECTION_LIST_REMOVE, function_name);
+
+	igt_assert_lt(0, intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_ADD_CONFIG, &config));
+}
+
 igt_main
 {
-	int fd;
+	int fd, sysfs;
+	static uint32_t devid;
 	char pci_slot[NAME_MAX];
 	const struct section {
 		const char *name;
@@ -319,10 +360,16 @@ igt_main
 		{ "xe_sync_entry_parse" },
 		{ }
 	};
+	const struct section oa_add_config_fail_functions[] = {
+		{ "xe_oa_alloc_regs"},
+		{ }
+	};
 
 	igt_fixture {
 		igt_require(fail_function_injection_enabled());
 		fd = drm_open_driver(DRIVER_XE);
+		devid = intel_get_drm_devid(fd);
+		sysfs = igt_sysfs_open(fd);
 		igt_device_get_pci_slot_name(fd, pci_slot);
 		setup_injection_fault();
 	}
@@ -335,6 +382,10 @@ igt_main
 		igt_subtest_f("vm-bind-fail-%s", s->name)
 			vm_bind_fail(fd, s->name);
 
+	for (const struct section *s = oa_add_config_fail_functions; s->name; s++)
+		igt_subtest_f("oa-add-config-fail-%s", s->name)
+			oa_add_config_fail(fd, sysfs, devid, s->name);
+
 	igt_fixture {
 		xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_UNBIND);
 	}
@@ -344,6 +395,7 @@ igt_main
 			inject_fault_probe(fd, pci_slot, s->name);
 
 	igt_fixture {
+		close(sysfs);
 		drm_close_driver(fd);
 		xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_BIND);
 	}
diff --git a/tests/meson.build b/tests/meson.build
index a0f984b34..ca5565c21 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -398,6 +398,7 @@ extra_dependencies = {
 	'perf_pmu':  [ lib_igt_perf ],
 	'sw_sync': [ libatomic ],
 	'xe_oa': [ lib_igt_xe_oa ],
+	'xe_fault_injection': [ lib_igt_xe_oa ],
 }
 
 test_executables = []
-- 
2.34.1


             reply	other threads:[~2025-02-26 23:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 23:20 nakshtra.goyal [this message]
2025-02-28  1:23 ` ✓ Xe.CI.BAT: success for tests/intel/xe_fault_injection: Inject errors during observation IOCTL Patchwork
2025-02-28  1:52 ` ✓ i915.CI.BAT: " Patchwork
2025-02-28  6:05 ` ✓ Xe.CI.Full: " Patchwork
2025-02-28 12:00 ` ✗ i915.CI.Full: failure " Patchwork
2025-03-03  5:42 ` [PATCH i-g-t] " Pottumuttu, Sai Teja

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250226232055.2835226-1-nakshtra.goyal@intel.com \
    --to=nakshtra.goyal@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=ramadevi.gandi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox