From patchwork Thu Jan 29 13:32:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 5742321 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 04A539F399 for ; Thu, 29 Jan 2015 13:33:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B3BD2010C for ; Thu, 29 Jan 2015 13:33:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0BA97201DD for ; Thu, 29 Jan 2015 13:33:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DEB972095; Thu, 29 Jan 2015 05:33:25 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 6707572095 for ; Thu, 29 Jan 2015 05:33:24 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 29 Jan 2015 05:33:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,486,1418112000"; d="scan'208";a="669694612" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.102]) by fmsmga002.fm.intel.com with ESMTP; 29 Jan 2015 05:33:22 -0800 Received: by rosetta (Postfix, from userid 1000) id 1975380052; Thu, 29 Jan 2015 15:32:54 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Thu, 29 Jan 2015 15:32:50 +0200 Message-Id: <1422538371-20043-1-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/2] tests: Add gem_ctx_params 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add gem_ctx_params to check context parameters ioctl test for set and getting ban periods. Cc: Chris Wilson Signed-off-by: Mika Kuoppala --- tests/Makefile.sources | 1 + tests/gem_ctx_params.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 tests/gem_ctx_params.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 74deec3..54bea34 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -25,6 +25,7 @@ TESTS_progs_M = \ gem_cs_tlb \ gem_ctx_bad_exec \ gem_ctx_exec \ + gem_ctx_params \ gem_dummy_reloc_loop \ gem_evict_alignment \ gem_evict_everything \ diff --git a/tests/gem_ctx_params.c b/tests/gem_ctx_params.c new file mode 100644 index 0000000..f831ecd --- /dev/null +++ b/tests/gem_ctx_params.c @@ -0,0 +1,211 @@ +/* + * Copyright © 2015 Intel Corporation + * + * 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. + * + * Authors: + * Mika Kuoppala + * + */ + +#include "drmtest.h" +#include "ioctl_wrappers.h" +#include "igt_aux.h" + +IGT_TEST_DESCRIPTION("Checks for context parameters"); + +struct local_drm_i915_gem_context_create { + __u32 ctx_id; + __u32 pad; +}; + +struct local_drm_i915_gem_context_destroy { + __u32 ctx_id; + __u32 pad; +}; + +#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create) +#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy) + +static uint32_t context_create(int fd) +{ + struct local_drm_i915_gem_context_create create; + int ret; + + create.ctx_id = rand(); + create.pad = rand(); + + ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create); + igt_assert(ret == 0); + + return create.ctx_id; +} + +static int context_destroy(int fd, uint32_t ctx_id) +{ + int ret; + struct local_drm_i915_gem_context_destroy destroy; + + destroy.ctx_id = ctx_id; + destroy.pad = rand(); + + ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy); + if (ret != 0) + return -errno; + + return 0; +} + +static int _get_ban_period(int fd, struct local_i915_gem_context_param *p) +{ + int r; + + r = gem_context_get_param(fd, p); + if (r == -1) + return errno; + + return 0; +} + +static int get_ban_period(int fd, int ctx) +{ + struct local_i915_gem_context_param p; + + p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + p.size = rand(); + p.context = rand(); + if (p.context == ctx) + p.context = ctx + 1; + p.value = ((uint64_t)rand() << 32) | rand(); + + igt_assert(gem_context_get_param(fd, &p) == -1); + igt_assert(errno == ENOENT); + + p.context = ctx; + p.param = 0xdeadf00d; + + igt_assert(gem_context_get_param(fd, &p) == -1); + igt_assert(errno == EINVAL); + + p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + igt_assert(gem_context_get_param(fd, &p) == 0); + igt_assert(errno == 0); + igt_assert(p.size == 0); + + return p.value; +} + +static int set_ban_period(int fd, struct local_i915_gem_context_param *p) +{ + int r; + + r = gem_context_set_param(fd, p); + if (r == -1) + return errno; + + return 0; +} + +static void test_ctx_params_invalid(bool new_ctx) +{ + struct local_i915_gem_context_param p; + int fd, period; + uint32_t ctx; + + fd = drm_open_any(); + + igt_require(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD)); + + if (new_ctx) + ctx = context_create(fd); + else + ctx = 0; + + period = get_ban_period(fd, ctx); + igt_assert(period > 2); + + p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + p.size = 0xdeadf00d; + p.context = ctx; + p.value = ((uint64_t)rand() << 32) | rand(); + + igt_assert(set_ban_period(fd, &p) == EINVAL); + + p.size = 0; + p.context = 0xdeadf00d; + + igt_assert(set_ban_period(fd, &p) == ENOENT); + + p.size = 0; + p.context = ctx; + p.value = period; + + igt_fork(child, 1) { + const int tmp = p.value; + + igt_drop_root(); + p.value = tmp - 2; + + igt_assert(set_ban_period(fd, &p) == EPERM); + igt_assert(_get_ban_period(fd, &p) >= 0); + p.value = tmp - 2; + igt_assert(set_ban_period(fd, &p) == EPERM); + p.value = tmp + 2; + igt_assert(set_ban_period(fd, &p) == 0); + p.value = tmp; + igt_assert(set_ban_period(fd, &p) == EPERM); + } + + igt_waitchildren(); + + p.value = period; + igt_assert(set_ban_period(fd, &p) == 0); + + p.size = 0; + p.context = ctx; + p.value = period + 1; + + igt_assert(set_ban_period(fd, &p) == 0); + + p.size = 0; + p.context = ctx; + p.value = period - 2; + igt_assert(set_ban_period(fd, &p) == 0); + + if (ctx != 0) { + context_destroy(fd, ctx); + igt_assert(_get_ban_period(fd, &p) == ENOENT); + igt_assert(set_ban_period(fd, &p) == ENOENT); + } + + close(fd); + + igt_assert(set_ban_period(fd, &p) == EBADF); + igt_assert(_get_ban_period(fd, &p) == EBADF); +} + +igt_main +{ + igt_subtest("params-default-invalid") + test_ctx_params_invalid(false); + + igt_subtest("params-ctx-invalid") + test_ctx_params_invalid(true); +}