[PATCH 2/2] tests: timer: set maximum wait time to obtain test results

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Pablo Neira Ayuso pablo at gnumonks.org
Sun Nov 13 16:40:09 UTC 2011


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 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 72c07a9..3775151 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);
-- 
1.7.2.5


--fdj2RfSjLxBAspz7--




More information about the OpenBSC mailing list