aboutsummaryrefslogtreecommitdiffstats
path: root/tests/timer/timer_test.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-22 04:23:34 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-22 07:18:39 +0200
commit9c9a04705ff431c1e10bf40f2e964a43360441ac (patch)
tree7fe17b5a1e65f97a7bd6d8d211975213439f2ea6 /tests/timer/timer_test.c
parent633a0e76a2fbb31ce6dd4dadb35313aed3aa385c (diff)
timer_test: also report early finishes, report timing on error
When a timer was late, show the timing details. Also count whether timers fired early, for completeness' sake. Change-Id: Id3942637d77a28b5092ffffcc3e6d9d67c2b8e68
Diffstat (limited to 'tests/timer/timer_test.c')
-rw-r--r--tests/timer/timer_test.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 4981fd5..c576a04 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -67,6 +67,7 @@ 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;
+static unsigned int too_soon = 0;
static void main_timer_fired(void *data)
{
@@ -115,17 +116,30 @@ static void secondary_timer_fired(void *data)
timersub(&current, &v->stop, &res);
if (timercmp(&res, &precision, >)) {
- fprintf(stderr, "ERROR: timer %p has expired too late!\n",
- &v->timer);
+ fprintf(stderr, "ERROR: timer has expired too late:"
+ " wanted %d.%06d now %d.%06d diff %d.%06d\n",
+ (int)v->stop.tv_sec, (int)v->stop.tv_usec,
+ (int)current.tv_sec, (int)current.tv_usec,
+ (int)res.tv_sec, (int)res.tv_usec
+ );
too_late++;
}
+ else if (timercmp(&current, &v->stop, <)) {
+ fprintf(stderr, "ERROR: timer has expired too soon:"
+ " wanted %d.%06d now %d.%06d diff %d.%06d\n",
+ (int)v->stop.tv_sec, (int)v->stop.tv_usec,
+ (int)current.tv_sec, (int)current.tv_usec,
+ (int)res.tv_sec, (int)res.tv_usec
+ );
+ too_soon++;
+ }
llist_del(&v->head);
talloc_free(data);
expired_timers++;
if (expired_timers == total_timers) {
- fprintf(stdout, "test over: added=%u expired=%u too_late=%u \n",
- total_timers, expired_timers, too_late);
+ fprintf(stdout, "test over: added=%u expired=%u too_soon=%u too_late=%u\n",
+ total_timers, expired_timers, too_soon, too_late);
exit(EXIT_SUCCESS);
}