[igt-dev] [PATCH i-g-t v3 06/11] tests/gem_wait: use igt_cork

Antonio Argenziano antonio.argenziano at intel.com
Fri Feb 16 00:43:05 UTC 2018


From: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>

With igt_cork added as common utility we can use it instead of the
local copy

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>

Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/gem_wait.c | 58 ++++++++++++++------------------------------------------
 1 file changed, 14 insertions(+), 44 deletions(-)

diff --git a/tests/gem_wait.c b/tests/gem_wait.c
index cf8c8154..c9010f1c 100644
--- a/tests/gem_wait.c
+++ b/tests/gem_wait.c
@@ -69,51 +69,15 @@ static void invalid_buf(int fd)
 #define AWAIT 4
 #define WRITE 8
 
-struct cork {
-	int device;
-	uint32_t handle;
-	uint32_t fence;
-};
-
-static struct cork plug(int fd, unsigned flags)
-{
-	struct cork c;
-	struct vgem_bo bo;
-	int dmabuf;
-
-	if ((flags & (WRITE | AWAIT)) == 0)
-		return (struct cork){0};
-
-	c.device = drm_open_driver(DRIVER_VGEM);
-
-	bo.width = bo.height = 1;
-	bo.bpp = 4;
-	vgem_create(c.device, &bo);
-	c.fence = vgem_fence_attach(c.device, &bo, VGEM_FENCE_WRITE);
-
-	dmabuf = prime_handle_to_fd(c.device, bo.handle);
-	c.handle = prime_fd_to_handle(fd, dmabuf);
-	close(dmabuf);
-
-	return c;
-}
-
-static void unplug(struct cork *c)
-{
-	if (!c->device)
-		return;
-
-	vgem_fence_signal(c->device, c->fence);
-	close(c->device);
-}
-
 static void basic(int fd, unsigned engine, unsigned flags)
 {
-	struct cork cork = plug(fd, flags);
-	igt_spin_t *spin = igt_spin_batch_new(fd, 0, engine, cork.handle);
+	struct igt_cork_vgem cork = {0};
+	uint32_t plug =
+		flags & (WRITE | AWAIT) ? igt_cork_plug(fd, VGEM_BO, &cork) : 0;
+	igt_spin_t *spin = igt_spin_batch_new(fd, 0, engine, plug);
 	struct drm_i915_gem_wait wait = {
-	       	flags & WRITE ? cork.handle : spin->handle
-       	};
+		flags & WRITE ? plug : spin->handle
+	};
 
 	igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
@@ -127,7 +91,9 @@ static void basic(int fd, unsigned engine, unsigned flags)
 			timeout = 1;
 		}
 
-		unplug(&cork);
+		if (flags & (WRITE | AWAIT))
+			igt_cork_unplug(VGEM_BO, &cork);
+
 		igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
 		while (__gem_wait(fd, &wait) == -ETIME)
@@ -137,7 +103,9 @@ static void basic(int fd, unsigned engine, unsigned flags)
 		igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 		igt_assert_eq_s64(wait.timeout_ns, 0);
 
-		unplug(&cork);
+		if (flags & (WRITE | AWAIT))
+			igt_cork_unplug(VGEM_BO, &cork);
+
 		wait.timeout_ns = 0;
 		igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
@@ -157,6 +125,8 @@ static void basic(int fd, unsigned engine, unsigned flags)
 		igt_assert(wait.timeout_ns == 0);
 	}
 
+	if (plug)
+		gem_close(fd, plug);
 	igt_spin_batch_free(fd, spin);
 }
 
-- 
2.14.2



More information about the igt-dev mailing list