From patchwork Fri May 9 11:54:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: oscar.mateo@intel.com X-Patchwork-Id: 4141961 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 415AC9F387 for ; Fri, 9 May 2014 11:59:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20541201E7 for ; Fri, 9 May 2014 11:59:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C7D6D201DC for ; Fri, 9 May 2014 11:59:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2404F6E033; Fri, 9 May 2014 04:59:27 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 401386E033 for ; Fri, 9 May 2014 04:59:26 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 09 May 2014 04:59:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="4.97,1018,1389772800"; d="scan'208"; a="537627409" Received: from omateolo-linux2.iwi.intel.com ([172.28.253.145]) by orsmga002.jf.intel.com with ESMTP; 09 May 2014 04:59:24 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 9 May 2014 12:54:17 +0100 Message-Id: <1399636457-3646-1-git-send-email-oscar.mateo@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1397234892-13820-1-git-send-email-oscar.mateo@intel.com> References: <1397234892-13820-1-git-send-email-oscar.mateo@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] tests/gem_error_capture: Initial testcase for error state capture/dump X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Mateo Guarantees that error capture works at a very basic level. v2: Also check that the ring object contains a reloc with MI_BB_START for the presumed batch object's address. v3: Chris review comments: - Move variables to local scope. - Do not assume there is only one request. - Some gen encode flags into the BB start address. Also, use igt_set/get_stop_rings as suggested by Mika Kuoppala. Signed-off-by: Oscar Mateo --- tests/.gitignore | 1 + tests/Makefile.sources | 1 + tests/gem_error_capture.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 tests/gem_error_capture.c diff --git a/tests/.gitignore b/tests/.gitignore index d360b20..3b60c90 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 fae7f97..b63696f 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..d725d6c --- /dev/null +++ b/tests/gem_error_capture.c @@ -0,0 +1,254 @@ +/* + * 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 + * + */ + +/* + * Testcase: Check whether basic error state capture/dump mechanism is correctly + * working for all rings. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "ioctl_wrappers.h" +#include "drmtest.h" +#include "intel_io.h" +#include "igt_debugfs.h" +#include "intel_chipset.h" + +#define MAGIC_NUMBER 0x10001 +uint32_t batch[4] = {MI_NOOP, MI_BATCH_BUFFER_END, MAGIC_NUMBER, MAGIC_NUMBER}; +static uint32_t devid; + +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_error_state(const char *expected_ring_name, + uint64_t expected_offset) +{ + FILE *file; + int debug_fd; + char *line = NULL; + size_t line_size = 0; + char *ring_name = NULL; + bool bb_ok = false, req_ok = false, ringbuf_ok = false; + + 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) { + char *dashes = NULL; + int bb_matched = 0; + uint32_t gtt_offset; + int req_matched = 0; + int requests; + uint32_t tail; + int ringbuf_matched = 0; + int i, items; + + dashes = strstr(line, "---"); + if (!dashes) + continue; + + ring_name = realloc(ring_name, dashes - line); + strncpy(ring_name, line, dashes - line); + ring_name[dashes - line - 1] = '\0'; + + bb_matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n", + >t_offset); + if (bb_matched == 1) { + char expected_line[32]; + + igt_assert(strstr(ring_name, expected_ring_name)); + igt_assert(gtt_offset == expected_offset); + + for (i = 0; i < sizeof(batch) / 4; i++) { + igt_assert(getline(&line, &line_size, file) > 0); + snprintf(expected_line, sizeof(expected_line), "%08x : %08x", + 4*i, batch[i]); + igt_assert(strstr(line, expected_line)); + } + bb_ok = true; + continue; + } + + req_matched = sscanf(dashes, "--- %d requests\n", &requests); + if (req_matched == 1) { + igt_assert(strstr(ring_name, expected_ring_name)); + igt_assert(requests > 0); + + for (i = 0; i < requests; i++) { + uint32_t seqno; + long jiffies; + + igt_assert(getline(&line, &line_size, file) > 0); + items = sscanf(line, " seqno 0x%08x, emitted %ld, tail 0x%08x\n", + &seqno, &jiffies, &tail); + igt_assert(items == 3); + } + req_ok = true; + continue; + } + + ringbuf_matched = sscanf(dashes, "--- ringbuffer = 0x%08x\n", + >t_offset); + if (ringbuf_matched == 1) { + unsigned int offset, command, expected_addr = 0; + + if (!strstr(ring_name, expected_ring_name)) + continue; + igt_assert(req_ok); + + for (i = 0; i < tail / 4; i++) { + igt_assert(getline(&line, &line_size, file) > 0); + items = sscanf(line, "%08x : %08x\n", + &offset, &command); + igt_assert(items == 2); + if ((command & 0x1F800000) == MI_BATCH_BUFFER_START) { + igt_assert(getline(&line, &line_size, file) > 0); + items = sscanf(line, "%08x : %08x\n", + &offset, &expected_addr); + igt_assert(items == 2); + i++; + } + } + if (intel_gen(devid) >= 4) + igt_assert(expected_addr == expected_offset); + else + igt_assert((expected_addr & ~0x1) == expected_offset); + ringbuf_ok = true; + continue; + } + + if (bb_ok && req_ok && ringbuf_ok) + break; + } + igt_assert(bb_ok && req_ok && ringbuf_ok); + + 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; + enum stop_ring_flags flags; + + 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; + + flags = igt_to_stop_ring_flag(ring_id); + igt_set_stop_rings(flags); + + gem_execbuf(fd, &execbuf); + gem_sync(fd, handle); + + igt_assert(igt_get_stop_rings() == STOP_RING_NONE); + 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)); + + devid = intel_get_drm_devid(fd); + } + + 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); + } +}