From patchwork Wed May 13 11:53:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: ankitprasad.r.sharma@intel.com X-Patchwork-Id: 6396501 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 0BFA69F1C2 for ; Wed, 13 May 2015 12:07:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CE912041B for ; Wed, 13 May 2015 12:07:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7FB6E203EB for ; Wed, 13 May 2015 12:07:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 164C76E2C7; Wed, 13 May 2015 05:07:38 -0700 (PDT) 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 96E926E2C7 for ; Wed, 13 May 2015 05:07:36 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 13 May 2015 05:07:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,420,1427785200"; d="scan'208";a="570691597" Received: from ankitprasad-desktop.iind.intel.com ([10.223.82.39]) by orsmga003.jf.intel.com with ESMTP; 13 May 2015 05:07:35 -0700 From: ankitprasad.r.sharma@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 13 May 2015 17:23:44 +0530 Message-Id: <1431518024-16296-4-git-send-email-ankitprasad.r.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431518024-16296-1-git-send-email-ankitprasad.r.sharma@intel.com> References: <1431518024-16296-1-git-send-email-ankitprasad.r.sharma@intel.com> MIME-Version: 1.0 Cc: Ankitprasad Sharma , akash.goel@intel.com, shashidhar.hiremath@intel.com Subject: [Intel-gfx] [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl 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 From: Ankitprasad Sharma This test validates the two parameters (size and flags) GEM_CREATE ioctl. Signed-off-by: Ankitprasad Sharma --- tests/Makefile.sources | 1 + tests/gem_create.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 tests/gem_create.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 3f1413f..681973d 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -23,6 +23,7 @@ TESTS_progs_M = \ gem_caching \ gem_close_race \ gem_concurrent_blit \ + gem_create \ gem_stolen \ gem_cs_tlb \ gem_ctx_param_basic \ diff --git a/tests/gem_create.c b/tests/gem_create.c new file mode 100644 index 0000000..74597f1 --- /dev/null +++ b/tests/gem_create.c @@ -0,0 +1,177 @@ +/* + * Copyright © 2011 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: + * Ankitprasad Sharma + * + */ + +/** @file gem_create.c + * + * This is a test for the extended and old gem_create ioctl, that + * includes allocation of object from stolen memory and shmem + * + * The goal is to simply ensure that basics work and invalid input + * combinations are rejected. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "ioctl_wrappers.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_io.h" +#include "intel_chipset.h" +#include "igt_aux.h" +#include "drmtest.h" +#include "drm.h" +#include "i915_drm.h" + +#define CLEAR(s) memset(&s, 0, sizeof(s)) +#define SIZE 2048 +#define OFFSET 3072 + +static struct drm_intel_bufmgr *bufmgr; +static struct intel_batchbuffer *batch; + +static void invalid_flag_test(int fd) +{ + int ret = 0; + +struct local_i915_gem_create_v2 { + uint64_t size; + uint32_t handle; + uint32_t pad; +#define I915_CREATE_PLACEMENT_STOLEN (1<<0) + uint32_t flags; +} create; + +#define LOCAL_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2) + gem_require_stolen_support(fd); + + create.handle = 0; + create.size = SIZE; + create.flags = ~I915_CREATE_PLACEMENT_STOLEN; + ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create); + + igt_assert(ret <= 0); +} + +static void invalid_size_test(int fd) +{ + int handle; + + handle = __gem_create(fd, 0); + igt_assert(handle == 0); +} + +/* Creating an object with non-aligned size and trying to access offset of + * value (size+x) & length y, where (size+x+y) <= object's last page boundary. + * pwrite here must be successful. + */ +static void valid_nonaligned_size(int fd) +{ + int handle, i; + uint32_t buf[1024]; + + for (i = 0; i < 1024; i ++) + buf[i] = 0xdead; + + handle = gem_create(fd, SIZE); + igt_assert(handle != 0); + + gem_write(fd, handle, OFFSET, buf, 256); + + gem_close(fd, handle); +} + +/* Creating an object with non-aligned size and trying to access offset of + * value (size+x) & length y, where (size+x+y) > object's last page boundary. + * pwrite here must result in failure. + */ +static void invalid_nonaligned_size(int fd) +{ + int handle, i; + uint32_t buf[1024]; + struct drm_i915_gem_pwrite gem_pwrite; + + for (i = 0; i < 1024; i ++) + buf[i] = 0xdead; + + handle = gem_create(fd, SIZE); + + CLEAR(gem_pwrite); + gem_pwrite.handle = handle; + gem_pwrite.offset = OFFSET; + /* Out of bound access */ + gem_pwrite.size = 2048; + gem_pwrite.data_ptr = (uintptr_t)buf; + igt_assert(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) != 0); + + gem_close(fd, handle); +} + +igt_main +{ + int i, fd, gtt_size_total, gtt_size_mappable; + uint32_t devid; + + igt_skip_on_simulation(); + + igt_fixture { + fd = drm_open_any(); + devid = intel_get_drm_devid(fd); + + drm_intel_get_aperture_sizes(fd, (size_t*)>t_size_total, + (size_t*)>t_size_mappable); + bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); + batch = intel_batchbuffer_alloc(bufmgr, devid); + } + + igt_subtest("stolen-invalid-flag") + invalid_flag_test(fd); + + igt_subtest("stolen-invalid-size") + invalid_size_test(fd); + + igt_subtest("stolen-valid-nonaligned") + valid_nonaligned_size(fd); + + igt_subtest("stolen-invalid-nonaligned") + invalid_nonaligned_size(fd); + + igt_fixture { + intel_batchbuffer_free(batch); + drm_intel_bufmgr_destroy(bufmgr); + } +}