From patchwork Mon May 12 10:35:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 4158381 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB4CD9F387 for ; Mon, 12 May 2014 10:35:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3273520219 for ; Mon, 12 May 2014 10:35:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 57DCC20148 for ; Mon, 12 May 2014 10:35:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BED586E4C8; Mon, 12 May 2014 03:35:26 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by gabe.freedesktop.org (Postfix) with ESMTP id E89E76E4C8 for ; Mon, 12 May 2014 03:35:24 -0700 (PDT) Received: by mail-we0-f172.google.com with SMTP id k48so6683509wev.31 for ; Mon, 12 May 2014 03:35:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=+X/F/DPWIVRIsDLogtNDbRYlURrqCBDX6X1HWIPFUZc=; b=ZvC54fSdLDwrZlH0MbFkjqXtSm/6HtidUJP7h3EvsM+vi8kt6O4vOWkiAlhi2w5GUh 0FZcY8qu1OLuKBleXz5dp+vE7oVthCeOgo+1RGbR93g5327AR8Kd8SEieTfWaTFEXDYi +urVC0wIhbp9jFZcq8yAYi9qTS0C6TEkB8tWNhjWM6CLQFcRl8IOZeJJcW+L9ppeLXSH P4CYot7y+sQwE+totA7VD6aaOe1CNr4IVVa/9rBb6ApeYJx4RdzUBaIVtRHsXpArVN21 G6rL+s/fqU4Shsxuo+HijSyNJKOS0hzVQKytEFhpHGO4VXVbdfc6Btr1mVQqYJJUxF0g JXsw== X-Gm-Message-State: ALoCoQkCAb6CqyNcwvPzlFrXx6E/I56frK69BOAW/1xu/OjHY1ieDHu5Nv+fpdK1JoYAMHlBVSVj X-Received: by 10.180.89.1 with SMTP id bk1mr14773008wib.35.1399890923642; Mon, 12 May 2014 03:35:23 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id cw2sm17362761wjb.39.2014.05.12.03.35.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 May 2014 03:35:22 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Mon, 12 May 2014 11:35:20 +0100 Message-Id: <1399890921-13068-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 1.9.0 Subject: [Intel-gfx] [PATCH i-g-t 1/2] lib: add igt_set_timeout X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 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.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Add a function to stop and fail a test after the specified number of seconds have elapsed. Signed-off-by: Thomas Wood Acked-by: Damien Lespiau --- lib/igt_core.c | 44 +++++++++++++++++++++++++++++++++++++++++--- lib/igt_core.h | 2 ++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 6f137ab..238068c 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -618,9 +618,12 @@ void igt_fail(int exitcode) if (test_child) exit(exitcode); - if (in_subtest) - exit_subtest("FAIL"); - else { + if (in_subtest) { + if (exitcode == 78) + exit_subtest("TIMEOUT"); + else + exit_subtest("FAIL"); + } else { assert(!test_with_subtests || in_fixture); if (in_fixture) { @@ -1201,3 +1204,38 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args) } else vprintf(format, args); } + +static void igt_alarm_handler(int signal) +{ + /* subsequent tests are skipped */ + skip_subtests_henceforth = SKIP; + + /* exit with status 78 to indicate timeout */ + igt_fail(78); +} + +/** + * igt_set_timeout: + * @seconds: seconds before timeout + * + * Stop the current test and skip any subsequent tests after the specified + * number of seconds have elapsed. The test will exit with "timeout" status + * (78). Any previous timer is cancelled and no timeout is scheduled if @seconds + * is zero. + * + */ +void igt_set_timeout(unsigned int seconds) +{ + struct sigaction sa; + + sa.sa_handler = igt_alarm_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + + if (seconds == 0) + sigaction(SIGALRM, NULL, NULL); + else + sigaction(SIGALRM, &sa, NULL); + + alarm(seconds); +} diff --git a/lib/igt_core.h b/lib/igt_core.h index 7ede0d3..63ed9a5 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -465,4 +465,6 @@ extern enum igt_log_level igt_log_level; } while (0) +void igt_set_timeout(unsigned int timeout); + #endif /* IGT_CORE_H */