diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2011-11-13 17:40:09 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-11-14 13:35:42 +0100 |
commit | 72eb44cc51c2172a0880c8cef46f5873af180836 (patch) | |
tree | bbf26e4605f945d5fe0c0d827dfcada9ff24b9b2 /tests/timer | |
parent | 7a0ca16eec9e5215fcb8ba931adac00e57648455 (diff) |
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.
Diffstat (limited to 'tests/timer')
-rw-r--r-- | tests/timer/timer_test.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <stdio.h> #include <stdlib.h> +#include <signal.h> #include <getopt.h> #include <osmocom/core/talloc.h> @@ -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); |