<div dir="ltr"><div>A bunch of these tests assume that the handle is looked up after the other parameters are checked. Other than that, looks good.<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 4:09 PM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
Some basic sync object interface tests<br>
<br>
Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
---<br>
tests/Makefile.sources | 1 +<br>
tests/syncobj_basic.c | 260 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++++<br>
2 files changed, 261 insertions(+)<br>
create mode 100644 tests/syncobj_basic.c<br>
<br>
diff --git a/tests/Makefile.sources b/tests/Makefile.sources<br>
index 5b98a5a..bb013c7 100644<br>
--- a/tests/Makefile.sources<br>
+++ b/tests/Makefile.sources<br>
@@ -229,6 +229,7 @@ TESTS_progs = \<br>
prime_udl \<br>
prime_vgem \<br>
sw_sync \<br>
+ syncobj_basic \<br>
template \<br>
tools_test \<br>
vgem_basic \<br>
diff --git a/tests/syncobj_basic.c b/tests/syncobj_basic.c<br>
new file mode 100644<br>
index 0000000..a7a6742<br>
--- /dev/null<br>
+++ b/tests/syncobj_basic.c<br>
@@ -0,0 +1,260 @@<br>
+/*<br>
+ * Copyright © 2017 Red Hat<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "igt.h"<br>
+#include <unistd.h><br>
+#include <sys/ioctl.h><br>
+#include "drm.h"<br>
+<br>
+IGT_TEST_DESCRIPTION("Basic check for drm sync objects.");<br>
+<br>
+/* destroy a random handle */<br>
+static void<br>
+test_bad_destroy(int fd)<br>
+{<br>
+ struct drm_syncobj_destroy destroy;<br>
+ int ret;<br>
+<br>
+ destroy.handle = 0xdeadbeef;<br>
+ destroy.pad = 0;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy);<br>
+<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+/* handle to fd a bad handle */<br>
+static void<br>
+test_bad_handle_to_fd(int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle;<br>
+ int ret;<br>
+<br>
+ handle.handle = 0xdeadbeef;<br>
+ handle.flags = 0;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_<wbr>FD, &handle);<br>
+<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+/* fd to handle a bad fd */<br>
+static void<br>
+test_bad_fd_to_handle(int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle;<br>
+ int ret;<br>
+<br>
+ handle.fd = -1;<br>
+ handle.flags = 0;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_<wbr>HANDLE, &handle);<br>
+<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+/* fd to handle an fd but not a sync file one */<br>
+static void<br>
+test_illegal_fd_to_handle(int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle;<br>
+ int ret;<br>
+<br>
+ handle.fd = fd;<br>
+ handle.flags = 0;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_<wbr>HANDLE, &handle);<br>
+<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+static void<br>
+test_bad_flags_fd_to_handle(<wbr>int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle = { 0 };<br>
+ int ret;<br>
+<br>
+ handle.flags = 0xdeadbeef;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_<wbr>HANDLE, &handle);<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+static void<br>
+test_bad_flags_handle_to_fd(<wbr>int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle = { 0 };<br>
+ int ret;<br>
+<br>
+ handle.flags = 0xdeadbeef;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_<wbr>FD, &handle);<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+static void<br>
+test_bad_pad_handle_to_fd(int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle = { 0 };<br>
+ int ret;<br>
+<br>
+ handle.pad = 0xdeadbeef;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_<wbr>FD, &handle);<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+static void<br>
+test_bad_pad_fd_to_handle(int fd)<br>
+{<br>
+ struct drm_syncobj_handle handle = { 0 };<br>
+ int ret;<br>
+<br>
+ handle.pad = 0xdeadbeef;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_<wbr>HANDLE, &handle);<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+<br>
+<br>
+/* destroy with data in the padding */<br>
+static void<br>
+test_bad_destroy_pad(int fd)<br>
+{<br>
+ struct drm_syncobj_create create = { 0 };<br>
+ struct drm_syncobj_destroy destroy;<br>
+ int ret;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create);<br>
+<br>
+ destroy.handle = create.handle;<br>
+ destroy.pad = 0xdeadbeef;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy);<br>
+<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+<br>
+ destroy.handle = create.handle;<br>
+ destroy.pad = 0;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy);<br>
+ igt_assert(ret == 0);<br>
+}<br>
+<br>
+static void<br>
+test_bad_create_flags(int fd)<br>
+{<br>
+ struct drm_syncobj_create create = { 0 };<br>
+ int ret;<br>
+<br>
+ create.flags = 0xdeadbeef;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create);<br>
+ igt_assert(ret == -1 && errno == EINVAL);<br>
+}<br>
+<br>
+/*<br>
+ * currently don't do handle deduplication<br>
+ * test we get a different handle back.<br>
+ */<br>
+static void<br>
+test_valid_cycle(int fd)<br>
+{<br>
+ int ret;<br>
+ struct drm_syncobj_create create = { 0 };<br>
+ struct drm_syncobj_handle handle = { 0 };<br>
+ struct drm_syncobj_destroy destroy = { 0 };<br>
+ uint32_t first_handle;<br>
+<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create);<br>
+ igt_assert(ret == 0);<br>
+<br>
+ first_handle = create.handle;<br>
+<br>
+ handle.handle = create.handle;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_<wbr>FD, &handle);<br>
+ igt_assert(ret == 0);<br>
+ handle.handle = 0;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_<wbr>HANDLE, &handle);<br>
+ close(handle.fd);<br>
+ igt_assert(ret == 0);<br>
+<br>
+ igt_assert(handle.handle != first_handle);<br>
+<br>
+ destroy.handle = handle.handle;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy);<br>
+ igt_assert(ret == 0);<br>
+<br>
+ destroy.handle = first_handle;<br>
+ ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy);<br>
+ igt_assert(ret == 0);<br>
+}<br>
+<br>
+static bool has_syncobj(int fd)<br>
+{<br>
+ uint64_t value;<br>
+ if (drmGetCap(fd, DRM_CAP_SYNCOBJ, &value))<br>
+ return false;<br>
+ return value ? true : false;<br>
+}<br>
+<br>
+igt_main<br>
+{<br>
+ int fd;<br>
+<br>
+ igt_fixture {<br>
+ fd = drm_open_driver(DRIVER_ANY);<br>
+ igt_require(has_syncobj(fd));<br>
+ }<br>
+<br>
+<br>
+ igt_subtest("bad-destroy")<br>
+ test_bad_destroy(fd);<br>
+<br>
+ igt_subtest("bad-create-flags"<wbr>)<br>
+ test_bad_create_flags(fd);<br>
+<br>
+ igt_subtest("bad-handle-to-fd"<wbr>)<br>
+ test_bad_handle_to_fd(fd);<br>
+<br>
+ igt_subtest("bad-fd-to-handle"<wbr>)<br>
+ test_bad_fd_to_handle(fd);<br>
+<br>
+ igt_subtest("bad-flags-handle-<wbr>to-fd")<br>
+ test_bad_flags_handle_to_fd(<wbr>fd);<br>
+<br>
+ igt_subtest("bad-flags-fd-to-<wbr>handle")<br>
+ test_bad_flags_fd_to_handle(<wbr>fd);<br>
+<br>
+ igt_subtest("bad-pad-handle-<wbr>to-fd")<br>
+ test_bad_pad_handle_to_fd(fd);<br>
+<br>
+ igt_subtest("bad-pad-fd-to-<wbr>handle")<br>
+ test_bad_pad_fd_to_handle(fd);<br>
+<br>
+ igt_subtest("illegal-fd-to-<wbr>handle")<br>
+ test_illegal_fd_to_handle(fd);<br>
+<br>
+ igt_subtest("bad-destroy-pad")<br>
+ test_bad_destroy_pad(fd);<br>
+<br>
+ igt_subtest("test-valid-cycle"<wbr>)<br>
+ test_valid_cycle(fd);<br>
+<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.4<br>
<br>
______________________________<wbr>_________________<br>
Intel-gfx mailing list<br>
<a href="mailto:Intel-gfx@lists.freedesktop.org">Intel-gfx@lists.freedesktop.<wbr>org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/intel-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/intel-gfx</a><br>
</font></span></blockquote></div><br></div>