[igt-dev] [PATCH] Add a test for importing array sync_files

Jason Ekstrand jason at jlekstrand.net
Tue Aug 2 21:01:03 UTC 2022


As of 68129f431faa ("dma-buf: warn about containers in dma_resv object")
in the kernel, dma_resv_add_shared_fence will warn if you attempt to add
a container fence.  This test tries to trigger this warning by adding a
bunch of fences to a dma-buf, exporting a sync_file (which should
contain an array fence) and then importing that sync_file into a new
dma-buf.

Signed-off-by: Jason Ekstrand <jason.ekstrand at collabora.com>
---
 tests/dmabuf_sync_file.c | 48 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tests/dmabuf_sync_file.c b/tests/dmabuf_sync_file.c
index 2179a76d..d3d149ac 100644
--- a/tests/dmabuf_sync_file.c
+++ b/tests/dmabuf_sync_file.c
@@ -461,6 +461,48 @@ static void test_import_multiple(int fd, bool write)
 	igt_assert(!sync_file_busy(write_sync_file));
 }
 
+static void test_import_one_sync_file_multiple_fences(int fd)
+{
+	struct vgem_bo bo;
+	int i, dmabuf, sync_file;
+	uint32_t fences[32];
+
+	igt_require_sw_sync();
+	igt_require(has_dmabuf_import_sync_file(fd));
+
+	bo.width = 1;
+	bo.height = 1;
+	bo.bpp = 32;
+	vgem_create(fd, &bo);
+
+	dmabuf = prime_handle_to_fd(fd, bo.handle);
+
+	for (i = 0; i < ARRAY_SIZE(fences); i++)
+		fences[i] = vgem_fence_attach(fd, &bo, 0);
+
+	sync_file = dmabuf_export_sync_file(dmabuf, DMA_BUF_SYNC_WRITE);
+
+	close(dmabuf);
+	gem_close(fd, bo.handle);
+
+	vgem_create(fd, &bo);
+
+	dmabuf = prime_handle_to_fd(fd, bo.handle);
+
+	dmabuf_import_sync_file(dmabuf, DMA_BUF_SYNC_WRITE, sync_file);
+
+	for (i = 0; i < ARRAY_SIZE(fences); i++) {
+		igt_assert(dmabuf_busy(dmabuf, DMA_BUF_SYNC_WRITE));
+		vgem_fence_signal(fd, fences[i]);
+	}
+
+	igt_assert(!dmabuf_busy(dmabuf, DMA_BUF_SYNC_WRITE));
+
+	close(sync_file);
+	close(dmabuf);
+	gem_close(fd, bo.handle);
+}
+
 igt_main
 {
 	int fd;
@@ -505,4 +547,10 @@ igt_main
 		     "operations.");
 	igt_subtest("import-multiple-read-write")
 		test_import_multiple(fd, true);
+
+	igt_describe("Test importing a sync file containing multiple fences. "
+		     "The core dma_resv code will warn if we try to add "
+		     "container fences directly.");
+	igt_subtest("import-sync-file-multiple-fences")
+		test_import_one_sync_file_multiple_fences(fd);
 }
-- 
2.37.1



More information about the igt-dev mailing list