[PATCH] osmo-hlr[master]: add gsup_test to catch OS#3231

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri May 4 14:14:44 UTC 2018


Review at  https://gerrit.osmocom.org/8028

add gsup_test to catch OS#3231

Encode an Insert Subscr Data with is_ps == true to trigger the encoding bug
described in OS#3231, i.e. show that it is fixed.

Move osmo_gsup_addr_send() to a separate .c file, so that it can be overridden
in the regression test to just dump the msgb instead.

I used this test to reproduce issue OS#3231, and now that it's here we might as
well keep it, and possibly expand on it in the future.

Related: OS#3231
Change-Id: Id1453351758f3e1a9ff03bd99fefaf51886e77da
---
M configure.ac
M src/Makefile.am
A src/gsup_send.c
M src/luop.c
M src/luop.h
M tests/Makefile.am
A tests/gsup/Makefile.am
A tests/gsup/gsup_test.c
A tests/gsup/gsup_test.err
A tests/gsup/gsup_test.ok
M tests/testsuite.at
11 files changed, 191 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/28/8028/1

diff --git a/configure.ac b/configure.ac
index a632a1d..cedba45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,5 +104,6 @@
 	tests/auc/Makefile
 	tests/auc/gen_ts_55_205_test_sets/Makefile
 	tests/gsup_server/Makefile
+	tests/gsup/Makefile
 	tests/db/Makefile
 	)
diff --git a/src/Makefile.am b/src/Makefile.am
index 60fc479..ea5023d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,6 +52,7 @@
 	rand_urandom.c \
 	hlr_vty.c \
 	hlr_vty_subscr.c \
+	gsup_send.c \
 	$(NULL)
 
 osmo_hlr_LDADD = \
diff --git a/src/gsup_send.c b/src/gsup_send.c
new file mode 100644
index 0000000..b2c4e02
--- /dev/null
+++ b/src/gsup_send.c
@@ -0,0 +1,45 @@
+/* (C) 2018 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/* This is kept separate to be able to override the actual sending functions from unit tests. */
+
+#include <errno.h>
+
+#include "gsup_server.h"
+#include "gsup_router.h"
+
+#include <osmocom/core/logging.h>
+
+/* Send a msgb to a given address using routing */
+int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
+			const uint8_t *addr, size_t addrlen,
+			struct msgb *msg)
+{
+	struct osmo_gsup_conn *conn;
+
+	conn = gsup_route_find(gs, addr, addrlen);
+	if (!conn) {
+		DEBUGP(DLGSUP, "Cannot find route for addr %s\n", addr);
+		msgb_free(msg);
+		return -ENODEV;
+	}
+
+	return osmo_gsup_conn_send(conn, msg);
+}
+
diff --git a/src/luop.c b/src/luop.c
index 54c3884..edf4c51 100644
--- a/src/luop.c
+++ b/src/luop.c
@@ -165,23 +165,6 @@
 	luop->state = new_state;
 }
 
