diff options
author | Dave Airlie <airlied@redhat.com> | 2017-04-12 02:12:54 +0100 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2017-04-12 04:41:11 +0100 |
commit | 8950d8c2179b13156ed30b6f6170f13c6e49a1d9 (patch) | |
tree | 05d43656a9aef630d517a3ede0f1e22c440c9d38 | |
parent | 82fdfc65d81e08df08089c3c9cee65f9505c71e2 (diff) |
igt: add syncobj_basic.syncobj
Some basic sync object interface tests
-rw-r--r-- | tests/Makefile.sources | 1 | ||||
-rw-r--r-- | tests/syncobj_basic.c | 369 |
2 files changed, 370 insertions, 0 deletions
diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 45c21a0c..8b4d515f 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -140,6 +140,7 @@ TESTS_progs_M = \ prime_self_import \ prime_vgem \ sw_sync \ + syncobj_basic \ template \ vgem_basic \ vgem_slow \ diff --git a/tests/syncobj_basic.c b/tests/syncobj_basic.c new file mode 100644 index 00000000..af8c6b8e --- /dev/null +++ b/tests/syncobj_basic.c @@ -0,0 +1,369 @@ +/* + * Copyright © 2017 Red Hat + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "igt.h" +#include <unistd.h> +#include <sys/ioctl.h> +#include <poll.h> +#include "drm.h" +#include <linux/sync_file.h> +IGT_TEST_DESCRIPTION("Basic check for drm sync objects."); + +#ifndef SYNC_FILE_TYPE_FENCE +#define SYNC_FILE_TYPE_FENCE 0 +#endif +#ifndef SYNC_FILE_TYPE_SEMAPHORE +#define SYNC_FILE_TYPE_SEMAPHORE 1 +#endif + +#ifndef DRM_CAP_SYNCOBJ +#define DRM_CAP_SYNCOBJ 0x12 +#endif + +/* destroy a random handle */ +static void +test_bad_destroy(int fd) +{ + struct drm_syncobj_destroy destroy; + int ret; + + destroy.handle = 0xdeadbeef; + destroy.pad = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy); + + igt_assert(ret == -1 && errno == EINVAL); +} + +/* info a random handle */ +static void +test_bad_info(int fd) +{ + struct drm_syncobj_create_info info; + int ret; + + info.handle = 0xdeadbeef; + info.pad = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_INFO, &info); + + igt_assert(ret == -1 && errno == EINVAL); +} + +/* handle to fd a bad handle */ +static void +test_bad_handle_to_fd(int fd) +{ + struct drm_syncobj_handle handle; + int ret; + + handle.handle = 0xdeadbeef; + handle.flags = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + + igt_assert(ret == -1 && errno == EINVAL); +} + +/* fd to handle a bad fd */ +static void +test_bad_fd_to_handle(int fd) +{ + struct drm_syncobj_handle handle; + int ret; + + handle.fd = -1; + handle.flags = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &handle); + + igt_assert(ret == -1 && errno == EINVAL); +} + +/* fd to handle an fd but not a sync file one */ +static void +test_illegal_fd_to_handle(int fd) +{ + struct drm_syncobj_handle handle; + int ret; + + handle.fd = fd; + handle.flags = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &handle); + + igt_assert(ret == -1 && errno == EINVAL); +} + +/* destroy with data in the padding */ +static void +test_bad_destroy_pad(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + struct drm_syncobj_destroy destroy; + int ret; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + + destroy.handle = create.handle; + destroy.pad = 0xdeadbeef; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy); + + igt_assert(ret == -1 && errno == EINVAL); + + destroy.handle = create.handle; + destroy.pad = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy); + igt_assert(ret == 0); +} + +/* create with data in the padding */ +static void +test_bad_create_pad(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + int ret; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + create.pad = 0xdeadbeef; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == -1 && errno == EINVAL); +} + +/* get info with data in the padding */ +static void +test_bad_info_pad(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + int ret; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + create.pad = 0; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == 0); + + create.type = 0; + create.pad = 0xdeadbeef; + + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_INFO, &create); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_create_type(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + int ret; + + create.type = 0xdeadbeef; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_create_type_fence(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + int ret; + + create.type = SYNC_FILE_TYPE_FENCE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_create_flags(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + int ret; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + create.flags = 0xdeadbeef; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == -1 && errno == EINVAL); +} + +/* + * currently don't do handle deduplication + * test we get a different handle back. + */ +static void +test_valid_cycle(int fd) +{ + int ret; + struct drm_syncobj_create_info create = { 0 }; + struct drm_syncobj_handle handle = { 0 }; + struct drm_syncobj_destroy destroy = { 0 }; + uint32_t first_handle; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == 0); + + first_handle = create.handle; + + handle.handle = create.handle; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == 0); + handle.handle = 0; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &handle); + close(handle.fd); + igt_assert(ret == 0); + + igt_assert(handle.handle != first_handle); + + destroy.handle = handle.handle; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy); + igt_assert(ret == 0); + + destroy.handle = first_handle; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy); + igt_assert(ret == 0); +} + +static void +test_poll_semaphore_fail(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + struct drm_syncobj_handle handle = { 0 }; + struct pollfd fds; + int ret; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == 0); + + handle.handle = create.handle; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == 0); + + fds.fd = handle.fd; + fds.events = POLLIN; + + ret = poll(&fds, 1, 500); + igt_assert(ret == 1 && fds.revents & POLLERR); +} + +static void +test_merge_ioctl_fail(int fd) +{ + struct drm_syncobj_create_info create = { 0 }; + struct drm_syncobj_handle handle = { 0 }; + int ret; + uint32_t handle_a, handle_b; + int fd_a, fd_b; + struct sync_merge_data merge = { 0 }; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == 0); + handle_a = create.handle; + + create.type = SYNC_FILE_TYPE_SEMAPHORE; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); + igt_assert(ret == 0); + handle_b = create.handle; + + handle.handle = handle_a; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == 0); + fd_a = handle.fd; + + handle.handle = handle_b; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == 0); + fd_b = handle.fd; + + strcpy(merge.name, "synctest"); + merge.fd2 = fd_b; + + ret = ioctl(fd_a, SYNC_IOC_MERGE, &merge); + igt_assert(ret == -1 && errno == EINVAL); +} + + +static bool has_syncobj(int fd) +{ + uint64_t value; + if (drmGetCap(fd, DRM_CAP_SYNCOBJ, &value)) + return false; + return value ? true : false; +} + +igt_main +{ + int fd; + + igt_fixture { + fd = drm_open_driver(DRIVER_ANY); + igt_require(has_syncobj(fd)); + } + + + igt_subtest("bad-destroy") + test_bad_destroy(fd); + + igt_subtest("bad-create-type") + test_bad_create_type(fd); + + igt_subtest("bad-create-type-fence") + test_bad_create_type_fence(fd); + + igt_subtest("bad-create-flags") + test_bad_create_flags(fd); + + igt_subtest("bad-info") + test_bad_info(fd); + + igt_subtest("bad-handle-to-fd") + test_bad_handle_to_fd(fd); + + igt_subtest("bad-fd-to-handle") + test_bad_fd_to_handle(fd); + + igt_subtest("illegal-fd-to-handle") + test_illegal_fd_to_handle(fd); + + igt_subtest("bad-destroy-pad") + test_bad_destroy_pad(fd); + + igt_subtest("bad-create-pad") + test_bad_create_pad(fd); + + igt_subtest("bad-info-pad") + test_bad_info_pad(fd); + + igt_subtest("test-valid-cycle") + test_valid_cycle(fd); + + igt_subtest("test-poll-semaphore-fail") + test_poll_semaphore_fail(fd); + + igt_subtest("test-merge-ioctl-fail") + test_merge_ioctl_fail(fd); +} |