[Intel-gfx] [PATCH 2/2] tests/gem_reset_stats: add tests for ban period ioctl

Mika Kuoppala mika.kuoppala at linux.intel.com
Thu Jan 29 05:32:51 PST 2015


Test parameter set/get for ban periods.
Test actual impact on banning.

Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
---
 tests/gem_reset_stats.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 100 insertions(+), 1 deletion(-)

diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 646d6da..7b04fb7 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -52,6 +52,8 @@
 #define RS_BATCH_PENDING (1 << 1)
 #define RS_UNKNOWN       (1 << 2)
 
+IGT_TEST_DESCRIPTION("Checks for RESET_STATS_IOCTL, context banning and reset recovery");
+
 static uint32_t devid;
 static bool hw_contexts;
 
@@ -1047,6 +1049,98 @@ static void defer_hangcheck(int ring_num)
 	close(fd);
 }
 
+static bool was_banned_in_period(int fd, int ctx, int seconds)
+{
+	int h1,h2,h3,h4;
+	bool banned;
+
+	h1 = inject_hang_no_ban_error(fd, ctx);
+	igt_assert(h1 >= 0);
+
+	sleep(seconds);
+
+	h2 = exec_valid(fd, ctx);
+	igt_assert(h2 >= 0);
+
+	h3 = inject_hang_no_ban_error(fd, ctx);
+	igt_assert(h3 >= 0);
+
+	gem_sync(fd, h3);
+
+	h4 = exec_valid(fd, ctx);
+	banned = (h4 == -EIO);
+
+	gem_close(fd, h1);
+	gem_close(fd, h2);
+	gem_close(fd, h3);
+	if (h4 >= 0)
+		gem_close(fd, h4);
+
+	return banned;
+}
+
+static int get_ban_period(int fd, uint32_t ctx)
+{
+	struct local_i915_gem_context_param p;
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = rand();
+	p.context = ctx;
+	p.value = ((uint64_t)rand() << 32) | rand();
+
+	igt_assert(gem_context_get_param(fd, &p) == 0);
+
+	return p.value;
+}
+
+static void set_ban_period(int fd, uint32_t ctx, int period)
+{
+	struct local_i915_gem_context_param p;
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = 0;
+	p.context = ctx;
+	p.value = period;
+	igt_assert(gem_context_set_param(fd, &p) == 0);
+}
+
+static void test_ban_period(bool new_ctx)
+{
+	int fd, period;
+	uint32_t ctx;
+
+	fd = drm_open_any();
+
+	igt_require(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD));
+
+	if (new_ctx)
+		ctx = context_create(fd);
+	else
+		ctx = 0;
+
+	period = get_ban_period(fd, ctx);
+	igt_assert(period > 2);
+
+	period += 2;
+
+	set_ban_period(fd, ctx, period);
+
+	igt_assert(was_banned_in_period(fd, ctx, period + 2) == false);
+
+	set_ban_period(fd, ctx, 0);
+
+	igt_assert(was_banned_in_period(fd, ctx, 0) == false);
+
+	/* We just hanged, wait for a while */
+	sleep(period + 2);
+
+	set_ban_period(fd, ctx, period);
+
+	igt_assert(was_banned_in_period(fd, ctx, period  / 4) == true);
+
+	close(fd);
+}
+
 static bool gem_has_hw_contexts(int fd)
 {
 	struct local_drm_i915_gem_context_create create;
@@ -1111,7 +1205,7 @@ static void check_gpu_ok(void)
 
 #define RING_HAS_CONTEXTS (current_ring->contexts(current_ring))
 #define RUN_TEST(...) do { check_gpu_ok(); __VA_ARGS__; check_gpu_ok(); } while (0)
-#define RUN_CTX_TEST(...) do { igt_skip_on(RING_HAS_CONTEXTS == false); RUN_TEST(__VA_ARGS__); } while (0)
+#define RUN_CTX_TEST(...) do { igt_require(RING_HAS_CONTEXTS); RUN_TEST(__VA_ARGS__); } while (0)
 
 igt_main
 {
@@ -1191,5 +1285,10 @@ igt_main
 		igt_subtest_f("defer-hangcheck-%s", name)
 			RUN_TEST(defer_hangcheck(i));
 
+		igt_subtest_f("ban-period-%s", name)
+			RUN_TEST(test_ban_period(false));
+
+		igt_subtest_f("ban-period-ctx-%s", name)
+			RUN_CTX_TEST(test_ban_period(true));
 	}
 }
-- 
1.9.1



More information about the Intel-gfx mailing list