[Intel-gfx] [PATCH igt] igt: Add gem_exec_capture to exercise capturing user requested buffers on hang
Chris Wilson
chris at chris-wilson.co.uk
Sat Dec 3 15:47:06 UTC 2016
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
tests/Makefile.sources | 1 +
tests/gem_exec_capture.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 170 insertions(+)
create mode 100644 tests/gem_exec_capture.c
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 04dd2d5..ee6a02f 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -36,6 +36,7 @@ TESTS_progs_M = \
gem_exec_async \
gem_exec_bad_domains \
gem_exec_basic \
+ gem_exec_capture \
gem_exec_create \
gem_exec_faulting_reloc \
gem_exec_fence \
diff --git a/tests/gem_exec_capture.c b/tests/gem_exec_capture.c
new file mode 100644
index 0000000..55d230e
--- /dev/null
+++ b/tests/gem_exec_capture.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright © 2016 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 "igt.h"
+#include "igt_sysfs.h"
+
+#define LOCAL_OBJECT_CAPTURE (1 << 7)
+#define LOCAL_PARAM_HAS_EXEC_CAPTURE 44
+
+IGT_TEST_DESCRIPTION("Check that we capture the user specified objects on a hang");
+
+static void check_error_state(int fd, struct drm_i915_gem_exec_object2 *obj)
+{
+ char *error, *str;
+ int dir;
+
+ dir = igt_sysfs_open(fd, NULL);
+ error = igt_sysfs_get(dir, "error");
+ igt_assert(error);
+
+ /* render ring --- user = 0x00000000 ffffd000 */
+ igt_debug("%s\n", error);
+ for (str = error; (str = strstr(str, "--- user = ")); str++) {
+ uint64_t addr;
+ uint32_t hi, lo;
+
+ igt_assert(sscanf(str, "--- user = 0x%x %x", &hi, &lo) == 2);
+ addr = hi;
+ addr <<= 32;
+ addr |= lo;
+ igt_assert_eq_u64(addr, obj->offset);
+ }
+
+ igt_sysfs_set(dir, "error", "Begone!");
+ close(dir);
+}
+
+static void capture(int fd, unsigned ring)
+{
+ const int gen = intel_gen(intel_get_drm_devid(fd));
+ struct drm_i915_gem_exec_object2 obj[3];
+#define SCRATCH 0
+#define CAPTURE 1
+#define BATCH 2
+ struct drm_i915_gem_relocation_entry reloc;
+ struct drm_i915_gem_execbuffer2 execbuf;
+ uint32_t *batch;
+ int i;
+
+ memset(obj, 0, sizeof(obj));
+ obj[SCRATCH].handle = gem_create(fd, 4096);
+ obj[CAPTURE].handle = gem_create(fd, 4096);
+ obj[CAPTURE].flags = LOCAL_OBJECT_CAPTURE;
+
+ obj[BATCH].handle = gem_create(fd, 4096);
+ obj[BATCH].relocs_ptr = (uintptr_t)&reloc;
+ obj[BATCH].relocation_count = 1;
+
+ memset(&reloc, 0, sizeof(reloc));
+ reloc.target_handle = obj[BATCH].handle; /* recurse */
+ reloc.presumed_offset = 0;
+ reloc.offset = sizeof(uint32_t);
+ reloc.delta = 0;
+ reloc.read_domains = I915_GEM_DOMAIN_COMMAND;
+ reloc.write_domain = 0;
+
+ batch = gem_mmap__cpu(fd, obj[BATCH].handle, 0, 4096, PROT_WRITE);
+ gem_set_domain(fd, obj[BATCH].handle,
+ I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+
+ i = 0;
+ batch[i++] = 0xdeadbeef; /* crashme */
+ batch[i++] = -1;
+ batch[i] = MI_BATCH_BUFFER_START; /* not crashed? try again! */
+ if (gen >= 8) {
+ batch[i] |= 1 << 8 | 1;
+ batch[++i] = 0;
+ batch[++i] = 0;
+ } else if (gen >= 6) {
+ batch[i] |= 1 << 8;
+ batch[++i] = 0;
+ } else {
+ batch[i] |= 2 << 6;
+ batch[++i] = 0;
+ if (gen < 4) {
+ batch[i] |= 1;
+ reloc.delta = 1;
+ }
+ }
+ munmap(batch, 4096);
+
+ memset(&execbuf, 0, sizeof(execbuf));
+ execbuf.buffers_ptr = (uintptr_t)obj;
+ execbuf.buffer_count = 3;
+ execbuf.flags = ring;
+ gem_execbuf(fd, &execbuf);
+
+ /* Check that only the buffer we marked is reported in the error */
+ gem_sync(fd, obj[BATCH].handle);
+ check_error_state(fd, &obj[CAPTURE]);
+
+ gem_close(fd, obj[BATCH].handle);
+ gem_close(fd, obj[CAPTURE].handle);
+ gem_close(fd, obj[SCRATCH].handle);
+}
+
+static bool has_capture(int fd)
+{
+ drm_i915_getparam_t gp;
+ int async = -1;
+
+ gp.param = LOCAL_PARAM_HAS_EXEC_CAPTURE;
+ gp.value = &async;
+ drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+ return async > 0;
+}
+
+igt_main
+{
+ const struct intel_execution_engine *e;
+ igt_hang_t hang;
+ int fd = -1;
+
+ igt_skip_on_simulation();
+
+ igt_fixture {
+ fd = drm_open_driver_master(DRIVER_INTEL);
+ gem_require_mmap_wc(fd);
+ igt_require(has_capture(fd));
+ igt_allow_hang(fd, 0, HANG_ALLOW_CAPTURE);
+ }
+
+ for (e = intel_execution_engines; e->name; e++) {
+ /* default exec-id is purely symbolic */
+ if (e->exec_id == 0)
+ continue;
+
+ igt_subtest_f("capture-%s", e->name) {
+ gem_require_ring(fd, e->exec_id | e->flags);
+ capture(fd, e->exec_id | e->flags);
+ }
+ }
+
+ igt_fixture {
+ igt_disallow_hang(fd, hang);
+ close(fd);
+ }
+}
--
2.10.2
More information about the Intel-gfx
mailing list