-/* Send a msgb to a given address using routing */
-int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
-			const uint8_t *addr, size_t addrlen,
-			struct msgb *msg)
-{
-	struct osmo_gsup_conn *conn;
-
-	conn = gsup_route_find(gs, addr, addrlen);
-	if (!conn) {
-		DEBUGP(DMAIN, "Cannot find route for addr %s\n", addr);
-		msgb_free(msg);
-		return -ENODEV;
-	}
-
-	return osmo_gsup_conn_send(conn, msg);
-}
-
 /*! Transmit UPD_LOC_ERROR and destroy lu_operation */
 void lu_op_tx_error(struct lu_operation *luop, enum gsm48_gmm_cause cause)
 {
diff --git a/src/luop.h b/src/luop.h
index 053a025..d690243 100644
--- a/src/luop.h
+++ b/src/luop.h
@@ -28,6 +28,7 @@
 #include <osmocom/gsm/gsup.h>
 
 #include "db.h"
+#include "gsup_server.h"
 
 #define CANCEL_TIMEOUT_SECS	30
 #define ISD_TIMEOUT_SECS	30
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f1cc710..58679ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,6 +2,7 @@
 	auc \
 	gsup_server \
 	db \
+	gsup \
 	$(NULL)
 
 # The `:;' works around a Bash 3.2 bug when the output is not writeable.
diff --git a/tests/gsup/Makefile.am b/tests/gsup/Makefile.am
new file mode 100644
index 0000000..7c33dbd
--- /dev/null
+++ b/tests/gsup/Makefile.am
@@ -0,0 +1,41 @@
+AM_CPPFLAGS = \
+	$(all_includes) \
+	-I$(top_srcdir)/src \
+	$(NULL)
+
+AM_CFLAGS = \
+	-Wall \
+	-ggdb3 \
+	$(LIBOSMOCORE_CFLAGS) \
+	$(LIBOSMOGSM_CFLAGS) \
+	$(LIBOSMOABIS_CFLAGS) \
+	$(NULL)
+
+AM_LDFLAGS = \
+	$(NULL)
+
+EXTRA_DIST = \
+	gsup_test.ok \
+	gsup_test.err \
+	$(NULL)
+
+noinst_PROGRAMS = \
+	gsup_test \
+	$(NULL)
+
+gsup_test_SOURCES = \
+	gsup_test.c \
+	$(NULL)
+
+gsup_test_LDADD = \
+	$(top_srcdir)/src/luop.c \
+	$(top_srcdir)/src/gsup_server.c \
+	$(top_srcdir)/src/gsup_router.c \
+	$(LIBOSMOCORE_LIBS) \
+	$(LIBOSMOGSM_LIBS) \
+	$(LIBOSMOABIS_LIBS) \
+	$(NULL)
+
+.PHONY: update_exp
+update_exp:
+	$(builddir)/gsup_test >"$(srcdir)/gsup_test.ok" 2>"$(srcdir)/gsup_test.err"
diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c
new file mode 100644
index 0000000..41865d2
--- /dev/null
+++ b/tests/gsup/gsup_test.c
@@ -0,0 +1,91 @@
+/* (C) 2018 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <string.h>
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/application.h>
+#include <osmocom/gsm/gsup.h>
+
+#include "logging.h"
+#include "luop.h"
+
+struct osmo_gsup_server;
+
+/* override osmo_gsup_addr_send() to not actually send anything. */
+int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
+			const uint8_t *addr, size_t addrlen,
+			struct msgb *msg)
+{
+	LOGP(DMAIN, LOGL_DEBUG, "%s\n", msgb_hexdump(msg));
+	msgb_free(msg);
+	return 0;
+}
+
+int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
+			  struct hlr_subscriber *subscr)
+{
+	return 0;
+}
+
+/* Verify that the internally allocated msgb is large enough */
+void test_gsup_tx_insert_subscr_data()
+{
+	struct lu_operation luop = {
+		.state = LU_S_LU_RECEIVED,
+		.subscr = {
+			.imsi = "123456789012345",
+			.msisdn = "987654321098765",
+			.nam_cs = true,
+			.nam_ps = true,
+		},
+		.is_ps = true,
+	};
+
+	lu_op_tx_insert_subscr_data(&luop);
+}
+
+const struct log_info_cat default_categories[] = {
+	[DMAIN] = {
+		.name = "DMAIN",
+		.description = "Main Program",
+		.enabled = 1, .loglevel = LOGL_DEBUG,
+	},
+};
+
+static struct log_info info = {
+	.cat = default_categories,
+	.num_cat = ARRAY_SIZE(default_categories),
+};
+
+int main(int argc, char **argv)
+{
+	void *ctx = talloc_named_const(NULL, 0, "gsup_test");
+	osmo_init_logging2(ctx, &info);
+	log_set_print_filename(osmo_stderr_target, 0);
+	log_set_print_timestamp(osmo_stderr_target, 0);
+	log_set_use_color(osmo_stderr_target, 0);
+	log_set_print_category(osmo_stderr_target, 1);
+
+	test_gsup_tx_insert_subscr_data();
+
+	printf("Done.\n");
+	return EXIT_SUCCESS;
+}
diff --git a/tests/gsup/gsup_test.err b/tests/gsup/gsup_test.err
new file mode 100644
index 0000000..d9d272a
--- /dev/null
+++ b/tests/gsup/gsup_test.err
@@ -0,0 +1,2 @@
+DMAIN 10 01 08 21 43 65 87 09 21 43 f5 08 09 08 89 67 45 23 01 89 67 f5 05 07 10 01 01 12 02 01 2a 
+DMAIN LU OP state change: LU RECEIVED -> ISD SENT
diff --git a/tests/gsup/gsup_test.ok b/tests/gsup/gsup_test.ok
new file mode 100644
index 0000000..619c561
--- /dev/null
+++ b/tests/gsup/gsup_test.ok
@@ -0,0 +1 @@
+Done.
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 74179e7..70ae7ae 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -15,6 +15,13 @@
 AT_CHECK([$abs_top_builddir/tests/auc/auc_ts_55_205_test_sets], [], [expout], [experr])
 AT_CLEANUP
 
+AT_SETUP([gsup])
+AT_KEYWORDS([gsup])
+cat $abs_srcdir/gsup/gsup_test.ok > expout
+cat $abs_srcdir/gsup/gsup_test.err > experr
+AT_CHECK([$abs_top_builddir/tests/gsup/gsup_test], [], [expout], [experr])
+AT_CLEANUP
+
 AT_SETUP([gsup_server])
 AT_KEYWORDS([gsup_server])
 cat $abs_srcdir/gsup_server/gsup_server_test.ok > expout

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1453351758f3e1a9ff03bd99fefaf51886e77da
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list