[MERGED] libosmocore[master]: timer_test: also report early finishes, report timing on error

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Sep 23 02:18:16 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: timer_test: also report early finishes, report timing on error
......................................................................


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
---
M tests/timer/timer_test.c
M tests/timer/timer_test.ok
2 files changed, 19 insertions(+), 5 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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 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 @@
 
 	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);
 	}
 
diff --git a/tests/timer/timer_test.ok b/tests/timer/timer_test.ok
index 1bb382e..7c00000 100644
--- a/tests/timer/timer_test.ok
+++ b/tests/timer/timer_test.ok
@@ -1,2 +1,2 @@
 Running timer test for 5 steps, accepting imprecision of 0.020000 seconds
-test over: added=31 expired=31 too_late=0 
+test over: added=31 expired=31 too_soon=0 too_late=0

-- 
To view, visit https://gerrit.osmocom.org/883
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id3942637d77a28b5092ffffcc3e6d9d67c2b8e68
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list