[Intel-gfx] [PATCH i-g-t 6/8] tests/gem_wait: use igt_cork

Daniele Ceraolo Spurio daniele.ceraolospurio at intel.com
Thu Oct 12 22:27:32 UTC 2017


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>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/gem_wait.c | 52 ++++++++--------------------------------------------
 1 file changed, 8 insertions(+), 44 deletions(-)

diff --git a/tests/gem_wait.c b/tests/gem_wait.c
index cf8c815..5fba233 100644
--- a/tests/gem_wait.c
+++ b/tests/gem_wait.c
@@ -69,51 +69,14 @@ 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);
+	igt_cork_t *cork = flags & (WRITE | AWAIT) ? igt_cork_new(fd) : NULL;
+	igt_spin_t *spin = igt_spin_batch_new(fd, 0, engine,
+					      cork ? cork->handle : 0);
 	struct drm_i915_gem_wait wait = {
-	       	flags & WRITE ? cork.handle : spin->handle
-       	};
+		flags & WRITE ? cork->handle : spin->handle
+	};
 
 	igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
@@ -127,7 +90,7 @@ static void basic(int fd, unsigned engine, unsigned flags)
 			timeout = 1;
 		}
 
-		unplug(&cork);
+		igt_cork_signal(cork);
 		igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
 		while (__gem_wait(fd, &wait) == -ETIME)
@@ -137,7 +100,7 @@ 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);
+		igt_cork_signal(cork);
 		wait.timeout_ns = 0;
 		igt_assert_eq(__gem_wait(fd, &wait), -ETIME);
 
@@ -157,6 +120,7 @@ static void basic(int fd, unsigned engine, unsigned flags)
 		igt_assert(wait.timeout_ns == 0);
 	}
 
+	igt_cork_free(fd, cork);
 	igt_spin_batch_free(fd, spin);
 }
 
-- 
1.9.1



More information about the Intel-gfx mailing list