From 90ecf062d10a3ed1bb08cb887aea78b385072584 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 28 Oct 2013 09:10:46 +0000 Subject: [PATCH] tests: Add gem_close_race The intention is to exercise #70784. Yet the first challenge is make the test suite happy. --- tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/gem_close_race.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 tests/gem_close_race.c diff --git a/tests/.gitignore b/tests/.gitignore index eded4a7..4a04c0d 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -12,6 +12,7 @@ gem_bad_blit gem_bad_length gem_basic gem_caching +gem_close_race gem_concurrent_blit gem_cpu_reloc gem_cs_prefetch diff --git a/tests/Makefile.am b/tests/Makefile.am index 99d7b7a..e9e37a6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -68,6 +68,7 @@ TESTS_progs = \ drm_vma_limiter_cpu \ drm_vma_limiter_gtt \ gem_bad_length \ + gem_close_race \ gem_cpu_reloc \ gem_cs_prefetch \ gem_ctx_bad_destroy \ diff --git a/tests/gem_close_race.c b/tests/gem_close_race.c new file mode 100644 index 0000000..cceae36 --- /dev/null +++ b/tests/gem_close_race.c @@ -0,0 +1,148 @@ +/* + * Copyright © 2013 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: + * Chris Wilson + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "i915_drm.h" +#include "drmtest.h" + +#define OBJECT_SIZE 1024*1024*4 + +#define COPY_BLT_CMD (2<<29|0x53<<22|0x6) +#define BLT_WRITE_ALPHA (1<<21) +#define BLT_WRITE_RGB (1<<20) + +static void selfcopy(int fd, uint32_t handle) +{ + struct drm_i915_gem_relocation_entry reloc[2]; + struct drm_i915_gem_exec_object2 gem_exec[2]; + struct drm_i915_gem_execbuffer2 execbuf; + uint32_t buf[10]; + uint32_t batch; + + memset(reloc, 0, sizeof(reloc)); + memset(gem_exec, 0, sizeof(gem_exec)); + memset(&execbuf, 0, sizeof(execbuf)); + + buf[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB; + buf[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024); + buf[2] = 0; + buf[3] = 1024 << 16 | 1024; + buf[4] = 0; + reloc[0].offset = 4 * sizeof(uint32_t); + reloc[0].delta = 0; + reloc[0].target_handle = handle; + reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; + reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; + reloc[0].presumed_offset = 0; + + buf[5] = 0; + buf[6] = 4*1024; + buf[7] = 0; + reloc[1].offset = 7 * sizeof(uint32_t); + reloc[1].delta = 0; + reloc[1].target_handle = handle; + reloc[1].read_domains = I915_GEM_DOMAIN_RENDER; + reloc[1].write_domain = 0; + reloc[1].presumed_offset = 0; + + buf[8] = MI_BATCH_BUFFER_END; + buf[9] = 0; + + gem_exec[0].handle = handle; + + batch = gem_create(fd, 4096); + + gem_write(fd, batch, 0, buf, sizeof(buf)); + gem_exec[1].handle = batch; + gem_exec[1].relocation_count = 2; + gem_exec[1].relocs_ptr = (uintptr_t)reloc; + + execbuf.buffers_ptr = (uintptr_t)&gem_exec; + execbuf.buffer_count = 2; + execbuf.batch_len = sizeof(buf); + if (HAS_BLT_RING(intel_get_drm_devid(fd))) + execbuf.flags |= I915_EXEC_BLT; + + gem_execbuf(fd, &execbuf); +} + +static int open_drm(void) +{ + char name[80]; + + sprintf(name, "/dev/dri/card%d", drm_get_card()); + return open(name, O_RDWR); +} + +static uint32_t load(int fd) +{ + uint32_t handle; + + handle = gem_create(fd, OBJECT_SIZE); + if (handle == 0) + return 0; + + selfcopy(fd, handle); + return handle; +} + +static void run(int child) +{ + int fd; + uint32_t handle; + + fd = open_drm(); + igt_assert(fd != -1); + + handle = load(fd); + if (child & 1) + gem_read(fd, handle, 0, &handle, sizeof(handle)); +} + +int main(int argc, char *argv[]) +{ + igt_skip_on_simulation(); + igt_subtest_init(argc, argv); + + igt_subtest("gem-close-race") + igt_fork(child, 100) + run(child); + + igt_waitchildren(); + igt_exit(); +} -- 2.7.4