[PATCH i-g-t 1/4] tests/core_hotunplug: Use PCI device sysfs entry, not DRM
Janusz Krzysztofik
janusz.krzysztofik at linux.intel.com
Sat Jun 6 17:51:02 UTC 2020
Future subtests may want to still access the device after driver
unbind. Refactor prepare() helper.
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
---
tests/core_hotunplug.c | 67 ++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 28 deletions(-)
diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c
index e03f3b945..2192a1293 100644
--- a/tests/core_hotunplug.c
+++ b/tests/core_hotunplug.c
@@ -49,42 +49,53 @@ struct hotunplug {
/* Helpers */
-static void prepare_for_unbind(struct hotunplug *priv, char *buf, int buflen)
+static int prepare_common(struct hotunplug *priv)
{
- int len;
+ int fd_sysfs_drm;
+
+ igt_debug("opening device\n");
+ priv->fd.drm = __drm_open_driver(DRIVER_ANY);
+ igt_assert(priv->fd.drm >= 0);
+
+ fd_sysfs_drm = igt_sysfs_open(priv->fd.drm);
+ igt_assert(fd_sysfs_drm >= 0);
+
+ return fd_sysfs_drm;
+}
+
+static void prepare_for_rebind(struct hotunplug *priv, char *buf, int buflen)
+{
+ int fd_sysfs_drm, len;
igt_assert(buflen);
- priv->fd.sysfs_drv = openat(priv->fd.sysfs_dev, "device/driver",
- O_DIRECTORY);
- igt_assert(priv->fd.sysfs_drv >= 0);
+ fd_sysfs_drm = prepare_common(priv);
+
+ priv->fd.sysfs_drv = openat(fd_sysfs_drm, "device/driver", O_DIRECTORY);
- len = readlinkat(priv->fd.sysfs_dev, "device", buf, buflen - 1);
+ len = readlinkat(fd_sysfs_drm, "device", buf, buflen - 1);
buf[len] = '\0';
priv->dev_bus_addr = strrchr(buf, '/');
- igt_assert(priv->dev_bus_addr++);
- /* sysfs_dev no longer needed */
- close(priv->fd.sysfs_dev);
+ close(fd_sysfs_drm);
+
+ igt_assert(priv->fd.sysfs_drv >= 0);
+ igt_assert(priv->dev_bus_addr++);
}
-static void prepare(struct hotunplug *priv, char *buf, int buflen)
+static void prepare_for_rescan(struct hotunplug *priv)
{
- igt_debug("opening device\n");
- priv->fd.drm = __drm_open_driver(DRIVER_ANY);
- igt_assert(priv->fd.drm >= 0);
+ int fd_sysfs_drm = prepare_common(priv);
- priv->fd.sysfs_dev = igt_sysfs_open(priv->fd.drm);
- igt_assert(priv->fd.sysfs_dev >= 0);
+ priv->fd.sysfs_dev = openat(fd_sysfs_drm, "device", O_DIRECTORY);
- if (buf) {
- prepare_for_unbind(priv, buf, buflen);
- } else {
- /* prepare for bus rescan */
- priv->fd.sysfs_bus = openat(priv->fd.sysfs_dev,
- "device/subsystem", O_DIRECTORY);
- igt_assert(priv->fd.sysfs_bus >= 0);
- }
+ priv->fd.sysfs_bus = openat(fd_sysfs_drm, "device/subsystem",
+ O_DIRECTORY);
+
+ close(fd_sysfs_drm);
+
+ igt_assert(priv->fd.sysfs_dev >= 0);
+ igt_assert(priv->fd.sysfs_bus >= 0);
}
static const char *failure;
@@ -118,7 +129,7 @@ static void device_unplug(int fd_sysfs_dev)
{
failure = "Device unplug timeout!";
igt_set_timeout(60, failure);
- igt_sysfs_set(fd_sysfs_dev, "device/remove", "1");
+ igt_sysfs_set(fd_sysfs_dev, "remove", "1");
igt_reset_timeout();
failure = NULL;
@@ -179,7 +190,7 @@ static void unbind_rebind(void)
struct hotunplug priv;
char buf[PATH_MAX];
- prepare(&priv, buf, sizeof(buf));
+ prepare_for_rebind(&priv, buf, sizeof(buf));
igt_debug("closing the device\n");
close(priv.fd.drm);
@@ -197,7 +208,7 @@ static void unplug_rescan(void)
{
struct hotunplug priv;
- prepare(&priv, NULL, 0);
+ prepare_for_rescan(&priv);
igt_debug("closing the device\n");
close(priv.fd.drm);
@@ -216,7 +227,7 @@ static void hotunbind_lateclose(void)
struct hotunplug priv;
char buf[PATH_MAX];
- prepare(&priv, buf, sizeof(buf));
+ prepare_for_rebind(&priv, buf, sizeof(buf));
igt_debug("hot unbinding the driver from the device\n");
driver_unbind(priv.fd.sysfs_drv, priv.dev_bus_addr);
@@ -234,7 +245,7 @@ static void hotunplug_lateclose(void)
{
struct hotunplug priv;
- prepare(&priv, NULL, 0);
+ prepare_for_rescan(&priv);
igt_debug("hot unplugging the device\n");
device_unplug(priv.fd.sysfs_dev);
--
2.21.1
More information about the Intel-gfx-trybot
mailing list