Re: [Intel-gfx] [PATCH 2/2] tests/drv_hangman: Add subtest for error state capture/dump

2014-05-21 Thread Mateo Lozano, Oscar
> -Original Message-
> From: Mika Kuoppala [mailto:mika.kuopp...@linux.intel.com]
> Sent: Tuesday, May 20, 2014 12:56 PM
> To: intel-gfx@lists.freedesktop.org
> Cc: Mateo Lozano, Oscar
> Subject: [PATCH 2/2] tests/drv_hangman: Add subtest for error state
> capture/dump
> 
> 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.
> 
> v4: Make as a subtest of drv_hangman.
> 
> Signed-off-by: Oscar Mateo  (v3)
> Signed-off-by: Mika Kuoppala 

Reviewed-by: Oscar Mateo  (v4)
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 2/2] tests/drv_hangman: Add subtest for error state capture/dump

2014-05-20 Thread Mika Kuoppala
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.

v4: Make as a subtest of drv_hangman.

Signed-off-by: Oscar Mateo  (v3)
Signed-off-by: Mika Kuoppala 
---
 tests/drv_hangman.c |  152 ++-
 1 file changed, 151 insertions(+), 1 deletion(-)

diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index cf141c6..8086573 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -22,6 +22,7 @@
  *
  * Authors:
  *Mika Kuoppala 
+ *Oscar Mateo 
  *
  */
 
@@ -30,6 +31,7 @@
 #include 
 #include 
 
+#include "intel_chipset.h"
 #include "drmtest.h"
 #include "igt_debugfs.h"
 #include "ioctl_wrappers.h"
@@ -222,11 +224,16 @@ static void check_other_clients(void)
igt_assert_f(0, "other clients running\n");
 }
 
+#define MAGIC_NUMBER 0x10001
+const uint32_t batch[] = { MI_NOOP,
+  MI_BATCH_BUFFER_END,
+  MAGIC_NUMBER,
+  MAGIC_NUMBER };
+
 static uint64_t submit_batch(int fd, unsigned ring_id, bool stop_ring)
 {
struct drm_i915_gem_execbuffer2 execbuf;
struct drm_i915_gem_exec_object2 exec;
-   const uint32_t batch[2] = { MI_BATCH_BUFFER_END, 0 };
uint64_t presumed_offset;
 
gem_require_ring(fd, ring_id);
@@ -333,6 +340,144 @@ static void test_ring_missed_irq(void)
close(fd);
 }
 
+static void check_error_state(const int gen,
+ 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++) {
+