From 72eb44cc51c2172a0880c8cef46f5873af180836 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 13 Nov 2011 17:40:09 +0100 Subject: tests: timer: set maximum wait time to obtain test results If the timer test takes more than 2 * (number of steps + 10), we abort the test. This calculation is based on the maximum timeout randomly set (10 seconds) plus the number of steps (some existing timers may be reset in each step). We double this to have some extra grace time to finish. --- tests/timer/timer_test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/timer') diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index 72c07a9a..3775151c 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -137,10 +138,22 @@ static void secondary_timer_fired(void *data) } } +static void alarm_handler(int signum) +{ + fprintf(stderr, "ERROR: We took too long to run the timer test, " + "something seems broken, aborting.\n"); + exit(EXIT_FAILURE); +} + int main(int argc, char *argv[]) { int c; + if (signal(SIGALRM, alarm_handler) == SIG_ERR) { + perror("cannot register signal handler"); + exit(EXIT_FAILURE); + } + while ((c = getopt_long(argc, argv, "s:", NULL, NULL)) != -1) { switch(c) { case 's': @@ -162,6 +175,12 @@ int main(int argc, char *argv[]) osmo_timer_schedule(&main_timer, 1, 0); + /* if the test takes too long, we may consider that the timer scheduler + * has hung. We set some maximum wait time which is the double of the + * maximum timeout randomly set (10 seconds, worst case) plus the + * number of steps (since some of them are reset each step). */ + alarm(2 * (10 + timer_nsteps)); + #ifdef HAVE_SYS_SELECT_H while (1) { osmo_select_main(0); -- cgit v1.2.3