[MERGED] osmo-hlr[master]: db_test: don't verify SQLite issued error messages, they mig...

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
Tue Nov 21 18:42:30 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: db_test: don't verify SQLite issued error messages, they might change
......................................................................


db_test: don't verify SQLite issued error messages, they might change

A user on openbsc@ complained that with SQLite 3.8.2, the db_test fails with

  --- expected
  +++ stderr
  -DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
  +DDB (2067) abort at 35 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi

i.e. a trivial difference in the error message issued by SQLite.

For db_test, don't output any SQLite error messages: Add argument
enable_sqlite_logging, pass as true, except in db_test.c.
Remove the SQLite error messages from expected output.

(Note that there is a src/db_test.c program that's not of interest here, this
is about the tests/db/db_test.c)

Change-Id: I2513d71cc0072aef8d08f47d0a1959f311176229
---
M src/db.c
M src/db.h
M src/db_test.c
M src/hlr.c
M src/hlr_db_tool.c
M tests/db/db_test.c
M tests/db/db_test.err
7 files changed, 13 insertions(+), 14 deletions(-)

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



diff --git a/src/db.c b/src/db.c
index d16f8ec..cc06ee6 100644
--- a/src/db.c
+++ b/src/db.c
@@ -211,7 +211,7 @@
 	return 0;
 }
 
-struct db_context *db_open(void *ctx, const char *fname)
+struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logging)
 {
 	struct db_context *dbc = talloc_zero(ctx, struct db_context);
 	unsigned int i;
@@ -233,9 +233,11 @@
 			has_sqlite_config_sqllog = true;
 	}
 
-	rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
-	if (rc != SQLITE_OK)
-		LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
+	if (enable_sqlite_logging) {
+		rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
+		if (rc != SQLITE_OK)
+			LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
+	}
 
 	if (has_sqlite_config_sqllog) {
 		rc = sqlite3_config(SQLITE_CONFIG_SQLLOG, sql3_sql_log_cb, NULL);
diff --git a/src/db.h b/src/db.h
index fc8e511..92fdac4 100644
--- a/src/db.h
+++ b/src/db.h
@@ -38,7 +38,7 @@
 bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
 bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
 void db_close(struct db_context *dbc);
-struct db_context *db_open(void *ctx, const char *fname);
+struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite3_logging);
 
 #include <osmocom/crypt/auth.h>
 
diff --git a/src/db_test.c b/src/db_test.c
index 0e823f9..7891c90 100644
--- a/src/db_test.c
+++ b/src/db_test.c
@@ -62,7 +62,7 @@
 		exit(1);
 	}
 
-	g_hlr->dbc = db_open(NULL, "hlr.db");
+	g_hlr->dbc = db_open(NULL, "hlr.db", true);
 	if (!g_hlr->dbc) {
 		LOGP(DMAIN, LOGL_ERROR, "Error opening database\n");
 		exit(1);
diff --git a/src/hlr.c b/src/hlr.c
index 78a7055..861597a 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -460,7 +460,7 @@
 		exit(1);
 	}
 
-	g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file);
+	g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true);
 	if (!g_hlr->dbc) {
 		LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
 		exit(1);
diff --git a/src/hlr_db_tool.c b/src/hlr_db_tool.c
index d8a3584..318308c 100644
--- a/src/hlr_db_tool.c
+++ b/src/hlr_db_tool.c
@@ -409,7 +409,7 @@
 		exit(EXIT_FAILURE);
 	}
 
-	g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file);
+	g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file, true);
 	if (!g_hlr_db_tool_ctx->dbc) {
 		LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
 		exit(EXIT_FAILURE);
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index 389ed00..23b84cc 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -820,7 +820,9 @@
 
 	/* omit the SQLite version and compilation flags from test output */
 	log_set_log_level(osmo_stderr_target, LOGL_ERROR);
-	dbc = db_open(ctx, "db_test.db");
+	/* Disable SQLite logging so that we're not vulnerable on SQLite error messages changing across
+	 * library versions. */
+	dbc = db_open(ctx, "db_test.db", false);
 	log_set_log_level(osmo_stderr_target, 0);
 	OSMO_ASSERT(dbc);
 
diff --git a/tests/db/db_test.err b/tests/db/db_test.err
index 0b09583..f7acfec 100644
--- a/tests/db/db_test.err
+++ b/tests/db/db_test.err
@@ -28,7 +28,6 @@
 }
 
 db_subscr_create(dbc, imsi0) --> -EIO
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
 DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
@@ -38,11 +37,9 @@
 }
 
 db_subscr_create(dbc, imsi1) --> -EIO
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_create(dbc, imsi1) --> -EIO
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
@@ -52,11 +49,9 @@
 }
 
 db_subscr_create(dbc, imsi2) --> -EIO
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_create(dbc, imsi2) --> -EIO
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2513d71cc0072aef8d08f47d0a1959f311176229
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
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