<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 10 November 2014 13:11, 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 Fri, 7 Nov 2014 21:56:48 +0200<br>
Giulio Camuffo <<a href="mailto:giuliocamuffo@gmail.com">giuliocamuffo@gmail.com</a>> wrote:<br>
<br>
> I have a couple of comments below, otherwise it looks good.<br>
><br>
><br>
> --<br>
> Giulio<br>
><br>
><br>
> 2014-09-24 15:37 GMT+03:00 Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>>:<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>
> > NO_TIMEOUTS.<br>
><br>
> I would namespace the env var a bit, something like WAYLAND_TESTS_NO_TIMEOUT.<br></div></div></blockquote><div><br></div><div>This follows the naming of LEAK_CHECK_ENABLED. I'll rename it and then send follow-up patch that will<br></div><div>rename LEAK_CHECK_ENABLED, so that it'll be consistent.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
><br>
> ><br>
> > Signed-off-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br>
> > ---<br>
> > tests/test-runner.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++<br>
> > tests/test-runner.h | 7 +++++++<br>
> > 2 files changed, 53 insertions(+)<br>
> ><br>
> > diff --git a/tests/test-runner.c b/tests/test-runner.c<br>
> > index af80d2b..c4687b7 100644<br>
> > --- a/tests/test-runner.c<br>
> > +++ b/tests/test-runner.c<br>
> > @@ -44,6 +44,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>
> > + * 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>
> > @@ -110,14 +115,54 @@ usage(const char *name, int status)<br>
> > exit(status);<br>
> > }<br>
> ><br>
> > +void<br>
> > +test_set_timeout(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>
><br>
> alarm() takes an 'unsigned', test_set_timeout should probably do the<br>
> same, or anyway catch <0 timeouts.<br></div></div></blockquote><div><br></div><div>Yes<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
><br>
> > + fprintf(stderr, "Timeout was %sset", re ? "re-" : "");<br>
> > +<br>
> > + if (to != 0)<br>
> > + fprintf(stderr, " to %d second from now.\n", to);<br>
> > + else<br>
> > + fprintf(stderr, " off.\n");<br>
> > +}<br>
> > +<br>
> > +static void<br>
> > +sigalrm_handler(int signum)<br>
> > +{<br>
> > + fprintf(stderr, "Test timeouted.\n");<br>
><br>
> nitpick: "timeouted"? Timed out sonds better to me. ;)<br></div></div></blockquote><div><br></div><div>true<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
><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 test. "<br>
> > @@ -189,6 +234,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("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..522cb84 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(int);<br>
> > +<br>
> > #endif<br>
<br>
</div></div>Yup, I completely agree with Giulio here.<br>
<br>
<br>
Thanks,<br>
pq<br></blockquote><div><br></div><div>Will fix it,<br><br></div><div>Thanks,<br>Marek <br></div></div><br></div></div>