public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Thomas Wood <thomas.wood@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 1/2] lib: add igt_set_timeout
Date: Mon, 12 May 2014 11:35:20 +0100	[thread overview]
Message-ID: <1399890921-13068-1-git-send-email-thomas.wood@intel.com> (raw)

Add a function to stop and fail a test after the specified number of
seconds have elapsed.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 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 */
-- 
1.9.0

             reply	other threads:[~2014-05-12 10:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-12 10:35 Thomas Wood [this message]
2014-05-12 10:35 ` [PATCH i-g-t 2/2] lib: set a timeout when reading crc values Thomas Wood
2014-05-12 13:31 ` [PATCH i-g-t 1/2] lib: add igt_set_timeout Damien Lespiau
2014-05-12 21:39 ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399890921-13068-1-git-send-email-thomas.wood@intel.com \
    --to=thomas.wood@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox