<div dir="ltr"><div>Oh, yes, sure.<br><br>Thanks,<br></div>Marek<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 17 November 2014 16:02, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, 12 Nov 2014 13:16:42 +0100<br>
Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> wrote:<br>
<br>
> Add test_set_timeout() function that allows the test to<br>
> set timeout for its completition. Any other call to the function<br>
> re-sets the timeout to the new value. The timeouts can be turned off<br>
> (usefull when debugging) by setting evironment variable<br>
> WAYLAND_TESTS_NO_TIMEOUTS.<br>
><br>
> v2:<br>
> rename NO_TIMEOUTS to WAYLAND_TESTS_NO_TIMEOUTS<br>
> use unsigned int as argument of test_set_timeout()<br>
> improve printing of the message about timeout<br>
><br>
> Signed-off-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br>
> ---<br>
> tests/test-runner.c | 47<br>
> +++++++++++++++++++++++++++++++++++++++++++++++ tests/test-runner.h<br>
> | 7 +++++++ 2 files changed, 54 insertions(+)<br>
><br>
> diff --git a/tests/test-runner.c b/tests/test-runner.c<br>
> index 8f3d5d3..3b2e6a9 100644<br>
> --- a/tests/test-runner.c<br>
> +++ b/tests/test-runner.c<br>
> @@ -41,6 +41,11 @@ static void* (*sys_calloc)(size_t, size_t);<br>
><br>
> int leak_check_enabled;<br>
><br>
> +/* when this var is set to 0, every call to test_set_timeout() is<br>
> + * suppressed - handy when debugging the test. Can be set by<br>
> + * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */<br>
> +static int timeouts_enabled = 1;<br>
> +<br>
> extern const struct test __start_test_section, __stop_test_section;<br>
><br>
> __attribute__ ((visibility("default"))) void *<br>
> @@ -107,14 +112,55 @@ usage(const char *name, int status)<br>
> exit(status);<br>
> }<br>
><br>
> +void<br>
> +test_set_timeout(unsigned int to)<br>
> +{<br>
> + int re;<br>
> +<br>
> + if (!timeouts_enabled) {<br>
> + fprintf(stderr, "Timeouts suppressed.\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + re = alarm(to);<br>
> + fprintf(stderr, "Timeout was %sset", re ? "re-" : "");<br>
> +<br>
> + if (to != 0)<br>
> + fprintf(stderr, " to %d second%c from now.\n",<br>
> + to, to > 1 ? 's' : 0);<br>
> + else<br>
> + fprintf(stderr, " off.\n");<br>
> +}<br>
> +<br>
> +static void<br>
> +sigalrm_handler(int signum)<br>
> +{<br>
> + fprintf(stderr, "Test timed out.\n");<br>
> + abort();<br>
> +}<br>
> +<br>
> static void<br>
> run_test(const struct test *t)<br>
> {<br>
> int cur_alloc = num_alloc;<br>
> int cur_fds, num_fds;<br>
> + struct sigaction sa;<br>
><br>
> cur_fds = count_open_fds();<br>
> +<br>
> + if (timeouts_enabled) {<br>
> + sa.sa_handler = sigalrm_handler;<br>
> + sa.sa_flags = 0;<br>
> + sigemptyset(&sa.sa_mask);<br>
> + assert(sigaction(SIGALRM, &sa, NULL) == 0);<br>
> + }<br>
> +<br>
> t->run();<br>
> +<br>
> + /* turn off timeout (if any) after test completition */<br>
> + if (timeouts_enabled)<br>
> + alarm(0);<br>
> +<br>
> if (leak_check_enabled) {<br>
> if (cur_alloc != num_alloc) {<br>
> fprintf(stderr, "Memory leak detected in<br>
> test. " @@ -147,6 +193,7 @@ int main(int argc, char *argv[])<br>
> sys_free = dlsym(RTLD_NEXT, "free");<br>
><br>
> leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");<br>
> + timeouts_enabled = !getenv("WAYLAND_TESTS_NO_TIMEOUTS");<br>
><br>
> if (argc == 2 && strcmp(argv[1], "--help") == 0)<br>
> usage(argv[0], EXIT_SUCCESS);<br>
> diff --git a/tests/test-runner.h b/tests/test-runner.h<br>
> index 707504c..3295e1c 100644<br>
> --- a/tests/test-runner.h<br>
> +++ b/tests/test-runner.h<br>
> @@ -37,4 +37,11 @@ count_open_fds(void);<br>
> void<br>
> exec_fd_leak_check(int nr_expected_fds); /* never returns */<br>
><br>
> +/*<br>
> + * set/reset the timeout in seconds. The timeout starts<br>
> + * at the point of invoking this function<br>
> + */<br>
> +void<br>
> +test_set_timeout(unsigned int);<br>
> +<br>
> #endif<br>
<br>
</div></div>Nice, pushed.<br>
<br>
However, would you like to follow up with a patch to fix the NUL byte<br>
printing in test_set_timeout()? ;-)<br>
<br>
<br>
Thanks,<br>
pq<br>
</blockquote></div><br></div>