[PATCH v2 i-g-t] tests/intel/xe_fault_injection: Inject errors during observation IOCTL
Pottumuttu, Sai Teja
sai.teja.pottumuttu at intel.com
Fri Mar 14 07:52:49 UTC 2025
On 13-03-2025 15:10, 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)
>
> Signed-off-by: Nakshtra Goyal <nakshtra.goyal at intel.com>
> ---
> tests/intel/xe_fault_injection.c | 56 +++++++++++++++++++++++++++++++-
> tests/meson.build | 1 +
> 2 files changed, 56 insertions(+), 1 deletion(-)
>
> diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c
> index 5409d19a6..1f150fbb0 100644
> --- a/tests/intel/xe_fault_injection.c
> +++ b/tests/intel/xe_fault_injection.c
> @@ -21,6 +21,7 @@
> #include "lib/intel_pat.h"
> #include "xe/xe_ioctl.h"
> #include "xe/xe_query.h"
> +#include "xe/xe_oa.h"
>
> #define INJECT_ERRNO -ENOMEM
> #define BO_ADDR 0x1a0000
> @@ -314,10 +315,51 @@ 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";
Looking at other oa tests, I think its a good practice to make sure that
we don't have a config with that uuid already and if its there, we will
have to remove it before proceeding.
> +
> + 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));
> + igt_assert(igt_sysfs_scanf(sysfs, path, "%"PRIu64, &config_id) == 1);
Looks like instead of reading sysfs we can do something like this as
well here,
int ret;
ret = intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_ADD_CONFIG, &config);
igt_assert_lt(0, ret);
igt_assert_eq(intel_xe_perf_ioctl(fd,
DRM_XE_OBSERVATION_OP_REMOVE_CONFIG, &ret), 0);
Do you think sysfs read gives any advantage here?
> + 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);
Maybe it would be better to do assert_eq to INJECT_ERRNO instead of just
saying that return value should be less than 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_assert_eq(intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_REMOVE_CONFIG, &config_id), 0);
The config_id here can be different I think. We need to get the new
config_id.
Sorry for not observing these while reviewing v1.
Thanks,
Sai Teja
> +}
> +
> 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 +408,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 +442,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 +455,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