From patchwork Wed Jan 7 14:21:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 5584861 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4A81F9F443 for ; Wed, 7 Jan 2015 14:16:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F82020221 for ; Wed, 7 Jan 2015 14:16:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5FD7C201EF for ; Wed, 7 Jan 2015 14:16:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E11DE6E321; Wed, 7 Jan 2015 06:16:15 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id AE01C6E321 for ; Wed, 7 Jan 2015 06:16:14 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 07 Jan 2015 06:13:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,714,1413270000"; d="scan'208";a="633776718" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.102]) by orsmga001.jf.intel.com with ESMTP; 07 Jan 2015 06:16:12 -0800 Received: by rosetta (Postfix, from userid 1000) id DD2BD80052; Wed, 7 Jan 2015 16:21:27 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Wed, 7 Jan 2015 16:21:24 +0200 Message-Id: <1420640484-13194-1-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <871tn665mi.fsf@gaia.fi.intel.com> References: <871tn665mi.fsf@gaia.fi.intel.com> Subject: [Intel-gfx] [PATCH] tests/gem_reset_stats: add tests for ban period ioctl X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test parameter set/get for ban periods. Test actual impact on banning. Signed-off-by: Mika Kuoppala --- 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)); } }