[PATCH i-g-t 1/4] tests/intel/xe_sriov_vfio: Add module load/unload subtests

Marcin Bernatowicz
2026-03-18T16:15:08Z

Introduce subtests that verify xe_vfio_pci can be loaded and unloaded,
while reporting already-loaded or already-unloaded initial state as
success. The unload path still skips when xe-vfio-pci has bound devices,
to avoid attempting removal while the driver is in use.

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Lukasz Laguna <lukasz.laguna@intel.com>
---
tests/intel/xe_sriov_vfio.c | 88 +++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 89 insertions(+)
create mode 100644 tests/intel/xe_sriov_vfio.c

diff --git a/tests/intel/xe_sriov_vfio.c b/tests/intel/xe_sriov_vfio.c
new file mode 100644
index 000000000..2fe0137e1
--- /dev/null
+++ b/tests/intel/xe_sriov_vfio.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright(c) 2026 Intel Corporation. All rights reserved.
+ */
+
+#include <ctype.h>
+#include <dirent.h>
+
+#include "igt_core.h"
+#include "igt_kmod.h"
+
+/**
+ * TEST: xe_sriov_vfio
+ * Category: Core
+ * Mega feature: SR-IOV
+ * Sub-category: SR-IOV VFIO
+ * Functionality: VFIO module
+ * Description: Verify basic xe-vfio-pci module operations.
+ *
+ * SUBTEST: load-xe-vfio-pci
+ * Description: Attempt to load xe_vfio_pci module.
+ *
+ * SUBTEST: unload-xe-vfio-pci
+ * Description: Attempt to unload xe_vfio_pci module (skips if busy).
+ */
+
+IGT_TEST_DESCRIPTION("Xe SR-IOV VFIO tests (xe-vfio-pci)");
+
+static const char *XE_VFIO_PCI_MOD = "xe_vfio_pci";
+static const char *XE_VFIO_PCI_DRV = "xe-vfio-pci";
+
+static bool pci_driver_has_any_bound_devices(const char *driver)
+{
+ char path[PATH_MAX];
+ DIR *dir;
+ struct dirent *de;
+
+ snprintf(path, sizeof(path), "/sys/bus/pci/drivers/%s", driver);
+ dir = opendir(path);
+ if (!dir)
+ return false;
+
+ while ((de = readdir(dir))) {
+ if (de->d_type != DT_LNK)
+ continue;
+ if (!isdigit(de->d_name[0]))
+ continue;
+
+ closedir(dir);
+ return true;
+ }
+
+ closedir(dir);
+ return false;
+}
+
+int igt_main()
+{
+ igt_describe("Attempt to load xe_vfio_pci module.");
+ igt_subtest("load-xe-vfio-pci") {
+ int ret;
+
+ if (igt_kmod_is_loaded(XE_VFIO_PCI_MOD))
+ igt_info("%s already loaded\n", XE_VFIO_PCI_MOD);
+
+ ret = igt_kmod_load(XE_VFIO_PCI_MOD, NULL);
+ igt_assert_f(ret == 0, "Failed to load %s (%d)\n", XE_VFIO_PCI_MOD, ret);
+ igt_assert(igt_kmod_is_loaded(XE_VFIO_PCI_MOD));
+ }
+
+ igt_describe("Attempt to unload xe_vfio_pci module (skips if busy).");
+ igt_subtest("unload-xe-vfio-pci") {
+ int ret;
+
+ if (!igt_kmod_is_loaded(XE_VFIO_PCI_MOD)) {
+ igt_info("%s already unloaded\n", XE_VFIO_PCI_MOD);
+ igt_success();
+ }
+
+ if (pci_driver_has_any_bound_devices(XE_VFIO_PCI_DRV))
+ igt_skip("%s has bound devices; not attempting unload\n", XE_VFIO_PCI_DRV);
+
+ ret = igt_kmod_unload(XE_VFIO_PCI_MOD);
+ igt_assert_f(ret == 0, "Failed to unload %s (%d)\n", XE_VFIO_PCI_MOD, ret);
+ igt_assert_f(!igt_kmod_is_loaded(XE_VFIO_PCI_MOD), "%s still loaded\n",
+ XE_VFIO_PCI_MOD);
+ }
+}
diff --git a/tests/meson.build b/tests/meson.build
index cecb4a8ae..26d9345ec 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -337,6 +337,7 @@ intel_xe_progs = [
'xe_sriov_admin',
'xe_sriov_auto_provisioning',
'xe_sriov_flr',
+ 'xe_sriov_vfio',
'xe_sriov_scheduling',
'xe_survivability',
'xe_sriov_vram',
--
2.43.0