Skip to contentSkip to conversation

tests/gem_reset_stats: split ctx tests

PATCH New Mika Kuoppala 1 participant 2 messages Jan 10, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tests/gem_reset_stats: split ctx tests

Split context related tests from non-context ones
and cleanup the naming.

---
 tests/gem_reset_stats.c |  138 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 108 insertions(+), 30 deletions(-)
tests/gem_reset_stats.c +108 -30
index 0515605..bed4a0c 100644
@@ -462,6 +462,94 @@ static void test_rs_ctx(int num_fds, int num_ctx, int hang_index,
 static void test_ban(void)
 {
 	int h1,h2,h3,h4,h5,h6,h7;
+	int fd_bad, fd_good;
+	int retry = 10;
+	int active_count = 0, pending_count = 0;
+	struct local_drm_i915_reset_stats rs_bad, rs_good;
+
+	fd_bad = drm_open_any();
+	igt_assert(fd_bad >= 0);
+
+	fd_good = drm_open_any();
+	igt_assert(fd_good >= 0);
+
+	assert_reset_status(fd_bad, 0, RS_NO_ERROR);
+	assert_reset_status(fd_good, 0, RS_NO_ERROR);
+
+	h1 = exec_valid(fd_bad, 0);
+	igt_assert(h1 >= 0);
+	h5 = exec_valid(fd_good, 0);
+	igt_assert(h5 >= 0);
+
+	assert_reset_status(fd_bad, 0, RS_NO_ERROR);
+	assert_reset_status(fd_good, 0, RS_NO_ERROR);
+
+	h2 = inject_hang(fd_bad, 0);
+	igt_assert(h2 >= 0);
+	active_count++;
+	/* Second hang will be pending for this */
+	pending_count++;
+
+	h6 = exec_valid(fd_good, 0);
+	h7 = exec_valid(fd_good, 0);
+
+        while (retry--) {
+                h3 = inject_hang(fd_bad, 0);
+                igt_assert(h3 >= 0);
+                gem_sync(fd_bad, h3);
+		active_count++;
+		/* This second hand will count as pending */
+                assert_reset_status(fd_bad, 0, RS_BATCH_ACTIVE);
+
+                h4 = exec_valid(fd_bad, 0);
+                if (h4 == -EIO) {
+                        gem_close(fd_bad, h3);
+                        break;
+                }
+
+                /* Should not happen often but sometimes hang is declared too slow
+                 * due to our way of faking hang using loop */
+
+                igt_assert(h4 >= 0);
+                gem_close(fd_bad, h3);
+                gem_close(fd_bad, h4);
+
+                printf("retrying for ban (%d)\n", retry);
+        }
+
+	igt_assert(h4 == -EIO);
+	assert_reset_status(fd_bad, 0, RS_BATCH_ACTIVE);
+
+	gem_sync(fd_good, h7);
+	assert_reset_status(fd_good, 0, RS_BATCH_PENDING);
+
+	igt_assert(gem_reset_stats(fd_good, 0, &rs_good) == 0);
+	igt_assert(gem_reset_stats(fd_bad, 0, &rs_bad) == 0);
+
+	igt_assert(rs_bad.batch_active == active_count);
+	igt_assert(rs_bad.batch_pending == pending_count);
+	igt_assert(rs_good.batch_active == 0);
+	igt_assert(rs_good.batch_pending == 2);
+
+	gem_close(fd_bad, h1);
+	gem_close(fd_bad, h2);
+	gem_close(fd_good, h6);
+	gem_close(fd_good, h7);
+
+	h1 = exec_valid(fd_good, 0);
+	igt_assert(h1 >= 0);
+	gem_close(fd_good, h1);
+
+	close(fd_bad);
+	close(fd_good);
+
+	igt_assert(gem_reset_status(fd_bad, 0) < 0);
+	igt_assert(gem_reset_status(fd_good, 0) < 0);
+}
+
+static void test_ban_ctx(void)
+{
+	int h1,h2,h3,h4,h5,h6,h7;
 	int ctx_good, ctx_bad;
 	int fd;
 	int retry = 10;
@@ -554,7 +642,7 @@ static void test_ban(void)
 	close(fd);
 }
 
-static void test_nonrelated_hang(void)
+static void test_unrelated_ctx(void)
 {
 	int h1,h2;
 	int fd1,fd2;
@@ -603,7 +691,7 @@ static int get_reset_count(int fd, int ctx)
 	return rs.reset_count;
 }
 
-static void test_double_destroy_pending(void)
+static void test_close_pending_ctx(void)
 {
 	int fd, h;
 	uint32_t ctx;
@@ -766,7 +854,7 @@ static void drop_root(void)
 	igt_assert(getuid() == 2);
 }
 
-static void __test_count(const bool create_ctx)
+static void test_reset_count(const bool create_ctx)
 {
 	int fd, h, ctx;
 	long c1, c2;
@@ -813,22 +901,6 @@ static void __test_count(const bool create_ctx)
 	close(fd);
 }
 
-static void test_count(void)
-{
-	return __test_count(false);
-}
-
-static void test_count_context(void)
-{
-	return __test_count(true);
-}
-
-static void test_global_reset_count(void)
-{
-	test_count();
-	test_count_context();
-}
-
 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
 {
 	struct local_drm_i915_reset_stats rs;
@@ -934,32 +1006,38 @@ igt_main
 		close(fd);
 	}
 
-	igt_subtest("basic-reset-status")
+	igt_subtest("params")
+		test_params();
+
+	igt_subtest("reset-stats")
 		test_rs(4, 1, 0);
 
-	igt_subtest("context-reset-status")
+	igt_subtest("reset-stats-ctx")
 		test_rs_ctx(4, 4, 1, 2);
 
 	igt_subtest("ban")
 		test_ban();
 
-	igt_subtest("ctx-unrelated")
-		test_nonrelated_hang();
+	igt_subtest("ban-ctx")
+		test_ban_ctx();
+
+	igt_subtest("unrelated-ctx")
+		test_unrelated_ctx();
 
-	igt_subtest("global-count")
-		test_global_reset_count();
+	igt_subtest("reset-count")
+		test_reset_count(false);
 
-	igt_subtest("double-destroy-pending")
-		test_double_destroy_pending();
+	igt_subtest("reset-count-ctx")
+		test_reset_count(true);
 
 	igt_subtest("close-pending")
 		test_close_pending();
 
+	igt_subtest("close-pending-ctx")
+		test_close_pending_ctx();
+
 	igt_subtest("close-pending-fork") {
 		test_close_pending_fork(true);
 		test_close_pending_fork(false);
 	}
-
-	igt_subtest("params")
-		test_params();
 }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 tests/gem_reset_stats: run tests on all rings

