summaryrefslogtreecommitdiffstats
path: root/tests/timer/timer_test.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2011-11-13 02:02:12 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-11-14 13:35:41 +0100
commitf141837ea8f9bf2b1526fa77cefb6d15af8de774 (patch)
tree3abb9bfcfa6d7485b7e03c29206a52c3233453fb /tests/timer/timer_test.c
parentf9eda7489b5afba9a0a5f9e1e623d61454b0e7e0 (diff)
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 <pablo@gnumonks.org>
Diffstat (limited to 'tests/timer/timer_test.c')
-rw-r--r--tests/timer/timer_test.c25
1 files changed, 22 insertions, 3 deletions
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 <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);