[igt-dev] [PATCH] tests: Add a new test for driver/device hot remove

Janusz Krzysztofik janusz.krzysztofik at intel.com
Thu Mar 28 16:47:19 UTC 2019


Run a dummy load in background to put some workload on a device, then try
to either remove (unplug) the device from its bus, or unbind the device's
driver from it, depending on which subtest has been selected.

The driver hot unbind / device hot unplug operation is expected to succeed
in a reasonable time, however long timeouts are used to allow kernel
level timeouts pop up first if any.

Please note that if running both subtests consecutively, the second one
is always skipped as the device is no longer available as soon as the
first subtest is completed.  The most reliable way to run another subtest
is to reboot the system first, then select next subtest to be run.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik at intel.com>
---
 tests/Makefile.sources |   1 +
 tests/drm_hot_remove.c | 106 +++++++++++++++++++++++++++++++++++++++++
 tests/meson.build      |   1 +
 3 files changed, 108 insertions(+)
 create mode 100644 tests/drm_hot_remove.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 71ccf00a..0f194e2c 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -18,6 +18,7 @@ TESTS_progs = \
 	core_getversion \
 	core_setmaster_vs_auth \
 	debugfs_test \
+	drm_hot_remove \
 	drm_import_export \
 	drm_mm \
 	drm_read \
diff --git a/tests/drm_hot_remove.c b/tests/drm_hot_remove.c
new file mode 100644
index 00000000..fbb033b4
--- /dev/null
+++ b/tests/drm_hot_remove.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "igt_device.h"
+#include "igt_dummyload.h"
+#include "igt_sysfs.h"
+
+#include <getopt.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static void driver_unbind(int device)
+{
+	char path[PATH_MAX], *dev_bus_addr;
+	int dir, len;
+
+	dir = igt_sysfs_open(device);
+
+	len = readlinkat(dir, "device", path, sizeof(path));
+	path[len] = '\0';
+	dev_bus_addr = strrchr(path, '/') + 1;
+
+	igt_sysfs_set(dir, "device/driver/unbind", dev_bus_addr);
+
+	close(dir);
+}
+
+static void device_unplug(int device)
+{
+	int dir;
+
+	dir = igt_sysfs_open(device);
+
+	igt_sysfs_set(dir, "device/remove", "1");
+
+	close(dir);
+}
+
+igt_main {
+	int device;
+
+	igt_fixture {
+		device = __drm_open_driver(DRIVER_ANY);
+	}
+
+	igt_subtest("unplug") {
+		igt_spin_t *spin;
+
+		/* Verify if a suitable DRM device/driver exists */
+		igt_skip_on(device < 0);
+
+		/* Run background workload */
+		spin = igt_spin_batch_new(device, .flags = IGT_SPIN_POLL_RUN);
+		igt_spin_busywait_until_running(spin);
+
+		/* Make the device disappear */
+		igt_set_timeout(60, "Device unplug timeout!");
+		device_unplug(device);
+		igt_reset_timeout();
+
+		close(device);
+		device = -1;
+	}
+
+	igt_subtest("unbind") {
+		igt_spin_t *spin;
+
+		/* Verify if a suitable DRM device/driver exists */
+		igt_skip_on(device < 0);
+
+		/* Run background workload */
+		spin = igt_spin_batch_new(device, .flags = IGT_SPIN_POLL_RUN);
+		igt_spin_busywait_until_running(spin);
+
+		/* Unbind the driver */
+		igt_set_timeout(60, "Driver unbind timeout!");
+		driver_unbind(device);
+		igt_reset_timeout();
+
+		close(device);
+		device = -1;
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index 9015f809..379addb1 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -5,6 +5,7 @@ test_progs = [
 	'core_getversion',
 	'core_setmaster_vs_auth',
 	'debugfs_test',
+	'drm_hot_remove',
 	'drm_import_export',
 	'drm_mm',
 	'drm_read',
-- 
2.20.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


More information about the igt-dev mailing list