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

Mika Kuoppala mika.kuoppala at linux.intel.com
Wed Jan 7 06:21:24 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 | 179 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 179 insertions(+)

diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index ab8728a..fdbc84b 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -1058,6 +1058,174 @@ 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, int ctx)
+{
+	struct local_i915_gem_context_param p;
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = rand();
+	p.context = rand();
+	if (p.context == ctx)
+		p.context = ctx + 1;
+	p.value = ((uint64_t)rand() << 32) | rand();
+
+	igt_assert(gem_context_get_param(fd, &p) == -1);
+	igt_assert(errno == ENOENT);
+
+	p.context = ctx;
+	p.param = 0xdeadf00d;
+
+	igt_assert(gem_context_get_param(fd, &p) == -1);
+	igt_assert(errno == EINVAL);
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	igt_assert(gem_context_get_param(fd, &p) == 0);
+
+	return p.value;
+}
+
+static int _set_ban_period(int fd, struct local_i915_gem_context_param *p)
+{
+	int r;
+
+	r = gem_context_set_param(fd, p);
+
+	if (r == -1)
+		return errno;
+
+	return 0;
+}
+
+static int set_ban_period(int fd, int 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;
+	return _set_ban_period(fd, &p);
+}
+
+static void test_ban_period_params(bool new_ctx)
+{
+	struct local_i915_gem_context_param p;
+	int fd, ctx, period;
+
+	fd = drm_open_any();
+	igt_assert(fd >= 0);
+
+	igt_skip_on(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD)
+		    == 0);
+
+	if (new_ctx)
+		ctx = context_create(fd);
+	else
+		ctx = 0;
+
+	period = get_ban_period(fd, ctx);
+	igt_assert(period > 2);
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = 0xdeadf00d;
+	p.context = ctx;
+	p.value = ((uint64_t)rand() << 32) | rand();
+
+	igt_assert(_set_ban_period(fd, &p) == EINVAL);
+
+	p.size = 0;
+	p.context = 0xdeadf00d;
+
+	igt_assert(_set_ban_period(fd, &p) == ENOENT);
+
+	p.size = 0;
+	p.context = ctx;
+	p.value = period;
+
+	igt_fork(child, 1) {
+		igt_drop_root();
+		p.value -= 2;
+
+		igt_assert(_set_ban_period(fd, &p) == EPERM);
+	}
+
+	igt_assert(_set_ban_period(fd, &p) == 0);
+
+	p.size = 0;
+	p.context = ctx;
+	p.value = period + 1;
+
+	igt_assert(_set_ban_period(fd, &p) == 0);
+}
+
+static void test_ban_period(bool new_ctx)
+{
+	int fd, ctx, period;
+
+	fd = drm_open_any();
+	igt_assert(fd >= 0);
+
+	igt_skip_on(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD)
+		    == 0);
+
+	if (new_ctx)
+		ctx = context_create(fd);
+	else
+		ctx = 0;
+
+	period = get_ban_period(fd, ctx);
+	igt_assert(period > 2);
+
+	period += 2;
+
+	igt_assert(set_ban_period(fd, ctx, period) == 0);
+
+	igt_assert(was_banned_in_period(fd, ctx, period + 2) == false);
+
+	igt_assert(set_ban_period(fd, ctx, 0) == 0);
+
+	igt_assert(was_banned_in_period(fd, ctx, 0) == false);
+
+	/* We just hanged, wait for a while */
+	sleep(period + 2);
+
+	igt_assert(set_ban_period(fd, ctx, period) == 0);
+
+	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;
@@ -1202,5 +1370,16 @@ igt_main
 		igt_subtest_f("defer-hangcheck-%s", name)
 			RUN_TEST(defer_hangcheck(i));
 
+		igt_subtest_f("ban-period-params-%s", name)
+			RUN_TEST(test_ban_period_params(false));
+
+		igt_subtest_f("ban-period-params-ctx-%s", name)
+			RUN_CTX_TEST(test_ban_period_params(true));
+
+		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