[PATCH i-g-t] tests/intel/xe_fault_injection: Inject errors during observation IOCTL
Pottumuttu, Sai Teja
sai.teja.pottumuttu at intel.com
Mon Mar 3 05:42:23 UTC 2025
On 27-02-2025 04:50, 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.
>
> Signed-off-by: Nakshtra Goyal <nakshtra.goyal at 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)
What if this sysfs read fails for some reason?
I think we can do an igt_assert(igt_sysfs_scanf(sysfs, path, "%"PRIu64,
&config_id) == 1) instead of an if here so that the test doesn't
progress further if the sysfs read fails.
> + 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));
I think we should clean up the config by calling
DRM_XE_OBSERVATION_OP_REMOVE_CONFIG here as well as done above.
Thank You
Sai Teja
> +}
> +
> 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 = []
More information about the igt-dev
mailing list