From ab3f4bdafe60dede32a48674ef9920df090bf3a7 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Fri, 2 Dec 2011 18:41:34 +0100 Subject: tests: add gem_exec_bad_domains To check whether the kernel properly rejects non-gpu domains in relocs. Signed-Off-by: Daniel Vetter --- .gitignore | 1 + tests/Makefile.am | 2 +- tests/gem_exec_bad_domains.c | 145 +++++++++++++++++++++++++++++++++++++++++++ tests/gem_storedw_loop_blt.c | 4 +- 4 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 tests/gem_exec_bad_domains.c diff --git a/.gitignore b/.gitignore index e055540f..aceb543e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ tests/gem_double_irq_loop tests/gem_dummy_reloc_loop tests/gem_exec_blt tests/gem_exec_nop +tests/gem_exec_bad_domains tests/gem_fence_thrash tests/gem_fenced_exec_thrash tests/gem_flink diff --git a/tests/Makefile.am b/tests/Makefile.am index 750e3a46..ec87cc72 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,6 +20,7 @@ TESTS_progs = \ gem_basic \ gem_exec_nop \ gem_exec_blt \ + gem_exec_bad_domains \ gem_flink \ gem_readwrite \ gem_ringfill \ @@ -51,7 +52,6 @@ TESTS_progs = \ gem_double_irq_loop \ gem_ring_sync_loop \ gem_pipe_control_store_loop \ - gem_hangcheck_forcewake \ gem_unref_active_buffers \ $(NULL) diff --git a/tests/gem_exec_bad_domains.c b/tests/gem_exec_bad_domains.c new file mode 100644 index 00000000..da104b12 --- /dev/null +++ b/tests/gem_exec_bad_domains.c @@ -0,0 +1,145 @@ +/* + * 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: + * Daniel Vetter + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "i915_drm.h" +#include "drmtest.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_gpu_tools.h" + +/* Testcase: Test whether the kernel rejects relocations with non-gpu domains + * + * If it does not, it'll oops somewhen later on because we don't expect that. + */ + +static drm_intel_bufmgr *bufmgr; +struct intel_batchbuffer *batch; + +#define BAD_GTT_DEST ((512*1024*1024)) /* past end of aperture */ + +static int +run_batch(struct intel_batchbuffer *batch) +{ + unsigned int used = batch->ptr - batch->buffer; + int ret; + + if (used == 0) + return 0; + + /* Round batchbuffer usage to 2 DWORDs. */ + if ((used & 4) == 0) { + *(uint32_t *) (batch->ptr) = 0; /* noop */ + batch->ptr += 4; + } + + /* Mark the end of the buffer. */ + *(uint32_t *)(batch->ptr) = MI_BATCH_BUFFER_END; /* noop */ + batch->ptr += 4; + used = batch->ptr - batch->buffer; + + ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer); + assert(ret == 0); + + batch->ptr = NULL; + + ret = drm_intel_bo_mrb_exec(batch->bo, used, NULL, 0, 0, 0); + + intel_batchbuffer_reset(batch); + + return ret; +} + +int main(int argc, char **argv) +{ + int fd, ret; + drm_intel_bo *tmp; + + fd = drm_open_any(); + + bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); + drm_intel_bufmgr_gem_enable_reuse(bufmgr); + batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); + + tmp = drm_intel_bo_alloc(bufmgr, "tmp", 128 * 128, 4096); + + BEGIN_BATCH(2); + OUT_BATCH(0); + OUT_RELOC(tmp, I915_GEM_DOMAIN_CPU, 0, 0); + ADVANCE_BATCH(); + ret = run_batch(batch); + if (ret != -EINVAL) { + fprintf(stderr, "(cpu, 0) reloc not rejected\n"); + exit(1); + } + + BEGIN_BATCH(2); + OUT_BATCH(0); + OUT_RELOC(tmp, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU, 0); + ADVANCE_BATCH(); + ret = run_batch(batch); + if (ret != -EINVAL) { + fprintf(stderr, "(cpu, cpu) reloc not rejected\n"); + exit(1); + } + + BEGIN_BATCH(2); + OUT_BATCH(0); + OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT, 0, 0); + ADVANCE_BATCH(); + ret = run_batch(batch); + if (ret != -EINVAL) { + fprintf(stderr, "(gtt, 0) reloc not rejected\n"); + exit(1); + } + + BEGIN_BATCH(2); + OUT_BATCH(0); + OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT, 0); + ADVANCE_BATCH(); + ret = run_batch(batch); + if (ret != -EINVAL) { + fprintf(stderr, "(gtt, gtt) reloc not rejected\n"); + exit(1); + } + + intel_batchbuffer_free(batch); + drm_intel_bufmgr_destroy(bufmgr); + + close(fd); + + return 0; +} diff --git a/tests/gem_storedw_loop_blt.c b/tests/gem_storedw_loop_blt.c index c67c2b3b..54730537 100644 --- a/tests/gem_storedw_loop_blt.c +++ b/tests/gem_storedw_loop_blt.c @@ -56,7 +56,7 @@ store_dword_loop(void) int cmd, i, val = 0; uint32_t *buf; - cmd = MI_STORE_DWORD_IMM | MI_MEM_VIRTUAL; + cmd = MI_STORE_DWORD_IMM; // | MI_MEM_VIRTUAL; for (i = 0; i < 0x100000; i++) { BEGIN_BATCH(4); @@ -113,7 +113,7 @@ int main(int argc, char **argv) } /* This supposedly only works with ppgtt */ - return 77; + //return 77; bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); if (!bufmgr) { -- cgit v1.2.3