summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-08 16:41:37 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-08 17:39:49 +0100
commit9d911d59a022f8f109849cc1abdf1a2adb9c4e7f (patch)
tree6d8b1dd649f2e913190f0108ed67dd48fae00c55
parent89c725051db3c911694e72393aa13d3fc328c3e2 (diff)
db: Add testcase for the db migration.
-rw-r--r--openbsc/src/libmsc/db.c2
-rw-r--r--openbsc/tests/db/Makefile.am2
-rw-r--r--openbsc/tests/db/db_test.c34
-rw-r--r--openbsc/tests/db/db_test.err2
-rw-r--r--openbsc/tests/db/hlr.sqlite3bin0 -> 29696 bytes
-rw-r--r--openbsc/tests/testsuite.at4
6 files changed, 42 insertions, 2 deletions
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 3b9269143..f7f7c56a5 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -271,6 +271,8 @@ static int update_db_revision_3(void)
dbi_result result;
struct gsm_sms *sms;
+ LOGP(DDB, LOGL_NOTICE, "Going to migrate from revision 3\n");
+
result = dbi_conn_query(conn, "BEGIN EXCLUSIVE TRANSACTION");
if (!result) {
LOGP(DDB, LOGL_ERROR,
diff --git a/openbsc/tests/db/Makefile.am b/openbsc/tests/db/Makefile.am
index 26ea70345..647b51991 100644
--- a/openbsc/tests/db/Makefile.am
+++ b/openbsc/tests/db/Makefile.am
@@ -2,7 +2,7 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(LIBSMPP34_CFLAGS) $(COVERAGE_CFLAGS)
AM_LDFLAGS = $(COVERAGE_LDFLAGS)
-EXTRA_DIST = db_test.ok
+EXTRA_DIST = db_test.ok db_test.err hlr.sqlite3
noinst_PROGRAMS = db_test
diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c
index ba3fdfb4d..ef2e538d1 100644
--- a/openbsc/tests/db/db_test.c
+++ b/openbsc/tests/db/db_test.c
@@ -116,6 +116,39 @@ static void test_sms(void)
subscr_put(subscr);
}
+static void test_sms_migrate(void)
+{
+ struct gsm_subscriber *rcv_subscr;
+ struct gsm_sms *sms;
+ static const uint8_t user_data_1[] = {
+ 0x41, 0xf1, 0xd8, 0x05, 0x22, 0x96, 0xcd, 0x2e,
+ 0x90, 0xf1, 0xfd, 0x06, 0x00 };
+ static const uint8_t user_data_2[] = {
+ 0x41, 0xf1, 0xd8, 0x05, 0x22, 0x96, 0xcd, 0x2e,
+ 0xd0, 0xf1, 0xfd, 0x06, 0x00 };
+
+ rcv_subscr = db_get_subscriber(GSM_SUBSCRIBER_IMSI, "901010000001111");
+ rcv_subscr->net = &dummy_net;
+
+ sms = db_sms_get(&dummy_net, 1);
+ OSMO_ASSERT(sms->id == 1);
+ OSMO_ASSERT(sms->receiver == rcv_subscr);
+ OSMO_ASSERT(strcmp(sms->text, "Abc. Def. Foo") == 0);
+ OSMO_ASSERT(sms->user_data_len == ARRAY_SIZE(user_data_1));
+ OSMO_ASSERT(memcmp(sms->user_data, user_data_1, ARRAY_SIZE(user_data_1)) == 0);
+ sms_free(sms);
+
+ sms = db_sms_get(&dummy_net, 2);
+ OSMO_ASSERT(sms->id == 2);
+ OSMO_ASSERT(sms->receiver == rcv_subscr);
+ OSMO_ASSERT(strcmp(sms->text, "Abc. Def. Goo") == 0);
+ OSMO_ASSERT(sms->user_data_len == ARRAY_SIZE(user_data_2));
+ OSMO_ASSERT(memcmp(sms->user_data, user_data_2, ARRAY_SIZE(user_data_2)) == 0);
+ sms_free(sms);
+
+ subscr_put(rcv_subscr);
+}
+
int main()
{
printf("Testing subscriber database code.\n");
@@ -168,6 +201,7 @@ int main()
SUBSCR_PUT(alice_db);
test_sms();
+ test_sms_migrate();
db_fini();
diff --git a/openbsc/tests/db/db_test.err b/openbsc/tests/db/db_test.err
new file mode 100644
index 000000000..0a0f2f38c
--- /dev/null
+++ b/openbsc/tests/db/db_test.err
@@ -0,0 +1,2 @@
+<000d> db.c:274 Going to migrate from revision 3
+ \ No newline at end of file
diff --git a/openbsc/tests/db/hlr.sqlite3 b/openbsc/tests/db/hlr.sqlite3
new file mode 100644
index 000000000..e59dcdca3
--- /dev/null
+++ b/openbsc/tests/db/hlr.sqlite3
Binary files differ
diff --git a/openbsc/tests/testsuite.at b/openbsc/tests/testsuite.at
index b2c551859..4465b2528 100644
--- a/openbsc/tests/testsuite.at
+++ b/openbsc/tests/testsuite.at
@@ -10,7 +10,9 @@ AT_CLEANUP
AT_SETUP([db])
AT_KEYWORDS([db])
cat $abs_srcdir/db/db_test.ok > expout
-AT_CHECK([$abs_top_builddir/tests/db/db_test], [], [expout], [ignore])
+cat $abs_srcdir/db/db_test.err > experr
+cat $abs_srcdir/db/hlr.sqlite3 > hlr.sqlite3
+AT_CHECK([$abs_top_builddir/tests/db/db_test], [], [expout], [experr])
AT_CLEANUP
AT_SETUP([channel])