From: "Bernatowicz, Marcin" <marcin.bernatowicz@linux.intel.com>
To: Lukasz Laguna <lukasz.laguna@intel.com>, igt-dev@lists.freedesktop.org
Cc: marcin.bernatowicz@intel.com
Subject: Re: [PATCH v4 2/2] tests/sriov_basic: Validate PF unbind with VFs enabled
Date: Thu, 6 Aug 2026 12:12:25 +0200 [thread overview]
Message-ID: <582e9353-c5e4-4257-acce-be88bf55ff50@linux.intel.com> (raw)
In-Reply-To: <20260806100332.1228103-3-lukasz.laguna@intel.com>
On 8/6/2026 12:03 PM, Lukasz Laguna wrote:
> 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>
> ---
> v4:
> - Fix unspecified values of local variables after longjmp (Marcin)
> ---
> tests/sriov_basic.c | 98 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 96 insertions(+), 2 deletions(-)
>
> diff --git a/tests/sriov_basic.c b/tests/sriov_basic.c
> index 1e563cee9..050d209b1 100644
> --- a/tests/sriov_basic.c
> +++ b/tests/sriov_basic.c
> @@ -3,8 +3,13 @@
> * Copyright(c) 2023 Intel Corporation. All rights reserved.
> */
>
> +#include <dirent.h>
> +
> #include "drmtest.h"
> #include "igt_core.h"
> +#include "igt_device.h"
> +#include "igt_device_scan.h"
> +#include "igt_pci.h"
> #include "igt_sriov_device.h"
>
> IGT_TEST_DESCRIPTION("Basic tests for enabling SR-IOV Virtual Functions");
> @@ -118,10 +123,71 @@ 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(!drm_close_driver(*pf_fd));
> + *pf_fd = -1;
> + 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);
> +}
> +
> +static void restore_pf_after_unbind(int *pf_fd, const char *pci_slot, const char *driver)
> +{
> + int ret;
> +
> + ret = igt_pci_get_bound_driver_name(pci_slot, NULL, 0);
> + if (!ret)
> + igt_assert(!igt_pci_driver_bind(driver, pci_slot));
> + else
> + igt_assert_eq(ret, 1);
> +
> + if (*pf_fd < 0)
> + *pf_fd = drm_open_driver(DRIVER_ANY);
> +}
> +
> int igt_main()
> {
> - int pf_fd;
> - bool autoprobe;
> + static int pf_fd = -1;
> + static bool autoprobe;
>
> igt_fixture() {
> pf_fd = drm_open_driver(DRIVER_ANY);
> @@ -210,7 +276,35 @@ int igt_main()
> }
> }
>
> + igt_subtest_group() {
> + static char pci_slot[NAME_MAX];
> + static char driver[NAME_MAX];
> +
> + igt_fixture() {
> + igt_device_set_filter_from_fd(pf_fd);
> + 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() {
> + restore_pf_after_unbind(&pf_fd, pci_slot, driver);
> + }
> + }
> +
> 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)");
LGTM,
Reviewed-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
next prev parent reply other threads:[~2026-08-06 10:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 10:03 [PATCH v4 0/2] tests/sriov_basic: Validate PF unbind with VFs enabled Lukasz Laguna
2026-08-06 10:03 ` [PATCH v4 1/2] lib/igt_device_scan: Extract helper setting device filter from fd Lukasz Laguna
2026-08-06 10:03 ` [PATCH v4 2/2] tests/sriov_basic: Validate PF unbind with VFs enabled Lukasz Laguna
2026-08-06 10:12 ` Bernatowicz, Marcin [this message]
2026-08-06 22:37 ` ✓ Xe.CI.BAT: success for tests/sriov_basic: Validate PF unbind with VFs enabled (rev2) Patchwork
2026-08-06 23:06 ` ✓ i915.CI.BAT: " Patchwork
2026-08-07 4:59 ` ✗ i915.CI.Full: failure " Patchwork
2026-08-07 11:29 ` ✗ Xe.CI.FULL: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=582e9353-c5e4-4257-acce-be88bf55ff50@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=lukasz.laguna@intel.com \
--cc=marcin.bernatowicz@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox