[PATCH] libosmocore[master]: timer_test: redirect some output from stderr to stdout

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Sep 22 04:33:08 UTC 2016


Review at  https://gerrit.osmocom.org/888

timer_test: redirect some output from stderr to stdout

This way we can check the output in timer_test.ok.

Change-Id: Ia3bba1c650be3558d370e0f59d4ee7f36ef97506
---
M tests/timer/timer_test.c
M tests/timer/timer_test.ok
2 files changed, 24 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/888/1

diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index d8e1ec9..12caecf 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -75,8 +75,8 @@
 	int i;
 
 	if (*step == timer_nsteps) {
-		fprintf(stderr, "Main timer has finished, please, "
-				"wait a bit for the final report.\n");
+		printf("Main timer has finished, please, "
+		       "wait a bit for the final report.\n");
 		return;
 	}
 	/* add 2^step pair of timers per step. */
@@ -87,7 +87,7 @@
 
 		v = talloc_zero(NULL, struct test_timer);
 		if (v == NULL) {
-			fprintf(stderr, "timer_test: OOM!\n");
+			printf("timer_test: OOM!\n");
 			return;
 		}
 		osmo_gettimeofday(&v->start, NULL);
@@ -99,7 +99,7 @@
 		osmo_timer_schedule(&v->timer, seconds, 0);
 		llist_add(&v->head, &timer_test_list);
 	}
-	fprintf(stderr, "added %d timers in step %u (expired=%u)\n",
+	printf("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);
@@ -117,21 +117,19 @@
 
 	timersub(&current, &v->stop, &res);
 	if (timercmp(&res, &precision, >)) {
-		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
-		       );
+		printf("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
-		       );
+		printf("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++;
 	}
 
@@ -139,8 +137,8 @@
 	talloc_free(data);
 	expired_timers++;
 	if (expired_timers == total_timers) {
-		fprintf(stdout, "test over: added=%u expired=%u too_soon=%u too_late=%u\n",
-			total_timers, expired_timers, too_soon, too_late);
+		printf("test over: added=%u expired=%u too_soon=%u too_late=%u\n",
+		       total_timers, expired_timers, too_soon, too_late);
 		exit(EXIT_SUCCESS);
 	}
 
@@ -182,7 +180,7 @@
 	steps = ((MAIN_TIMER_NSTEPS * TIME_BETWEEN_STEPS + 20) * 1e6)
 		/ TIME_BETWEEN_TIMER_CHECKS;
 
-	fprintf(stdout, "Running timer test for %u steps\n", timer_nsteps);
+	printf("Running timer test for %u steps\n", timer_nsteps);
 
 	osmo_timer_schedule(&main_timer, 1, 0);
 
@@ -193,7 +191,7 @@
 		osmo_gettimeofday_override_add(0, TIME_BETWEEN_TIMER_CHECKS);
 	}
 #else
-	fprintf(stdout, "Select not supported on this platform!\n");
+	printf("Select not supported on this platform!\n");
 #endif
 	return 0;
 }
diff --git a/tests/timer/timer_test.ok b/tests/timer/timer_test.ok
index 22b93aa..7617bc3 100644
--- a/tests/timer/timer_test.ok
+++ b/tests/timer/timer_test.ok
@@ -1,2 +1,8 @@
 Running timer test for 5 steps
+added 1 timers in step 0 (expired=0)
+added 2 timers in step 1 (expired=0)
+added 4 timers in step 2 (expired=1)
+added 8 timers in step 3 (expired=4)
+added 16 timers in step 4 (expired=7)
+Main timer has finished, please, wait a bit for the final report.
 test over: added=31 expired=31 too_soon=0 too_late=0

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3bba1c650be3558d370e0f59d4ee7f36ef97506
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list