summaryrefslogtreecommitdiff
path: root/tests/vgem_basic.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-06-22 07:21:09 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2016-07-12 21:52:41 +0100
commit93256e3e548c14117afb7e8178f56b0e0f520d10 (patch)
tree03cf740ee5c520c2b04f64e1e17e69871197c37f /tests/vgem_basic.c
parent36ffa375d33e4e0b9ce05e8d62df04cda8591903 (diff)
vgem: Add basic dma-buf fence interop
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests/vgem_basic.c')
-rw-r--r--tests/vgem_basic.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 578148b2..31166241 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -27,6 +27,7 @@
#include "igt_sysfs.h"
#include <sys/mman.h>
+#include <sys/poll.h>
#include <sys/stat.h>
#include <dirent.h>
@@ -150,6 +151,82 @@ static void test_dmabuf_mmap(int fd)
munmap(ptr, bo.size);
}
+static bool prime_busy(int fd, bool excl)
+{
+ struct pollfd pfd = { .fd = fd, .events = excl ? POLLOUT : POLLIN };
+ return poll(&pfd, 1, 0) == 0;
+}
+
+static void test_dmabuf_fence(int fd)
+{
+ struct vgem_bo bo;
+ int dmabuf;
+ uint32_t fence;
+
+ bo.width = 1024;
+ bo.height = 1;
+ bo.bpp = 32;
+ vgem_create(fd, &bo);
+
+ /* export, then fence */
+
+ dmabuf = prime_handle_to_fd(fd, bo.handle);
+
+ fence = vgem_fence_attach(fd, &bo, false);
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(prime_busy(dmabuf, true));
+
+ vgem_fence_signal(fd, fence);
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(!prime_busy(dmabuf, true));
+
+ fence = vgem_fence_attach(fd, &bo, true);
+ igt_assert(prime_busy(dmabuf, false));
+ igt_assert(prime_busy(dmabuf, true));
+
+ vgem_fence_signal(fd, fence);
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(!prime_busy(dmabuf, true));
+
+ gem_close(fd, bo.handle);
+}
+
+static void test_dmabuf_fence_before(int fd)
+{
+ struct vgem_bo bo;
+ int dmabuf;
+ uint32_t fence;
+
+ bo.width = 1024;
+ bo.height = 1;
+ bo.bpp = 32;
+ vgem_create(fd, &bo);
+
+ fence = vgem_fence_attach(fd, &bo, false);
+ dmabuf = prime_handle_to_fd(fd, bo.handle);
+
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(prime_busy(dmabuf, true));
+
+ vgem_fence_signal(fd, fence);
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(!prime_busy(dmabuf, true));
+
+ gem_close(fd, bo.handle);
+ vgem_create(fd, &bo);
+
+ fence = vgem_fence_attach(fd, &bo, true);
+ dmabuf = prime_handle_to_fd(fd, bo.handle);
+ igt_assert(prime_busy(dmabuf, false));
+ igt_assert(prime_busy(dmabuf, true));
+
+ vgem_fence_signal(fd, fence);
+ igt_assert(!prime_busy(dmabuf, false));
+ igt_assert(!prime_busy(dmabuf, true));
+
+ gem_close(fd, bo.handle);
+}
+
static void test_sysfs_read(int fd)
{
int dir = igt_sysfs_open(fd, NULL);
@@ -239,11 +316,22 @@ igt_main
igt_require(has_prime_export(fd));
}
- igt_subtest_f("dmabuf-export")
+ igt_subtest("dmabuf-export")
test_dmabuf_export(fd);
- igt_subtest_f("dmabuf-mmap")
+ igt_subtest("dmabuf-mmap")
test_dmabuf_mmap(fd);
+
+ igt_subtest_group {
+ igt_fixture {
+ igt_require(vgem_has_fences(fd));
+ }
+
+ igt_subtest("dmabuf-fence")
+ test_dmabuf_fence(fd);
+ igt_subtest("dmabuf-fence-before")
+ test_dmabuf_fence_before(fd);
+ }
}
igt_subtest("sysfs")