neels has submitted this change. (
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36892?usp=email )
Change subject: add umts_cell_id_test.c
......................................................................
add umts_cell_id_test.c
Prepare for adding proper mnc_3_digits support to struct umts_cell_id.
Show current behavior of the umts_cell_id <-> string conversions.
Show two expected errors in umts_cell_id_test.ok: the three-digit MNC
with leading zeros is lost (because the g_hnbgw->config.plmn has
mnc_3_digits == false).
The expected errors will be fixed in upcoming patch
Id9a91c80cd2745424a916aef4736993bb7cd8ba0
Related: SYS#6773
Change-Id: Ibbb61a2c53a11dea794f451d3074bc9ba50862fe
---
M configure.ac
M tests/Makefile.am
M tests/testsuite.at
A tests/umts_cell_id/Makefile.am
A tests/umts_cell_id/umts_cell_id_test.c
A tests/umts_cell_id/umts_cell_id_test.ok
6 files changed, 252 insertions(+), 1 deletion(-)
Approvals:
fixeria: Looks good to me, approved
osmith: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/configure.ac b/configure.ac
index 48842db..c81d2b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,6 +240,7 @@
tests/Makefile
tests/atlocal
tests/ranap_rab_ass/Makefile
+ tests/umts_cell_id/Makefile
doc/Makefile
doc/examples/Makefile
doc/manuals/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index df9e5a9..a4dcf4c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,6 @@
SUBDIRS = \
ranap_rab_ass \
+ umts_cell_id \
$(NULL)
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 84d85cf..c54521a 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -5,4 +5,10 @@
AT_KEYWORDS([ranap_rab_ass])
cat $abs_srcdir/ranap_rab_ass/ranap_rab_ass_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/ranap_rab_ass/ranap_rab_ass_test], [0], [expout],
[ignore])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
+
+AT_SETUP([umts_cell_id])
+AT_KEYWORDS([umts_cell_id])
+cat $abs_srcdir/umts_cell_id/umts_cell_id_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/umts_cell_id/umts_cell_id_test], [0], [expout],
[ignore])
+AT_CLEANUP
diff --git a/tests/umts_cell_id/Makefile.am b/tests/umts_cell_id/Makefile.am
new file mode 100644
index 0000000..d32fa25
--- /dev/null
+++ b/tests/umts_cell_id/Makefile.am
@@ -0,0 +1,38 @@
+AM_CPPFLAGS = \
+ $(all_includes) \
+ -I$(top_srcdir)/include \
+ $(NULL)
+
+AM_CFLAGS = \
+ -Wall \
+ -ggdb3 \
+ $(LIBASN1C_CFLAGS) \
+ $(LIBOSMOCORE_CFLAGS) \
+ $(LIBOSMOVTY_CFLAGS) \
+ $(LIBOSMORANAP_CFLAGS) \
+ $(LIBOSMOSIGTRAN_CFLAGS) \
+ $(LIBOSMOMGCPCLIENT_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ $(NULL)
+
+AM_LDFLAGS = -no-install
+
+EXTRA_DIST = \
+ umts_cell_id_test.ok \
+ $(NULL)
+
+check_PROGRAMS = \
+ umts_cell_id_test \
+ $(NULL)
+
+umts_cell_id_test_SOURCES = \
+ umts_cell_id_test.c \
+ $(NULL)
+
+umts_cell_id_test_LDADD = \
+ $(top_builddir)/src/osmo-hnbgw/libhnbgw.la \
+ $(NULL)
+
+.PHONY: update_exp
+update_exp:
+ $(builddir)/umts_cell_id_test >$(srcdir)/umts_cell_id_test.ok
diff --git a/tests/umts_cell_id/umts_cell_id_test.c
b/tests/umts_cell_id/umts_cell_id_test.c
new file mode 100644
index 0000000..e9183c4
--- /dev/null
+++ b/tests/umts_cell_id/umts_cell_id_test.c
@@ -0,0 +1,151 @@
+#include <stdio.h>
+
+#include <osmocom/hnbgw/hnbgw.h>
+
+struct test {
+ const char *id_str;
+ int expect_rc;
+ struct umts_cell_id id;
+};
+
+struct test tests[] = {
+ {
+ .id_str = "001-01-L1-R1-S1-C1",
+ .id = {
+ .mcc = 1,
+ .mnc = 1,
+ .lac = 1,
+ .rac = 1,
+ .sac = 1,
+ .cid = 1,
+ },
+ },
+
+ /* ensure that a 3-digit MNC with leading zeroes is kept separate from two-digit MNC */
+ {
+ .id_str = "001-001-L1-R1-S1-C1",
+ .id = {
+ .mcc = 1,
+ .mnc = 1,
+ .lac = 1,
+ .rac = 1,
+ .sac = 1,
+ .cid = 1,
+ },
+ },
+ {
+ .id_str = "001-099-L1-R1-S1-C1",
+ .id = {
+ .mcc = 1,
+ .mnc = 99,
+ .lac = 1,
+ .rac = 1,
+ .sac = 1,
+ .cid = 1,
+ },
+ },
+ {
+ .id_str = "001-99-L1-R1-S1-C1",
+ .id = {
+ .mcc = 1,
+ .mnc = 99,
+ .lac = 1,
+ .rac = 1,
+ .sac = 1,
+ .cid = 1,
+ },
+ },
+
+ {
+ .id_str = "999-999-L65534-R65535-S65535-C268435455",
+ .id = {
+ .mcc = 999,
+ .mnc = 999,
+ .lac = 65534,
+ .rac = 65535,
+ .sac = 65535,
+ .cid = (1 << 28) - 1,
+ },
+ },
+
+ {
+ .id_str = "1000-001-L1-R1-S1-C1",
+ .expect_rc = -EINVAL,
+ },
+ {
+ .id_str = "001-001-L65535-R1-S1-C1",
+ .expect_rc = -EINVAL,
+ },
+ /* TODO? There is no bounds checking on RAC and SAC.
+ {
+ .id_str = "001-001-L1-R65536-S1-C1",
+ .expect_rc = -EINVAL,
+ },
+ {
+ .id_str = "001-001-L1-R1-S65536-C1",
+ .expect_rc = -EINVAL,
+ },
+ */
+ {
+ .id_str = "001-001-L1-R1-S1-C268435456",
+ .expect_rc = -EINVAL,
+ },
+};
+
+int main(void)
+{
+ struct hnbgw hnbgw_dummy = {};
+ struct test *t;
+
+ /* umts_cell_id_to_str() accesses g_hnbgw->config.plmn.mnc_3_digits, so make sure it
is valid mem: */
+ g_hnbgw = &hnbgw_dummy;
+
+ for (t = tests; (t - tests) < ARRAY_SIZE(tests); t++) {
+ int rc;
+ struct umts_cell_id parsed;
+ char to_str[128] = {};
+
+ printf("\"%s\"\n", t->id_str);
+
+ memset(&parsed, 0x2b, sizeof(parsed));
+ rc = umts_cell_id_from_str(&parsed, t->id_str);
+ if (rc != t->expect_rc) {
+ printf(" ERROR: umts_cell_id_from_str(): expected rc == %d, got %d\n",
+ t->expect_rc, rc);
+ continue;
+ }
+
+ if (rc) {
+ if (rc == t->expect_rc)
+ printf(" expected rc != 0: ok\n");
+ continue;
+ }
+ printf(" -> umts_cell_id_from_str(): ok\n");
+
+ rc = umts_cell_id_to_str_buf(to_str, sizeof(to_str), &parsed);
+ if (rc <= 0) {
+ printf(" ERROR: umts_cell_id_to_str_buf(): expected rc == 0, got %d\n",
rc);
+ continue;
+ } else {
+ printf(" -> umts_cell_id_to_str_buf(): ok\n");
+
+ if (strcmp(t->id_str, to_str))
+ printf(" ERROR: conversion to umts_cell_id and back to string doesn't
return the original string\n");
+ printf(" -> \"%s\"\n", to_str);
+ }
+
+ if (umts_cell_id_equal(&t->id, &parsed)) {
+ printf(" umts_cell_id_equal(expected, parsed): ok\n");
+ } else {
+ char to_str_expect[128] = {};
+ umts_cell_id_to_str_buf(to_str_expect, sizeof(to_str_expect), &t->id);
+ printf(" ERROR: umts_cell_id_equal(expected, parsed) == false\n");
+ printf(" expected %s\n", to_str_expect);
+ printf(" got %s\n", to_str);
+ printf(" expected %s\n", osmo_hexdump((void *)&t->id,
sizeof(t->id)));
+ printf(" got %s\n", osmo_hexdump((void *)&parsed,
sizeof(t->id)));
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/umts_cell_id/umts_cell_id_test.ok
b/tests/umts_cell_id/umts_cell_id_test.ok
new file mode 100644
index 0000000..457f78a
--- /dev/null
+++ b/tests/umts_cell_id/umts_cell_id_test.ok
@@ -0,0 +1,33 @@
+"001-01-L1-R1-S1-C1"
+ -> umts_cell_id_from_str(): ok
+ -> umts_cell_id_to_str_buf(): ok
+ -> "001-01-L1-R1-S1-C1"
+ umts_cell_id_equal(expected, parsed): ok
+"001-001-L1-R1-S1-C1"
+ -> umts_cell_id_from_str(): ok
+ -> umts_cell_id_to_str_buf(): ok
+ ERROR: conversion to umts_cell_id and back to string doesn't return the original
string
+ -> "001-01-L1-R1-S1-C1"
+ umts_cell_id_equal(expected, parsed): ok
+"001-099-L1-R1-S1-C1"
+ -> umts_cell_id_from_str(): ok
+ -> umts_cell_id_to_str_buf(): ok
+ ERROR: conversion to umts_cell_id and back to string doesn't return the original
string
+ -> "001-99-L1-R1-S1-C1"
+ umts_cell_id_equal(expected, parsed): ok
+"001-99-L1-R1-S1-C1"
+ -> umts_cell_id_from_str(): ok
+ -> umts_cell_id_to_str_buf(): ok
+ -> "001-99-L1-R1-S1-C1"
+ umts_cell_id_equal(expected, parsed): ok
+"999-999-L65534-R65535-S65535-C268435455"
+ -> umts_cell_id_from_str(): ok
+ -> umts_cell_id_to_str_buf(): ok
+ -> "999-999-L65534-R65535-S65535-C268435455"
+ umts_cell_id_equal(expected, parsed): ok
+"1000-001-L1-R1-S1-C1"
+ expected rc != 0: ok
+"001-001-L65535-R1-S1-C1"
+ expected rc != 0: ok
+"001-001-L1-R1-S1-C268435456"
+ expected rc != 0: ok
--
To view, visit
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36892?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Ibbb61a2c53a11dea794f451d3074bc9ba50862fe
Gerrit-Change-Number: 36892
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged