[PATCH v5 i-g-t] tests/intel/xe_fault_injection: Inject errors during observation IOCTL

Francois Dugast francois.dugast at intel.com
Tue Mar 25 09:09:38 UTC 2025


On Mon, Mar 24, 2025 at 02:51:01PM +0530, Pottumuttu, Sai Teja wrote:
> On 24-03-2025 14:38, nakshtra.goyal at intel.com wrote:
> > From: Nakshtra Goyal <nakshtra.goyal at 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.
> > 
> > v1: Adding remove config at end of test , Adding igt_sysfs into igt_assert
> > so test fails if sysfs read fails (Sai Teja)
> > 
> > v2: Run sysfs check before creating config to destroy prev. config if
> > present, add one check before creating new config after destroying old
> > one (Sai Teja)
> > 
> > Signed-off-by: Nakshtra Goyal <nakshtra.goyal at intel.com>

Acked-by: Francois Dugast <francois.dugast at intel.com>

> > ---
> >   tests/intel/xe_fault_injection.c | 62 +++++++++++++++++++++++++++++++-
> >   tests/meson.build                |  1 +
> >   2 files changed, 62 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c
> > index 5409d19a6..eaf93a0b2 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
> > @@ -314,10 +315,57 @@ 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";
> > +
> > +	snprintf(path, sizeof(path), "metrics/%s/id", uuid);
> > +	/* Destroy previous configuration if present */
> > +	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);
> > +
> > +	memset(&config, 0, sizeof(config));
> > +	memcpy(config.uuid, uuid, sizeof(config.uuid));
> > +	config.n_regs = 1;
> > +	config.regs_ptr = to_user_pointer(mux_regs);
> > +
> > +	igt_assert_lt(0, intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_ADD_CONFIG, &config));
> > +	igt_assert(igt_sysfs_scanf(sysfs, path, "%"PRIu64, &config_id) == 1);
> 
> We could have dropped these sysfs reads as we get config_id directly as the
> return value of add config ioctl. But this way is also correct I guess, I
> don't see any harm as such.
> 
> > +	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);
> 
> I still think that it would be better to do an assert_eq to INJECT_ERRNO
> here. But then looking at other fault injection tests, it doesn't seem to be
> very important.
> 
> So, LGTM
> 
> Reviewed-by: Sai Teja Pottumuttu <sai.teja.pottumuttu at intel.com>
> 
> > +	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_assert(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);
> > +}
> > +
> >   igt_main
> >   {
> > -	int fd;
> > +	int fd, sysfs;
> >   	struct drm_xe_engine_class_instance *hwe;
> > +	static uint32_t devid;
> >   	char pci_slot[NAME_MAX];
> >   	const struct section {
> >   		const char *name;
> > @@ -366,9 +414,16 @@ igt_main
> >   		{ }
> >   	};
> > +	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();
> >   	}
> > @@ -393,6 +448,10 @@ igt_main
> >   				if (hwe->engine_class == DRM_XE_ENGINE_CLASS_VM_BIND)
> >   					exec_queue_create_fail(fd, hwe, s->name, s->flags);
> > +	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);
> >   	}
> > @@ -402,6 +461,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 2f5406523..c4a9093c4 100644
> > --- a/tests/meson.build
> > +++ b/tests/meson.build
> > @@ -401,6 +401,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 = []


More information about the igt-dev mailing list