From f9eda7489b5afba9a0a5f9e1e623d61454b0e7e0 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 13 Nov 2011 01:02:54 +0100 Subject: tests: Use GNU autotest to execute our tests and compare textual output The output of make check is looking like this now: 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) --- tests/timer/timer_test.ok | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/timer/timer_test.ok (limited to 'tests/timer') diff --git a/tests/timer/timer_test.ok b/tests/timer/timer_test.ok new file mode 100644 index 00000000..b1792f18 --- /dev/null +++ b/tests/timer/timer_test.ok @@ -0,0 +1,19 @@ +Running timer test for 16 steps, accepting imprecision of 0.010000 seconds +added 1 timers in step 0 (expired=0) +added 2 timers in step 1 (expired=0) +added 4 timers in step 2 (expired=0) +added 8 timers in step 3 (expired=0) +added 16 timers in step 4 (expired=1) +added 32 timers in step 5 (expired=4) +added 64 timers in step 6 (expired=33) +added 128 timers in step 7 (expired=87) +added 256 timers in step 8 (expired=183) +added 512 timers in step 9 (expired=466) +added 1024 timers in step 10 (expired=970) +added 2048 timers in step 11 (expired=1968) +added 4096 timers in step 12 (expired=3994) +added 8192 timers in step 13 (expired=8035) +added 16384 timers in step 14 (expired=16324) +added 32768 timers in step 15 (expired=32641) +Main timer has finished, please, wait a bit for the final report. +test over: added=65535 expired=65535 too_late=0 -- cgit v1.2.3 From f141837ea8f9bf2b1526fa77cefb6d15af8de774 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 13 Nov 2011 02:02:12 +0100 Subject: 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 --- tests/timer/timer_test.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'tests/timer') diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index bcaafdb2..a01a9e5c 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -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); -- cgit v1.2.3 From 7a0ca16eec9e5215fcb8ba931adac00e57648455 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 13 Nov 2011 17:22:33 +0100 Subject: tests: timer: use stderr for non-repeatable output This makes happy gnu-autotest for the timer test. We may still may fail if we run the test on a very heavy loaded system, but given the amount of timers that we using for the automatic test (only 32), this seems very unlikely to me. --- tests/timer/timer_test.c | 17 +++++++++-------- tests/timer/timer_test.ok | 21 ++------------------- 2 files changed, 11 insertions(+), 27 deletions(-) (limited to 'tests/timer') diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index a01a9e5c..72c07a9a 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -73,8 +73,8 @@ static void main_timer_fired(void *data) int i; if (*step == timer_nsteps) { - printf("Main timer has finished, please, wait a bit for the " - "final report.\n"); + fprintf(stderr, "Main timer has finished, please, " + "wait a bit for the final report.\n"); return; } /* add 2^step pair of timers per step. */ @@ -96,7 +96,7 @@ static void main_timer_fired(void *data) osmo_timer_schedule(&v->timer, seconds, 0); llist_add(&v->head, &timer_test_list); } - printf("added %d timers in step %u (expired=%u)\n", + fprintf(stderr, "added %d timers in step %u (expired=%u)\n", add_in_this_step, *step, expired_timers); total_timers += add_in_this_step; osmo_timer_schedule(&main_timer, TIME_BETWEEN_STEPS, 0); @@ -112,7 +112,8 @@ static void secondary_timer_fired(void *data) timersub(¤t, &v->stop, &res); if (timercmp(&res, &precision, >)) { - printf("ERROR: timer %p has expired too late!\n", v->timer); + fprintf(stderr, "ERROR: timer %p has expired too late!\n", + v->timer); too_late++; } @@ -120,7 +121,7 @@ static void secondary_timer_fired(void *data) talloc_free(data); expired_timers++; if (expired_timers == total_timers) { - printf("test over: added=%u expired=%u too_late=%u \n", + fprintf(stdout, "test over: added=%u expired=%u too_late=%u \n", total_timers, expired_timers, too_late); exit(EXIT_SUCCESS); } @@ -155,8 +156,8 @@ int main(int argc, char *argv[]) } } - printf("Running timer test for %u steps, accepting imprecision " - "of %u.%.6u seconds\n", + fprintf(stdout, "Running timer test for %u steps, accepting " + "imprecision of %u.%.6u seconds\n", timer_nsteps, TIMER_PRES_SECS, TIMER_PRES_USECS); osmo_timer_schedule(&main_timer, 1, 0); @@ -166,6 +167,6 @@ int main(int argc, char *argv[]) osmo_select_main(0); } #else - printf("Select not supported on this platform!\n"); + fprintf(stdout, "Select not supported on this platform!\n"); #endif } diff --git a/tests/timer/timer_test.ok b/tests/timer/timer_test.ok index b1792f18..b4e0e118 100644 --- a/tests/timer/timer_test.ok +++ b/tests/timer/timer_test.ok @@ -1,19 +1,2 @@ -Running timer test for 16 steps, accepting imprecision of 0.010000 seconds -added 1 timers in step 0 (expired=0) -added 2 timers in step 1 (expired=0) -added 4 timers in step 2 (expired=0) -added 8 timers in step 3 (expired=0) -added 16 timers in step 4 (expired=1) -added 32 timers in step 5 (expired=4) -added 64 timers in step 6 (expired=33) -added 128 timers in step 7 (expired=87) -added 256 timers in step 8 (expired=183) -added 512 timers in step 9 (expired=466) -added 1024 timers in step 10 (expired=970) -added 2048 timers in step 11 (expired=1968) -added 4096 timers in step 12 (expired=3994) -added 8192 timers in step 13 (expired=8035) -added 16384 timers in step 14 (expired=16324) -added 32768 timers in step 15 (expired=32641) -Main timer has finished, please, wait a bit for the final report. -test over: added=65535 expired=65535 too_late=0 +Running timer test for 5 steps, accepting imprecision of 0.010000 seconds +test over: added=31 expired=31 too_late=0 -- cgit v1.2.3 From 72eb44cc51c2172a0880c8cef46f5873af180836 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 13 Nov 2011 17:40:09 +0100 Subject: 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. --- tests/timer/timer_test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/timer') diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index 72c07a9a..3775151c 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -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); -- cgit v1.2.3