summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMika Kuoppala <mika.kuoppala@intel.com>2015-01-05 18:08:06 +0200
committerMika Kuoppala <mika.kuoppala@intel.com>2015-01-05 19:12:19 +0200
commit7d43537d7e837188588500be3eb583ff98cfd081 (patch)
treecb4d26efbd240819418ac7ecb5cb974aa49a27db
parent303e05b456de8da8ac1997789055f62e31f9028f (diff)
tests/gem_reset_stats: add tests for ban period ioctlban_params
Test parameter set/get for ban periods. Test actual impact on banning. Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
-rw-r--r--tests/gem_reset_stats.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index ab8728a3..f1c141e1 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -1058,6 +1058,168 @@ 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);
+
+ /* We just hanged, wait for a while */
+ sleep(period + 2);
+
+ 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 +1364,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));
}
}