[PATCH] libosmocore[master]: timer_test: do not use real time: deterministic and faster

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/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Sep 22 05:18:38 UTC 2016


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/886

to look at the new patch set (#3).

timer_test: do not use real time: deterministic and faster

Use osmo_gettimeofday_override* to decouple the timer test from real time. No
longer call osmo_select_main(), since select() actually waits for real time.

This reduces the timer_test to the osmo_timer_* logic and excludes the real
time and osmo_timers_nearest() accuracy testing with actual waiting involved.
This may be seen as a loss, but is more fit for a test suite.

The main point here is to get deterministic results in jenkins, so that we
don't have to retrigger jobs based on timing failures; added bonus is that the
test runs much faster now.

Change-Id: Ic5649512df86dd17070daa2f314159eafaf8feb8
---
M tests/timer/timer_test.c
1 file changed, 15 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/86/886/3

diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 6308113..461d060 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -59,6 +59,9 @@
 /* time between two steps, in secs. */
 #define TIME_BETWEEN_STEPS	1
 
+/* how much time elapses between checks, in microsecs */
+#define TIME_BETWEEN_TIMER_CHECKS 423210
+
 static int timer_nsteps = MAIN_TIMER_NSTEPS;
 static unsigned int expired_timers = 0;
 static unsigned int total_timers = 0;
@@ -106,7 +109,8 @@
 static void secondary_timer_fired(void *data)
 {
 	struct test_timer *v = data, *this, *tmp;
-	struct timeval current, res, precision = { 1, 0 };
+	struct timeval current, res;
+	struct timeval precision = { 0, TIME_BETWEEN_TIMER_CHECKS + 1};
 
 	osmo_gettimeofday(&current, NULL);
 
@@ -150,21 +154,12 @@
 	}
 }
 
-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;
+	int steps;
 
-	if (signal(SIGALRM, alarm_handler) == SIG_ERR) {
-		perror("cannot register signal handler");
-		exit(EXIT_FAILURE);
-	}
+	osmo_gettimeofday_override = true;
 
 	while ((c = getopt_long(argc, argv, "s:", NULL, NULL)) != -1) {
 	switch(c) {
@@ -181,21 +176,21 @@
 		}
 	}
 
+	steps = ((MAIN_TIMER_NSTEPS * TIME_BETWEEN_STEPS + 20) * 1e6)
+		/ TIME_BETWEEN_TIMER_CHECKS;
+
 	fprintf(stdout, "Running timer test for %u steps\n", timer_nsteps);
 
 	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);
+	while (steps--) {
+		osmo_timers_prepare();
+		osmo_timers_update();
+		osmo_gettimeofday_override_add(0, TIME_BETWEEN_TIMER_CHECKS);
 	}
 #else
 	fprintf(stdout, "Select not supported on this platform!\n");
 #endif
+	return 0;
 }

-- 
To view, visit https://gerrit.osmocom.org/886
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ic5649512df86dd17070daa2f314159eafaf8feb8
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list