Hi Holger,

On Sun, Nov 13, 2011 at 01:30:16AM +0100, Holger Hans Peter Freyther wrote:
> Hi Pablo, all
> 
> I have pushed GNU autotest[1] integration of libosmocore into the
> zecke/gnu-autotest branch and invoking make check will execute the testsuite.
> 
> The output looks like this:
> ## ------------------------------------- ##
> ## libosmocore 0.4.0.10-c015 test suite. ##
> ## ------------------------------------- ##
> 
> Regression tests.
> 
>   1: bits                                            ok
>   2: msgfile                                         ok
>   3: sms                                             ok
>   4: smscb                                           ok
>   5: timer                                           FAILED (testsuite.at:38)
>   6: ussd                                            FAILED (testsuite.at:44)
> 
> 
> GNU autotest will execute an external application and then can check the exit
> code, compare the stdout/stderr to a file. In this case the timer test fails
> as the test itself is randomized and does not always provide the same output.

Interesting, never played with this autotest stuff so far.

> Pablo if your time permits it would be nice if you could:
>       - Provide a cli option to make the test have less iterations (to make
>         make check run faster)

Patch attached for this.

>       - Provide a cli option to produce a repeatable output (e.g. by
>         omitting the expired output).

Can we tell the tool to compare stdout but to ignore stderr? If so, we
can display the repeatable output in stdout and the non-repeatable output
in stderr.

> What do you think? In some ways I think that executing the timer test as part
> of our regression tests makes sense but maybe specially on a loaded machine
> the test might be flaky...

Yes, with lots of timers, the expiration may not be done in time on
a loaded machine. If we can ignore the stderr output, we can put the
information about timers not expiring in time to stderr.
>From 7dd44f307a5459a2d83818617ebbfd98f7455ece Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <[email protected]>
Date: Sun, 13 Nov 2011 02:02:12 +0100
Subject: [PATCH] tests: timer: add parameter to select the number of steps

Holger likes having a parameter to set the number of steps in this
test. Now you can set it via `-s' option.

Signed-off-by: Pablo Neira Ayuso <[email protected]>
---
 tests/timer/timer_test.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index bcaafdb..a01a9e5 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <getopt.h>
 
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/timer.h>
@@ -60,6 +61,7 @@ struct test_timer {
 #define TIMER_PRES_SECS		0
 #define TIMER_PRES_USECS	10000
 
+static int timer_nsteps = MAIN_TIMER_NSTEPS;
 static unsigned int expired_timers = 0;
 static unsigned int total_timers = 0;
 static unsigned int too_late = 0;
@@ -70,7 +72,7 @@ static void main_timer_fired(void *data)
 	unsigned int add_in_this_step;
 	int i;
 
-	if (*step == MAIN_TIMER_NSTEPS) {
+	if (*step == timer_nsteps) {
 		printf("Main timer has finished, please, wait a bit for the "
 		       "final report.\n");
 		return;
@@ -134,11 +136,28 @@ static void secondary_timer_fired(void *data)
 	}
 }
 
-int main(int argc, char** argv)
+int main(int argc, char *argv[])
 {
+	int c;
+
+	while ((c = getopt_long(argc, argv, "s:", NULL, NULL)) != -1) {
+	switch(c) {
+		case 's':
+			timer_nsteps = atoi(optarg);
+			if (timer_nsteps <= 0) {
+				fprintf(stderr, "%s: steps must be > 0\n",
+					argv[0]);
+				exit(EXIT_FAILURE);
+			}
+			break;
+		default:
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	printf("Running timer test for %u steps, accepting imprecision "
 	       "of %u.%.6u seconds\n",
-		MAIN_TIMER_NSTEPS, TIMER_PRES_SECS, TIMER_PRES_USECS);
+		timer_nsteps, TIMER_PRES_SECS, TIMER_PRES_USECS);
 
 	osmo_timer_schedule(&main_timer, 1, 0);
 
-- 
1.7.2.5

Reply via email to