From patchwork Mon Jan 7 19:58:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 1942441 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 4E5473FE37 for ; Mon, 7 Jan 2013 19:59:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3DD31E632C for ; Mon, 7 Jan 2013 11:59:26 -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 9B4C8E5EA4 for ; Mon, 7 Jan 2013 11:58:44 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 07 Jan 2013 11:58:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,425,1355126400"; d="scan'208";a="273939127" Received: from unknown (HELO localhost) ([10.252.123.53]) by fmsmga002.fm.intel.com with ESMTP; 07 Jan 2013 11:58:42 -0800 From: Imre Deak To: intel-gfx@lists.freedesktop.org Date: Mon, 7 Jan 2013 21:58:39 +0200 Message-Id: <1357588719-7053-1-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357318051-6622-1-git-send-email-imre.deak@intel.com> References: <1357318051-6622-1-git-send-email-imre.deak@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] =?utf-8?q?=5Bi-g-t_PATCH_v2=5D_tests=3A_add_test_for_?= =?utf-8?q?unaligned_tiled_buffers?= X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org In v2: - set the unaligned buffer size properly for Gen5 HW, before it was exactly the size of a tile row and thus not catching the bug - allocate only a tile row sized buffer to detect off-bound writes Signed-off-by: Imre Deak --- tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/unaligned_tiled_buf.c | 113 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tests/unaligned_tiled_buf.c diff --git a/tests/.gitignore b/tests/.gitignore index 7e2d901..bd5ab0c 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -85,6 +85,7 @@ prime_nv_test prime_self_import prime_udl testdisplay +unaligned_tiled_buf sysfs_rc6_residency sysfs_rps # Please keep sorted alphabetically diff --git a/tests/Makefile.am b/tests/Makefile.am index d63862a..c28d79a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,6 +14,7 @@ NOUVEAU_TESTS = \ endif TESTS_progs_M = \ + unaligned_tiled_buf \ gem_basic \ gem_cacheing \ gem_cpu_concurrent_blit \ diff --git a/tests/unaligned_tiled_buf.c b/tests/unaligned_tiled_buf.c new file mode 100644 index 0000000..4b2d666 --- /dev/null +++ b/tests/unaligned_tiled_buf.c @@ -0,0 +1,113 @@ +/* + * Copyright © 2012 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "i915_drm.h" +#include "drmtest.h" +#include "intel_gpu_tools.h" + +static void write_buf(int drm_fd, uint32_t handle, unsigned long offset, + void *buf, size_t size) +{ + uint8_t *p; + + p = gem_mmap__gtt(drm_fd, handle, offset + size, PROT_WRITE); + assert(p); + memcpy(p + offset, buf, size); + munmap(p, offset + size); +} + +static void read_buf(int drm_fd, uint32_t handle, unsigned long offset, + void *buf, size_t size) +{ + uint8_t *p; + + p = gem_mmap__gtt(drm_fd, handle, offset + size, PROT_READ); + assert(p); + memcpy(buf, p + offset, size); + munmap(p, offset + size); +} + +int main(int argc, char **argv) +{ + uint32_t dev_id; + uint32_t handle[2]; + uint8_t *buf; + size_t tiled_size; + size_t untiled_size; + size_t stride; + int fd; + int gen; + int i; + + fd = drm_open_any(); + dev_id = intel_get_drm_devid(fd); + + stride = 3 * 512; + untiled_size = 3 * 4096; /* tile row size */ + gen = intel_gen(dev_id); + if (gen >= 4) + tiled_size = 4 * 4096; + else if (gen == 3) + tiled_size = 1024 * 1024; + else + tiled_size = 512 * 1024; + + buf = malloc(tiled_size); + assert(buf); + + handle[0] = gem_create(fd, tiled_size); + handle[1] = gem_create(fd, untiled_size); + assert(handle[0] && handle[1]); + gem_set_domain(fd, handle[0], I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); + gem_set_domain(fd, handle[1], I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); + + gem_set_tiling(fd, handle[0], I915_TILING_X, stride); + + memset(buf, 0x55, tiled_size); + /* Make sure the first buffer is bound just before the second one. */ + write_buf(fd, handle[0], 0, buf, tiled_size); + write_buf(fd, handle[1], 0, buf, untiled_size); + + memset(buf, 0xAA, tiled_size); + write_buf(fd, handle[0], 0, buf, tiled_size); + + memset(buf, 0, untiled_size); + read_buf(fd, handle[1], 0, buf, untiled_size); + for (i = 0; i < untiled_size; i++) { + if (buf[i] != 0x55) { + fprintf(stderr, "corrupted byte at offset %d (%#02x instead of x55)\n", + i, buf[i]); + exit(EXIT_FAILURE); + } + } + + return 0; +}