[Intel-gfx] [PATCH] tests/gem_error_capture: Initial testcase for error state capture/dump

oscar.mateo at intel.com oscar.mateo at intel.com
Fri Apr 11 14:59:53 CEST 2014


From: Oscar Mateo <oscar.mateo at intel.com>

Signed-off-by: Oscar Mateo <oscar.mateo at intel.com>
---
 tests/.gitignore          |   1 +
 tests/Makefile.sources    |   1 +
 tests/gem_error_capture.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 232 insertions(+)
 create mode 100644 tests/gem_error_capture.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 146bab0..945574c 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -27,6 +27,7 @@ gem_ctx_create
 gem_ctx_exec
 gem_double_irq_loop
 gem_dummy_reloc_loop
+gem_error_capture
 gem_evict_alignment
 gem_evict_everything
 gem_exec_bad_domains
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index bf02a48..612beb6 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -24,6 +24,7 @@ TESTS_progs_M = \
 	gem_ctx_bad_exec \
 	gem_ctx_exec \
 	gem_dummy_reloc_loop \
+	gem_error_capture \
 	gem_evict_alignment \
 	gem_evict_everything \
 	gem_exec_bad_domains \
diff --git a/tests/gem_error_capture.c b/tests/gem_error_capture.c
new file mode 100644
index 0000000..bbf0f5d
--- /dev/null
+++ b/tests/gem_error_capture.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright © 2014 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:
+ *    Oscar Mateo <oscar.mateo at intel.com>
+ *
+ */
+
+/*
+ * Testcase: Check whether basic error state capture/dump mechanism is correctly
+ * working for all rings.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "drm.h"
+#include "ioctl_wrappers.h"
+#include "drmtest.h"
+#include "intel_io.h"
+#include "igt_debugfs.h"
+
+#define MAGIC_NUMBER 0x10001
+uint32_t batch[4] = {MI_NOOP, MI_BATCH_BUFFER_END, MAGIC_NUMBER, MAGIC_NUMBER};
+
+static void stop_rings(void)
+{
+	int fd;
+	static const char buf[] = "0xf";
+
+	fd = igt_debugfs_open("i915_ring_stop", O_WRONLY);
+	igt_assert(fd >= 0);
+
+	igt_assert(write(fd, buf, sizeof(buf)) == sizeof(buf));
+
+	close(fd);
+}
+
+static bool rings_stopped(void)
+{
+	int fd;
+	static char buf[128];
+	unsigned long long val;
+
+	fd = igt_debugfs_open("i915_ring_stop", O_RDONLY);
+	igt_assert(fd >= 0);
+
+	igt_assert(read(fd, buf, sizeof(buf)) > 0);
+	close(fd);
+
+	sscanf(buf, "%llx", &val);
+
+	return (bool)val;
+}
+
+static void clear_error_state(void)
+{
+	int fd;
+	static const char buf[] = "";
+
+	fd = igt_debugfs_open("i915_error_state", O_WRONLY);
+	igt_assert(fd >= 0);
+
+	igt_assert(write(fd, buf, sizeof(buf)) == sizeof(buf));
+	close(fd);
+}
+
+static void check_bb_contents(char **line, size_t *line_size,
+		FILE *file, int pos, uint32_t expected_value)
+{
+	char expected_line[32];
+
+	igt_assert(getline(line, line_size, file) > 0);
+
+	snprintf(expected_line, sizeof(expected_line), "%08x :  %08x",
+			4*pos, expected_value);
+
+	igt_assert(strstr(*line, expected_line));
+}
+
+static void check_error_state(const char *expected_ring_name,
+				uint64_t expected_offset)
+{
+	FILE *file;
+	int debug_fd;
+	char *line = NULL;
+	size_t line_size;
+	char *dashes = NULL;
+	char *ring_name = NULL;
+	uint32_t gtt_offset = 0;
+	bool matched;
+	int i;
+
+	debug_fd = igt_debugfs_open("i915_error_state", O_RDONLY);
+	igt_assert(debug_fd >= 0);
+	file = fdopen(debug_fd, "r");
+
+	while (getline(&line, &line_size, file) > 0) {
+		dashes = strstr(line, "---");
+		if (dashes) {
+			ring_name = realloc(ring_name, dashes - line);
+			strncpy(ring_name, line, dashes - line);
+			ring_name[dashes - line - 1] = '\0';
+
+			matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n",
+					&gtt_offset);
+			if (matched) {
+				igt_assert(strstr(ring_name, expected_ring_name));
+				igt_assert(gtt_offset == expected_offset);
+
+				for (i = 0; i < sizeof(batch) / 4; i++)
+					check_bb_contents(&line, &line_size,
+							file, i, batch[i]);
+
+				break;
+			}
+		}
+	}
+
+	igt_assert(matched);
+
+	free(line);
+	free(ring_name);
+
+	close(debug_fd);
+}
+
+static void test(int fd, uint32_t handle, unsigned ring_id, const char *ring_name)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec;
+	uint64_t presumed_offset;
+
+	gem_require_ring(fd, ring_id);
+
+	clear_error_state();
+
+	exec.handle = handle;
+	exec.relocation_count = 0;
+	exec.relocs_ptr = 0;
+	exec.alignment = 0;
+	exec.offset = 0;
+	exec.flags = 0;
+	exec.rsvd1 = 0;
+	exec.rsvd2 = 0;
+
+	execbuf.buffers_ptr = (uintptr_t)&exec;
+	execbuf.buffer_count = 1;
+	execbuf.batch_start_offset = 0;
+	execbuf.batch_len = 16;
+	execbuf.cliprects_ptr = 0;
+	execbuf.num_cliprects = 0;
+	execbuf.DR1 = 0;
+	execbuf.DR4 = 0;
+	execbuf.flags = ring_id;
+	i915_execbuffer2_set_context_id(execbuf, 0);
+	execbuf.rsvd2 = 0;
+
+	gem_execbuf(fd, &execbuf);
+	gem_sync(fd, handle);
+
+	presumed_offset = exec.offset;
+
+	stop_rings();
+
+	gem_execbuf(fd, &execbuf);
+	gem_sync(fd, handle);
+
+	igt_assert(rings_stopped() == false);
+	igt_assert(presumed_offset == exec.offset);
+
+	check_error_state(ring_name, exec.offset);
+}
+
+uint32_t handle;
+int fd;
+
+igt_main
+{
+	igt_fixture {
+		fd = drm_open_any();
+
+		handle = gem_create(fd, 4096);
+		gem_write(fd, handle, 0, batch, sizeof(batch));
+	}
+
+	igt_subtest("render")
+		test(fd, handle, I915_EXEC_RENDER, "render ring");
+
+	igt_subtest("bsd")
+		test(fd, handle, I915_EXEC_BSD, "bsd ring");
+
+	igt_subtest("blt")
+		test(fd, handle, I915_EXEC_BLT, "blitter ring");
+
+	igt_subtest("vebox")
+		test(fd, handle, I915_EXEC_VEBOX, "video enhancement ring");
+
+	igt_fixture {
+		gem_close(fd, handle);
+
+		close(fd);
+	}
+}
-- 
1.9.0




More information about the Intel-gfx mailing list