From: Lukasz Laguna <lukasz.laguna@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: marcin.bernatowicz@intel.com, janusz.krzysztofik@intel.com
Subject: [PATCH 1/2] lib/igt_device_scan: Extract helper setting device filter from fd
Date: Wed, 29 Jul 2026 12:09:17 +0200 [thread overview]
Message-ID: <20260729100918.842807-1-lukasz.laguna@intel.com> (raw)
Helper sets device filter to the device corresponding to DRM device file
descriptor. Move the implementation from core_hotunplug test into the
library, so it can be reused in other tests.
Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
---
v3:
- move it to igt_device_scan (Janusz)
---
lib/igt_device_scan.c | 23 +++++++++++++++++++++++
lib/igt_device_scan.h | 2 ++
tests/core_hotunplug.c | 17 +----------------
3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index 7c7995224..decf19646 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -2477,3 +2477,26 @@ int igt_device_prepare_filtered_view(const char *vendor)
return gpu_count;
}
+
+/**
+ * igt_device_set_filter_from_fd:
+ * @fd: DRM device file descriptor
+ *
+ * Set device filter to the device corresponding to @fd.
+ */
+void igt_device_set_filter_from_fd(int fd)
+{
+ const char *filter_type = "sys:";
+ char filter[strlen(filter_type) + PATH_MAX + 1];
+ char *dst = stpcpy(filter, filter_type);
+ char path[PATH_MAX + 1];
+ struct stat st;
+
+ igt_assert(!fstat(fd, &st) && S_ISCHR(st.st_mode));
+ snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device",
+ major(st.st_rdev), minor(st.st_rdev));
+ igt_assert(realpath(path, dst));
+
+ igt_device_filter_free_all();
+ igt_assert_eq(igt_device_filter_add(filter), 1);
+}
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index f24a193cd..ac75fea8c 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -103,4 +103,6 @@ int igt_open_render(struct igt_device_card *card);
/* Add or use filters to match multiGPU devices */
int igt_device_prepare_filtered_view(const char *vendor);
+void igt_device_set_filter_from_fd(int fd);
+
#endif /* __IGT_DEVICE_SCAN_H__ */
diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c
index 7c9dae1bf..33de65369 100644
--- a/tests/core_hotunplug.c
+++ b/tests/core_hotunplug.c
@@ -550,21 +550,6 @@ static void post_healthcheck(struct hotunplug *priv)
cleanup(priv);
}
-static void set_filter_from_device(int fd)
-{
- const char *filter_type = "sys:";
- char filter[strlen(filter_type) + PATH_MAX + 1];
- char *dst = stpcpy(filter, filter_type);
- char path[PATH_MAX + 1];
-
- igt_assert(igt_sysfs_path(fd, path, PATH_MAX));
- igt_ignore_warn(strncat(path, "/device", PATH_MAX - strlen(path)));
- igt_assert(realpath(path, dst));
-
- igt_device_filter_free_all();
- igt_assert_eq(igt_device_filter_add(filter), 1);
-}
-
/* Subtests */
static void unbind_rebind(struct hotunplug *priv)
@@ -713,7 +698,7 @@ int igt_main()
}
/* Make sure subtests always reopen the same device */
- set_filter_from_device(fd_drm);
+ igt_device_set_filter_from_fd(fd_drm);
igt_assert_eq(close_device(fd_drm, "", "selected "), -1);
--
2.43.0
next reply other threads:[~2026-07-29 10:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 10:09 Lukasz Laguna [this message]
2026-07-29 10:09 ` [PATCH 2/2] tests/sriov_basic: Validate PF unbind with VFs enabled Lukasz Laguna
2026-07-29 17:36 ` ✓ Xe.CI.BAT: success for series starting with [1/2] lib/igt_device_scan: Extract helper setting device filter from fd Patchwork
2026-07-29 17:47 ` ✓ i915.CI.BAT: " Patchwork
2026-07-29 22:17 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-07-30 6:18 ` ✗ i915.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=20260729100918.842807-1-lukasz.laguna@intel.com \
--to=lukasz.laguna@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=janusz.krzysztofik@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