From patchwork Tue Aug 8 23:09:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dave Airlie X-Patchwork-Id: 9889279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C4FF6031B for ; Tue, 8 Aug 2017 23:10:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8F12889F for ; Tue, 8 Aug 2017 23:10:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 334F228944; Tue, 8 Aug 2017 23:10:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 385472889F for ; Tue, 8 Aug 2017 23:09:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 550946E023; Tue, 8 Aug 2017 23:09:57 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id A65AD6E023 for ; Tue, 8 Aug 2017 23:09:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B63788553E for ; Tue, 8 Aug 2017 23:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B63788553E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=airlied@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B63788553E Received: from dreadlord-bne-redhat-com.bne.redhat.com (dhcp-40-179.bne.redhat.com [10.64.40.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B1AC77BF6 for ; Tue, 8 Aug 2017 23:09:54 +0000 (UTC) From: Dave Airlie To: intel-gfx@lists.freedesktop.org Date: Wed, 9 Aug 2017 09:09:53 +1000 Message-Id: <20170808230953.815-1-airlied@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 08 Aug 2017 23:09:56 +0000 (UTC) Subject: [Intel-gfx] [PATCH i-g-t] igt: add syncobj_basic. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Airlie Some basic sync object interface tests Signed-off-by: Dave Airlie Reviewed-by: Jason Ekstrand --- tests/Makefile.sources | 1 + tests/syncobj_basic.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+) create mode 100644 tests/syncobj_basic.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 5b98a5a..bb013c7 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -229,6 +229,7 @@ TESTS_progs = \ prime_udl \ prime_vgem \ sw_sync \ + syncobj_basic \ template \ tools_test \ vgem_basic \ diff --git a/tests/syncobj_basic.c b/tests/syncobj_basic.c new file mode 100644 index 0000000..a7a6742 --- /dev/null +++ b/tests/syncobj_basic.c @@ -0,0 +1,260 @@ +/* + * 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 +#include +#include "drm.h" + +IGT_TEST_DESCRIPTION("Basic check for drm sync objects."); + +/* 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); +} + +/* 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); +} + +static void +test_bad_flags_fd_to_handle(int fd) +{ + struct drm_syncobj_handle handle = { 0 }; + int ret; + + handle.flags = 0xdeadbeef; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &handle); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_flags_handle_to_fd(int fd) +{ + struct drm_syncobj_handle handle = { 0 }; + int ret; + + handle.flags = 0xdeadbeef; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_pad_handle_to_fd(int fd) +{ + struct drm_syncobj_handle handle = { 0 }; + int ret; + + handle.pad = 0xdeadbeef; + ret = ioctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &handle); + igt_assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_pad_fd_to_handle(int fd) +{ + struct drm_syncobj_handle handle = { 0 }; + int ret; + + handle.pad = 0xdeadbeef; + 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 create = { 0 }; + struct drm_syncobj_destroy destroy; + int ret; + + 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); +} + +static void +test_bad_create_flags(int fd) +{ + struct drm_syncobj_create create = { 0 }; + int ret; + + 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 create = { 0 }; + struct drm_syncobj_handle handle = { 0 }; + struct drm_syncobj_destroy destroy = { 0 }; + uint32_t first_handle; + + 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 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-flags") + test_bad_create_flags(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("bad-flags-handle-to-fd") + test_bad_flags_handle_to_fd(fd); + + igt_subtest("bad-flags-fd-to-handle") + test_bad_flags_fd_to_handle(fd); + + igt_subtest("bad-pad-handle-to-fd") + test_bad_pad_handle_to_fd(fd); + + igt_subtest("bad-pad-fd-to-handle") + test_bad_pad_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("test-valid-cycle") + test_valid_cycle(fd); + +}