[PATCH wayland 1/4] tests: add timeout

Marek Chalupa mchqwerty at gmail.com
Wed Nov 12 02:33:46 PST 2014


On 12 November 2014 11:22, Marek Chalupa <mchqwerty at gmail.com> wrote:

>
>
> On 10 November 2014 13:11, Pekka Paalanen <ppaalanen at gmail.com> wrote:
>
>> On Fri, 7 Nov 2014 21:56:48 +0200
>> Giulio Camuffo <giuliocamuffo at gmail.com> wrote:
>>
>> > I have a couple of comments below, otherwise it looks good.
>> >
>> >
>> > --
>> > Giulio
>> >
>> >
>> > 2014-09-24 15:37 GMT+03:00 Marek Chalupa <mchqwerty at gmail.com>:
>> > > Add test_set_timeout() function that allows the test to
>> > > set timeout for its completition. Any other call to the function
>> > > re-sets the timeout to the new value. The timeouts can be turned off
>> > > (usefull when debugging) by setting evironment variable
>> > > NO_TIMEOUTS.
>> >
>> > I would namespace the env var a bit, something like
>> WAYLAND_TESTS_NO_TIMEOUT.
>>
>
> This follows the naming of LEAK_CHECK_ENABLED. I'll rename it and then
> send follow-up patch that will
> rename LEAK_CHECK_ENABLED, so that it'll be consistent.
>

Sorry, the env var is named: NO_ASSERT_LEAK_CHECK


>
>
>> >
>> > >
>> > > Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
>> > > ---
>> > >  tests/test-runner.c | 46
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> > >  tests/test-runner.h |  7 +++++++
>> > >  2 files changed, 53 insertions(+)
>> > >
>> > > diff --git a/tests/test-runner.c b/tests/test-runner.c
>> > > index af80d2b..c4687b7 100644
>> > > --- a/tests/test-runner.c
>> > > +++ b/tests/test-runner.c
>> > > @@ -44,6 +44,11 @@ static void* (*sys_calloc)(size_t, size_t);
>> > >
>> > >  int leak_check_enabled;
>> > >
>> > > +/* when this var is set to 0, every call to test_set_timeout() is
>> > > + * suppressed - handy when debugging the test. Can be set by
>> > > + * NO_TIMEOUTS evnironment var */
>> > > +static int timeouts_enabled = 1;
>> > > +
>> > >  extern const struct test __start_test_section, __stop_test_section;
>> > >
>> > >  __attribute__ ((visibility("default"))) void *
>> > > @@ -110,14 +115,54 @@ usage(const char *name, int status)
>> > >         exit(status);
>> > >  }
>> > >
>> > > +void
>> > > +test_set_timeout(int to)
>> > > +{
>> > > +       int re;
>> > > +
>> > > +       if (!timeouts_enabled) {
>> > > +               fprintf(stderr, "Timeouts suppressed.\n");
>> > > +               return;
>> > > +       }
>> > > +
>> > > +       re = alarm(to);
>> >
>> > alarm() takes an 'unsigned', test_set_timeout should probably do the
>> > same, or anyway catch <0 timeouts.
>>
>
> Yes
>
>
>> >
>> > > +       fprintf(stderr, "Timeout was %sset", re ? "re-" : "");
>> > > +
>> > > +       if (to != 0)
>> > > +               fprintf(stderr, " to %d second from now.\n", to);
>> > > +       else
>> > > +               fprintf(stderr, " off.\n");
>> > > +}
>> > > +
>> > > +static void
>> > > +sigalrm_handler(int signum)
>> > > +{
>> > > +       fprintf(stderr, "Test timeouted.\n");
>> >
>> > nitpick: "timeouted"? Timed out sonds better to me. ;)
>>
>
> true
>
>
>> >
>> > > +       abort();
>> > > +}
>> > > +
>> > >  static void
>> > >  run_test(const struct test *t)
>> > >  {
>> > >         int cur_alloc = num_alloc;
>> > >         int cur_fds, num_fds;
>> > > +       struct sigaction sa;
>> > >
>> > >         cur_fds = count_open_fds();
>> > > +
>> > > +       if (timeouts_enabled) {
>> > > +               sa.sa_handler = sigalrm_handler;
>> > > +               sa.sa_flags = 0;
>> > > +               sigemptyset(&sa.sa_mask);
>> > > +               assert(sigaction(SIGALRM, &sa, NULL) == 0);
>> > > +       }
>> > > +
>> > >         t->run();
>> > > +
>> > > +       /* turn off timeout (if any) after test completition */
>> > > +       if (timeouts_enabled)
>> > > +               alarm(0);
>> > > +
>> > >         if (leak_check_enabled) {
>> > >                 if (cur_alloc != num_alloc) {
>> > >                         fprintf(stderr, "Memory leak detected in
>> test. "
>> > > @@ -189,6 +234,7 @@ int main(int argc, char *argv[])
>> > >         sys_free = dlsym(RTLD_NEXT, "free");
>> > >
>> > >         leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");
>> > > +       timeouts_enabled = !getenv("NO_TIMEOUTS");
>> > >
>> > >         if (argc == 2 && strcmp(argv[1], "--help") == 0)
>> > >                 usage(argv[0], EXIT_SUCCESS);
>> > > diff --git a/tests/test-runner.h b/tests/test-runner.h
>> > > index 707504c..522cb84 100644
>> > > --- a/tests/test-runner.h
>> > > +++ b/tests/test-runner.h
>> > > @@ -37,4 +37,11 @@ count_open_fds(void);
>> > >  void
>> > >  exec_fd_leak_check(int nr_expected_fds); /* never returns */
>> > >
>> > > +/*
>> > > + * set/reset the timeout in seconds. The timeout starts
>> > > + * at the point of invoking this function
>> > > + */
>> > > +void
>> > > +test_set_timeout(int);
>> > > +
>> > >  #endif
>>
>> Yup, I completely agree with Giulio here.
>>
>>
>> Thanks,
>> pq
>>
>
> Will fix it,
>
> Thanks,
> Marek
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20141112/61849fc2/attachment-0001.html>


More information about the wayland-devel mailing list