Run all relevant tests on all rings.

---
 tests/gem_reset_stats.c |  132 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 90 insertions(+), 42 deletions(-)
tests/gem_reset_stats.c +90 -42
index bed4a0c..a98e2ad 100644
@@ -78,6 +78,41 @@ struct local_drm_i915_gem_context_destroy {
 
 static igt_debugfs_t dfs;
 
+#define LOCAL_I915_EXEC_VEBOX	(4 << 0)
+
+struct target_ring;
+
+static bool gem_has_render(int fd)
+{
+	return true;
+}
+
+static bool has_context(const struct target_ring *ring);
+
+static const struct target_ring {
+	uint32_t exec;
+	bool (*present)(int fd);
+	bool (*contexts)(const struct target_ring *ring);
+	const char *name;
+} rings[] = {
+	{ I915_EXEC_RENDER, gem_has_render, has_context, "render" },
+	{ I915_EXEC_BLT, gem_has_blt, has_context, "blt" },
+	{ I915_EXEC_BSD, gem_has_bsd, has_context, "bsd" },
+	{ LOCAL_I915_EXEC_VEBOX, gem_has_vebox, has_context, "vebox" },
+};
+
+static bool has_context(const struct target_ring *ring)
+{
+	if(ring->exec == I915_EXEC_RENDER)
+		return true;
+
+	return false;
+}
+
+#define NUM_RINGS (sizeof(rings)/sizeof(struct target_ring))
+
+static const struct target_ring *current_ring;
+
 static uint32_t context_create(int fd)
 {
 	struct local_drm_i915_gem_context_create create;
@@ -160,7 +195,7 @@ static int gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
 	return 0;
 }
 
-static int exec_valid(int fd, int ctx)
+static int exec_valid_ring(int fd, int ctx, int ring)
 {
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 exec;
@@ -186,7 +221,7 @@ static int exec_valid(int fd, int ctx)
 	execbuf.num_cliprects = 0;
 	execbuf.DR1 = 0;
 	execbuf.DR4 = 0;
-	execbuf.flags = 0;
+	execbuf.flags = ring;
 	i915_execbuffer2_set_context_id(execbuf, ctx);
 	execbuf.rsvd2 = 0;
 
@@ -197,6 +232,11 @@ static int exec_valid(int fd, int ctx)
 	return exec.handle;
 }
 
+static int exec_valid(int fd, int ctx)
+{
+	return exec_valid_ring(fd, ctx, current_ring->exec);
+}
+
 static void stop_rings(void)
 {
 	int fd;
@@ -211,7 +251,7 @@ static void stop_rings(void)
 #define BUFSIZE (4 * 1024)
 #define ITEMS   (BUFSIZE >> 2)
 
-static int inject_hang(int fd, int ctx)
+static int inject_hang_ring(int fd, int ctx, int ring)
 {
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 exec;
@@ -249,7 +289,7 @@ static int inject_hang(int fd, int ctx)
 	execbuf.num_cliprects = 0;
 	execbuf.DR1 = 0;
 	execbuf.DR4 = 0;
-	execbuf.flags = 0;
+	execbuf.flags = ring;
 	i915_execbuffer2_set_context_id(execbuf, ctx);
 	execbuf.rsvd2 = 0;
 
@@ -290,7 +330,7 @@ static int inject_hang(int fd, int ctx)
 	execbuf.num_cliprects = 0;
 	execbuf.DR1 = 0;
 	execbuf.DR4 = 0;
-	execbuf.flags = 0;
+	execbuf.flags = ring;
 	i915_execbuffer2_set_context_id(execbuf, ctx);
 	execbuf.rsvd2 = 0;
 
@@ -305,6 +345,11 @@ static int inject_hang(int fd, int ctx)
 	return exec.handle;
 }
 
+static int inject_hang(int fd, int ctx)
+{
+	return inject_hang_ring(fd, ctx, current_ring->exec);
+}
+
 static int _assert_reset_status(int fd, int ctx, int status)
 {
 	int rs;
@@ -727,20 +772,6 @@ static void test_close_pending(void)
 	close(fd);
 }
 
-#define LOCAL_I915_EXEC_VEBOX	(4 << 0)
-
-static const struct target_ring {
-	uint32_t exec;
-	bool (*avail)(int);
-} rings[] = {
-	{ 0, 0 },
-	{ I915_EXEC_BLT, gem_has_blt },
-	{ I915_EXEC_BSD, gem_has_bsd },
-	{ LOCAL_I915_EXEC_VEBOX, gem_has_vebox },
-};
-
-#define NUM_RINGS (sizeof(rings)/sizeof(struct target_ring))
-
 static void exec_noop_on_each_ring(int fd, const bool reverse)
 {
 	uint32_t batch[2] = {MI_BATCH_BUFFER_END, 0};
@@ -777,7 +808,7 @@ static void exec_noop_on_each_ring(int fd, const bool reverse)
 
 		ring = reverse ? &rings[NUM_RINGS - 1 - i] : &rings[i];
 
-		if (!ring->avail || (ring->avail && ring->avail(fd))) {
+		if (ring->present(fd)) {
 			execbuf.flags = ring->exec;
 			do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
 		}
@@ -980,17 +1011,19 @@ static void test_params(void)
 	close(fd);
 }
 
+#define RING_HAS_CONTEXTS current_ring->contexts(current_ring)
+#define RUN_CTX_TEST(...) do { igt_skip_on(RING_HAS_CONTEXTS == false); __VA_ARGS__; } while (0)
 
 igt_main
 {
 	struct local_drm_i915_gem_context_create create;
 	uint32_t devid;
-	int fd;
 	int ret;
 
 	igt_skip_on_simulation();
 
 	igt_fixture {
+		int fd;
 		fd = drm_open_any();
 		devid = intel_get_drm_devid(fd);
 		igt_require_f(intel_gen(devid) >= 4,
@@ -1009,35 +1042,50 @@ igt_main
 	igt_subtest("params")
 		test_params();
 
-	igt_subtest("reset-stats")
-		test_rs(4, 1, 0);
+	for (int i = 0; i < NUM_RINGS; i++) {
+		const char *name;
+		int fd;
+
+		current_ring = &rings[i];
+		name = current_ring->name;
 
-	igt_subtest("reset-stats-ctx")
-		test_rs_ctx(4, 4, 1, 2);
+		fd = drm_open_any();
+		gem_require_ring(fd, current_ring->exec);
+
+		igt_subtest_f("reset-stats-%s", name)
+			test_rs(4, 1, 0);
+
+		igt_subtest_f("reset-stats-ctx-%s", name)
+			RUN_CTX_TEST(test_rs_ctx(4, 4, 1, 2));
 
-	igt_subtest("ban")
-		test_ban();
+		igt_subtest_f("ban-%s", name)
+			test_ban();
 
-	igt_subtest("ban-ctx")
-		test_ban_ctx();
+		igt_subtest_f("ban-ctx-%s", name)
+			RUN_CTX_TEST(test_ban_ctx());
 
-	igt_subtest("unrelated-ctx")
-		test_unrelated_ctx();
+		igt_subtest_f("reset-count-%s", name)
+			test_reset_count(false);
 
-	igt_subtest("reset-count")
-		test_reset_count(false);
+		igt_subtest_f("reset-count-ctx-%s", name)
+			RUN_CTX_TEST(test_reset_count(true));
 
-	igt_subtest("reset-count-ctx")
-		test_reset_count(true);
+		igt_subtest_f("unrelated-ctx-%s", name)
+			RUN_CTX_TEST(test_unrelated_ctx());
 
-	igt_subtest("close-pending")
-		test_close_pending();
+		igt_subtest_f("close-pending-%s", name) {
+			test_close_pending();
+			gem_quiescent_gpu(fd);
+		}
 
-	igt_subtest("close-pending-ctx")
-		test_close_pending_ctx();
+		igt_subtest_f("close-pending-ctx-%s", name) {
+			RUN_CTX_TEST(test_close_pending_ctx());
+			gem_quiescent_gpu(fd);
+		}
 
-	igt_subtest("close-pending-fork") {
-		test_close_pending_fork(true);
-		test_close_pending_fork(false);
+		igt_subtest_f("close-pending-fork-%s", name) {
+			test_close_pending_fork(true);
+			test_close_pending_fork(false);
+		}
 	}
 }
Signature · 1 line
1.7.9.5