aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-22 04:47:04 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-22 07:18:39 +0200
commit7b4d727ec5debc3d057686a0a3f0f5f14260a282 (patch)
treeee1cdd97de4ea939b4f8d440a6443e5c107e8ac3
parent8e2f7e87f4d854e697c40545326a16e50614dd5c (diff)
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
-rw-r--r--tests/timer/timer_test.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 6308113c..461d0603 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -59,6 +59,9 @@ struct test_timer {
/* 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 main_timer_fired(void *data)
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 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;
+ 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 @@ int main(int argc, char *argv[])
}
}
+ 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;
}