[RFC,PATH,i-g-t,14/15] tests/core_hotunplug: Assert expected device presence/absence
diff mbox series

Message ID 20200720121908.28124-15-janusz.krzysztofik@linux.intel.com
State New
Headers show
Series
  • tests/core_hotunplug: Fixes and enhancements
Related show

Commit Message

Janusz Krzysztofik July 20, 2020, 12:19 p.m. UTC
Don't rely on successful write to sysfs control files, assert existence
/ non-existence of a respective device sysfs node as well.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
 tests/core_hotunplug.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch
diff mbox series

diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c
index 16b3a244f..9bca967c1 100644
--- a/tests/core_hotunplug.c
+++ b/tests/core_hotunplug.c
@@ -99,6 +99,9 @@  static void driver_unbind(struct hotunplug *priv, const char *prefix)
 				   priv->dev_bus_addr),
 		     "Driver unbind failure!");
 	igt_reset_timeout();
+
+	igt_assert_f(faccessat(priv->fd.sysfs_drv, priv->dev_bus_addr, F_OK, 0),
+		     "Unbound device still present\n");
 }
 
 /* Re-bind the driver to the device */
@@ -111,6 +114,10 @@  static void driver_bind(struct hotunplug *priv)
 				   priv->dev_bus_addr),
 		     "Driver re-bind failure!");
 	igt_reset_timeout();
+
+	igt_fail_on_f(faccessat(priv->fd.sysfs_drv, priv->dev_bus_addr,
+				F_OK, 0),
+		      "Rebound device not present!\n");
 }
 
 /* Remove (virtually unplug) the device from its bus */
@@ -133,6 +140,9 @@  static void device_unplug(struct hotunplug *priv, const char *prefix)
 	priv->fd.sysfs_dev = local_close(priv->fd.sysfs_dev);
 	igt_assert_f(priv->fd.sysfs_dev == -1,
 		     "Device sysfs node close failed\n");
+
+	igt_assert_f(faccessat(priv->fd.sysfs_bus, priv->dev_bus_addr, F_OK, 0),
+		     "Unplugged device still present\n");
 }
 
 /* Re-discover the device by rescanning its bus */
@@ -144,6 +154,10 @@  static void bus_rescan(struct hotunplug *priv)
 	igt_assert_f(igt_sysfs_set(priv->fd.sysfs_bus, "../rescan", "1"),
 		       "Bus rescan failure!");
 	igt_reset_timeout();
+
+	igt_fail_on_f(faccessat(priv->fd.sysfs_bus, priv->dev_bus_addr,
+				F_OK, 0),
+		      "Fakely unplugged device not rediscovered!\n");
 }
 
 static void cleanup(struct hotunplug *priv)