From e1077526c22d0ffd5a8a29b1200f58750ac42677 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 23 May 2019 10:27:50 +0200 Subject: 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 --- openbsc/tests/db/db_test.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c index 755a6e9eb..516718522 100644 --- a/openbsc/tests/db/db_test.c +++ b/openbsc/tests/db/db_test.c @@ -30,6 +30,7 @@ #include #include #include +#include static struct gsm_network dummy_net; static struct gsm_subscriber_group dummy_sgrp; @@ -208,6 +209,8 @@ int main() 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 @@ int main() } 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; -- cgit v1.2.3