diff options
author | Keith <keith@rhizomatica.org> | 2019-05-23 10:27:50 +0200 |
---|---|---|
committer | Keith <keith@rhizomatica.org> | 2019-05-23 10:30:36 +0200 |
commit | e1077526c22d0ffd5a8a29b1200f58750ac42677 (patch) | |
tree | 99a1cdcab1b67e1ab10d6bc357bcca4a9f46a56e | |
parent | c44cbbf839dcff3f7b83ca3a051854e52fe88e40 (diff) |
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
-rw-r--r-- | openbsc/tests/db/db_test.c | 22 |
1 files changed, 21 insertions, 1 deletions
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 <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 @@ 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; |