[igt-dev] [PATCH 2/3] tests/core_hotunplug: Add hotunplug with exported dma-buf test.

Andrey Grodzovsky andrey.grodzovsky at amd.com
Thu Jun 3 15:07:59 UTC 2021


Unplug a device while an exported BO is still around.

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky at amd.com>
---
 tests/core_hotunplug.c | 62 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c
index b553bc87..7cde0157 100644
--- a/tests/core_hotunplug.c
+++ b/tests/core_hotunplug.c
@@ -684,6 +684,59 @@ static void hotunplug_rescan(struct hotunplug *priv)
 	igt_assert_f(healthcheck(priv, false), "%s\n", priv->failure);
 }
 
+static void hotunplug_with_exported_bo_rescan(struct hotunplug *priv)
+{
+	int r;
+	uint32_t dma_buf_fd;
+	unsigned int *ptr;
+	amdgpu_bo_handle bo_handle;
+	uint32_t major, minor;
+	amdgpu_device_handle device;
+
+	struct amdgpu_bo_alloc_request request = {
+		.alloc_size = 4096,
+		.phys_alignment = 4096,
+		.preferred_heap = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = 0,
+	};
+
+	pre_check(priv);
+
+	priv->fd.drm = local_drm_open_driver(false, "", " for hot unplug with export");
+
+
+	r = amdgpu_device_initialize(priv->fd.drm, &major, &minor, &device);
+	igt_require(r == 0);
+
+	amdgpu_bo_alloc(device, &request, &bo_handle);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_bo_export(bo_handle, amdgpu_bo_handle_type_dma_buf_fd, &dma_buf_fd);
+	igt_assert(r == 0);
+
+	ptr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf_fd, 0);
+	igt_assert(ptr != MAP_FAILED);
+
+	amdgpu_bo_free(bo_handle);
+	amdgpu_device_deinitialize(device);
+	priv->fd.drm = close_device(priv->fd.drm, "late ", "removed ");
+	igt_assert_eq(priv->fd.drm, -1);
+
+	device_unplug(priv, "hot ", 0);
+
+	*ptr = 0xdeafbeef;
+
+	munmap(ptr, 4096);
+	close (dma_buf_fd);
+	return;
+
+	bus_rescan(priv, 0);
+
+	igt_assert_f(healthcheck(priv, false), "%s\n", priv->failure);
+}
+
+
+
 static void hotrebind(struct hotunplug *priv)
 {
 	pre_check(priv);
@@ -832,6 +885,15 @@ igt_main
 			recover(&priv);
 	}
 
+	igt_subtest_group {
+			igt_describe("Check if device with exported dma buf can be cleanly unplugged, then released and restored");
+			igt_subtest("hotunplug-with-exported-bo-rescan")
+			hotunplug_with_exported_bo_rescan(&priv);
+
+			igt_fixture
+				recover(&priv);
+	}
+
 	igt_fixture
 		post_healthcheck(&priv);
 
-- 
2.25.1



More information about the igt-dev mailing list