Change in openbsc[master]: tests: Mute stdout during db_prepare()

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu May 23 11:47:58 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/14140 )

Change subject: tests: Mute stdout during db_prepare()
......................................................................

tests: Mute stdout during db_prepare()

libdbi on debian unstable (at least)
outputs: "no table in statement !"
breaking the db_test.

Redirect stdout to /dev/null and restore
after the function completes.

Closes OS#4016

Change-Id: I8227aa8fa44d3237019db52dd0825f827797261b
---
M openbsc/tests/db/db_test.c
1 file changed, 21 insertions(+), 1 deletion(-)

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



diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c
index 755a6e9..5167185 100644
--- a/openbsc/tests/db/db_test.c
+++ b/openbsc/tests/db/db_test.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <inttypes.h>
+#include <unistd.h>
 
 static struct gsm_network dummy_net;
 static struct gsm_subscriber_group dummy_sgrp;
@@ -208,6 +209,8 @@
 
 	dummy_net.subscr_group = &dummy_sgrp;
 	dummy_sgrp.net         = &dummy_net;
+	int rc;
+	fpos_t pos;
 
 	if (db_init("hlr.sqlite3")) {
 		printf("DB: Failed to init database. Please check the option settings.\n");
@@ -215,10 +218,27 @@
 	}	 
 	printf("DB: Database initialized.\n");
 
-	if (db_prepare()) {
+	/* Muting stdout here because libdbi
+	 * may output noise on some platforms */
+
+	fflush(stdout);
+	fgetpos(stdout, &pos);
+	int old_stdout = dup(fileno(stdout));
+	freopen("/dev/null", "w", stdout);
+
+	rc = db_prepare();
+
+	fflush(stdout);
+	dup2(old_stdout, fileno(stdout));
+	close(old_stdout);
+	clearerr(stdout);
+	fsetpos(stdout, &pos);
+
+	if (rc) {
 		printf("DB: Failed to prepare database.\n");
 		return 1;
 	}
+
 	printf("DB: Database prepared.\n");
 
 	struct gsm_subscriber *alice = NULL;

-- 
To view, visit https://gerrit.osmocom.org/14140
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I8227aa8fa44d3237019db52dd0825f827797261b
Gerrit-Change-Number: 14140
Gerrit-PatchSet: 1
Gerrit-Owner: Keith Whyte <keith at rhizomatica.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190523/639e968b/attachment.html>


More information about the gerrit-log mailing list