All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/sriov_basic: Validate PF unbind with VFs enabled
@ 2026-07-17 13:44 Lukasz Laguna
  2026-07-17 14:56 ` ✓ i915.CI.BAT: success for " Patchwork
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Lukasz Laguna @ 2026-07-17 13:44 UTC (permalink / raw)
  To: igt-dev
  Cc: marcin.bernatowicz, satyanarayana.k.v.p, michal.wajdeczko,
	jakub1.kolakowski, adam.miszczak

Add new subtests covering PF driver unbind with VFs enabled in two
scenarios:
- with all VFs enabled,
- with one VF enabled and probed.

The tests verify that PF ends up unbound and VFs are disabled.

Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
---
 tests/sriov_basic.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/tests/sriov_basic.c b/tests/sriov_basic.c
index 1e563cee9..1c5bb878e 100644
--- a/tests/sriov_basic.c
+++ b/tests/sriov_basic.c
@@ -3,8 +3,13 @@
  * Copyright(c) 2023 Intel Corporation. All rights reserved.
  */
 
+#include <limits.h>
+#include <dirent.h>
+
 #include "drmtest.h"
 #include "igt_core.h"
+#include "igt_device.h"
+#include "igt_pci.h"
 #include "igt_sriov_device.h"
 
 IGT_TEST_DESCRIPTION("Basic tests for enabling SR-IOV Virtual Functions");
@@ -118,6 +123,51 @@ static void bind_unbind_vf(int pf_fd, unsigned int vf_num)
 	igt_sriov_disable_vfs(pf_fd);
 }
 
+static unsigned int count_pci_virtfn_entries(const char *pci_slot)
+{
+	char path[PATH_MAX];
+	unsigned int count = 0;
+	struct dirent *de;
+	DIR *dir;
+
+	snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s", pci_slot);
+	dir = opendir(path);
+	igt_assert_f(dir, "Failed to open %s\n", path);
+
+	while ((de = readdir(dir))) {
+		if (!strncmp(de->d_name, "virtfn", strlen("virtfn")))
+			count++;
+	}
+
+	closedir(dir);
+
+	return count;
+}
+
+/**
+ * SUBTEST: pf-unbind-with-vfs-enabled-numvfs-all
+ * Description:
+ *   Verify the PF driver unbind when all VFs are enabled.
+ *
+ * SUBTEST: pf-unbind-with-vf-probed
+ * Description:
+ *   Verify the PF driver unbind when one VF is enabled and probed.
+ */
+static void pf_unbind_with_vfs_enabled(int pf_fd, unsigned int num_vfs, bool vf_probe)
+{
+	char pci_slot[NAME_MAX];
+
+	vf_probe ? igt_sriov_enable_driver_autoprobe(pf_fd) :
+		   igt_sriov_disable_driver_autoprobe(pf_fd);
+	igt_sriov_enable_vfs(pf_fd, num_vfs);
+
+	igt_device_get_pci_slot_name(pf_fd, pci_slot);
+	igt_assert_eq(count_pci_virtfn_entries(pci_slot), num_vfs);
+	igt_assert(!igt_pci_device_unbind(pci_slot));
+	igt_assert(!igt_pci_get_bound_driver_name(pci_slot, NULL, 0));
+	igt_assert_eq(count_pci_virtfn_entries(pci_slot), 0);
+}
+
 int igt_main()
 {
 	int pf_fd;
@@ -210,7 +260,39 @@ int igt_main()
 		}
 	}
 
+	igt_subtest_group() {
+		char pci_slot[NAME_MAX];
+		char driver[NAME_MAX];
+
+		igt_fixture() {
+			igt_device_get_pci_slot_name(pf_fd, pci_slot);
+			igt_assert(igt_pci_get_bound_driver_name(pci_slot, driver, sizeof(driver)));
+		}
+
+		igt_describe("Test unbinds the PF driver when all VFs are enabled");
+		igt_subtest("pf-unbind-with-vfs-enabled-numvfs-all") {
+			for_max_sriov_num_vfs(pf_fd, num_vfs) {
+				pf_unbind_with_vfs_enabled(pf_fd, num_vfs, false);
+			}
+		}
+
+		igt_describe("Test unbinds the PF driver when one VF is enabled and probed");
+		igt_subtest("pf-unbind-with-vf-probed") {
+			pf_unbind_with_vfs_enabled(pf_fd, 1, true);
+		}
+
+		igt_fixture() {
+			if (!igt_pci_get_bound_driver_name(pci_slot, NULL, 0)) {
+				close(pf_fd);
+				pf_fd = -1;
+				igt_assert(!igt_pci_driver_bind(driver, pci_slot));
+				pf_fd = drm_open_driver(DRIVER_ANY);
+			}
+		}
+	}
+
 	igt_fixture() {
+		igt_abort_on_f(pf_fd < 0, "Device is not accessible\n");
 		igt_sriov_disable_vfs(pf_fd);
 		/* abort to avoid execution of next tests with enabled VFs */
 		igt_abort_on_f(igt_sriov_get_enabled_vfs(pf_fd) > 0, "Failed to disable VF(s)");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-21 13:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 13:44 [PATCH] tests/sriov_basic: Validate PF unbind with VFs enabled Lukasz Laguna
2026-07-17 14:56 ` ✓ i915.CI.BAT: success for " Patchwork
2026-07-17 15:05 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-17 21:14 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-07-18  1:30 ` ✗ i915.CI.Full: " Patchwork
2026-07-21 13:28 ` [PATCH] " Bernatowicz, Marcin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.