* [PATCH i-g-t 1/2] lib: add igt_set_timeout
@ 2014-05-12 10:35 Thomas Wood
2014-05-12 10:35 ` [PATCH i-g-t 2/2] lib: set a timeout when reading crc values Thomas Wood
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thomas Wood @ 2014-05-12 10:35 UTC (permalink / raw)
To: intel-gfx
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH i-g-t 2/2] lib: set a timeout when reading crc values
2014-05-12 10:35 [PATCH i-g-t 1/2] lib: add igt_set_timeout Thomas Wood
@ 2014-05-12 10:35 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Wood @ 2014-05-12 10:35 UTC (permalink / raw)
To: intel-gfx
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
lib/igt_debugfs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 4fd2e5a..0912f5b 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -459,7 +459,10 @@ static bool read_one_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out)
ssize_t bytes_read;
char buf[pipe_crc->buffer_len];
+ igt_set_timeout(5);
bytes_read = read(pipe_crc->crc_fd, &buf, pipe_crc->line_len);
+ igt_set_timeout(0);
+
igt_assert_cmpint(bytes_read, ==, pipe_crc->line_len);
buf[bytes_read] = '\0';
--
1.9.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH i-g-t 1/2] lib: add igt_set_timeout
2014-05-12 10:35 [PATCH i-g-t 1/2] lib: add igt_set_timeout Thomas Wood
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 ` Damien Lespiau
2014-05-12 21:39 ` Daniel Vetter
2 siblings, 0 replies; 4+ messages in thread
From: Damien Lespiau @ 2014-05-12 13:31 UTC (permalink / raw)
To: Thomas Wood; +Cc: intel-gfx
On Mon, May 12, 2014 at 11:35:20AM +0100, Thomas Wood wrote:
> 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>
Looks like a useful helper to have in any case. Both patches are:
Acked-by: Damien Lespiau <damien.lespiau@intel.com>
--
Damien
> ---
> 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
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH i-g-t 1/2] lib: add igt_set_timeout
2014-05-12 10:35 [PATCH i-g-t 1/2] lib: add igt_set_timeout Thomas Wood
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
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2014-05-12 21:39 UTC (permalink / raw)
To: Thomas Wood; +Cc: intel-gfx
On Mon, May 12, 2014 at 11:35:20AM +0100, Thomas Wood wrote:
> 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)
Right above this is the igt_exitcode = exitcode assignment. I wonder
whether we should upgrade a TIMEOUT to a FAIL if we run more than one
subtest.
> 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);
Hm, I didn't notice that your piglit testcase encodes 78 as "timeout". Or
I've forgotten about it again ;-) Iirc my first attempt didn't
special-case exit codes beyond the 77 "skip", but this works. One useful
thing though would be to add a bunch of #defines for these special values
somewhere in a header, e.g.
#define IGT_EXIT_TIMEOUT 78
#define IGT_EXIT_SKIP 77
#define IGT_EXIT_SUCCESS 0
But this is a follow-up patch.
-Daniel
> +}
> +
> +/**
> + * 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
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-12 21:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-12 10:35 [PATCH i-g-t 1/2] lib: add igt_set_timeout Thomas Wood
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox