diff mbox

tests/gem_reset_stats: add tests for ban period ioctl

Message ID 1420640484-13194-1-git-send-email-mika.kuoppala@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mika Kuoppala Jan. 7, 2015, 2:21 p.m. UTC
Test parameter set/get for ban periods.
Test actual impact on banning.

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

Comments

Chris Wilson Jan. 7, 2015, 2:21 p.m. UTC | #1
On Wed, Jan 07, 2015 at 04:21:24PM +0200, Mika Kuoppala wrote:
> Test parameter set/get for ban periods.
> Test actual impact on banning.

Nice. These are more like the tests Daniel was thinking of when he asked
his question. Could you please separate out the negative parameter
testing to a new gem_ctx_param set of tests? Testing whether changing
the ban period has any effect seems sensible to keep in gem_reset_stats.

> +	igt_skip_on(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD)
> +		    == 0);

is better as

igt_require(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD);

as that produces a saner error message.
-Chris
Daniel Vetter Jan. 7, 2015, 4:49 p.m. UTC | #2
On Wed, Jan 07, 2015 at 02:21:54PM +0000, Chris Wilson wrote:
> On Wed, Jan 07, 2015 at 04:21:24PM +0200, Mika Kuoppala wrote:
> > Test parameter set/get for ban periods.
> > Test actual impact on banning.
> 
> Nice. These are more like the tests Daniel was thinking of when he asked
> his question. Could you please separate out the negative parameter
> testing to a new gem_ctx_param set of tests? Testing whether changing
> the ban period has any effect seems sensible to keep in gem_reset_stats.

Imo the negative parameter tests are fine as-is, I've used the current
naming at least for the testcase tag. Usuaully I put an -invalid-
somewhere in the name though, but that's optional. Anyway patch merged,
thanks for patch, testcase& review.
-Daniel

> 
> > +	igt_skip_on(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD)
> > +		    == 0);
> 
> is better as
> 
> igt_require(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD);
> 
> as that produces a saner error message.
> -Chris
> 
> -- 
> Chris Wilson, Intel Open Source Technology Centre
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

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));
 	}
 }