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.
This commit is contained in:
Pablo Neira Ayuso 2011-11-13 17:40:09 +01:00 committed by Holger Hans Peter Freyther
parent 7a0ca16eec
commit 72eb44cc51
1 changed files with 19 additions and 0 deletions

View File

@ -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);