aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-11-22 14:59:46 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-12-19 16:37:55 +0100
commitbce5675e5fa1eb4bcbe0dd24d503456eaeb58a0d (patch)
tree338b2407a776d4112de78486892b281407e06a3e /openbsc/tests
parentc751cf92cbc25a5cfca8041ef3fdcc16ed5865ad (diff)
abis: Create a routine that can parse all SW Descriptions of a SW Config
Be able to parse the entire SW Config IE. Parse the SW Descruption into a struct provided by the caller.
Diffstat (limited to 'openbsc/tests')
-rw-r--r--openbsc/tests/Makefile.am2
-rw-r--r--openbsc/tests/abis/Makefile.am17
-rw-r--r--openbsc/tests/abis/abis_test.c118
-rw-r--r--openbsc/tests/abis/abis_test.ok9
-rw-r--r--openbsc/tests/testsuite.at6
5 files changed, 151 insertions, 1 deletions
diff --git a/openbsc/tests/Makefile.am b/openbsc/tests/Makefile.am
index cede8e824..7ea4cff67 100644
--- a/openbsc/tests/Makefile.am
+++ b/openbsc/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = gsm0408 db channel mgcp gprs si
+SUBDIRS = gsm0408 db channel mgcp gprs si abis
if BUILD_NAT
SUBDIRS += bsc-nat
diff --git a/openbsc/tests/abis/Makefile.am b/openbsc/tests/abis/Makefile.am
new file mode 100644
index 000000000..3255ecf55
--- /dev/null
+++ b/openbsc/tests/abis/Makefile.am
@@ -0,0 +1,17 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOABIS_CFLAGS) \
+ $(LIBOSMOGSM_CFLAGS) $(COVERAGE_CFLAGS)
+
+EXTRA_DIST = abis_test.ok
+
+noinst_PROGRAMS = abis_test
+
+abis_test_SOURCES = abis_test.c
+
+abis_test_LDADD = \
+ $(top_builddir)/src/libbsc/libbsc.a \
+ $(top_builddir)/src/libcommon/libcommon.a \
+ $(top_builddir)/src/libbsc/libbsc.a \
+ $(top_builddir)/src/libtrau/libtrau.a \
+ $(LIBOSMOCORE_LIBS) $(LIBOSMOABIS_LIBS) \
+ $(LIBOSMOGSM_LIBS)
diff --git a/openbsc/tests/abis/abis_test.c b/openbsc/tests/abis/abis_test.c
new file mode 100644
index 000000000..a2f6a05c2
--- /dev/null
+++ b/openbsc/tests/abis/abis_test.c
@@ -0,0 +1,118 @@
+/*
+ * (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * 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 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 <stdio.h>
+#include <stdlib.h>
+
+#include <osmocom/core/application.h>
+#include <osmocom/core/utils.h>
+
+#include <openbsc/gsm_data.h>
+#include <openbsc/abis_nm.h>
+#include <openbsc/debug.h>
+
+static const uint8_t simple_config[] = {
+ /*0, 13, */
+ 66, 18, 0, 3, 1, 2, 3, 19, 0, 3, 3, 4, 5,
+};
+
+static const uint8_t dual_config[] = {
+ /*0, 26, */
+ 66, 18, 0, 3, 1, 2, 3, 19, 0, 3, 3, 4, 5,
+ 66, 18, 0, 3, 9, 7, 5, 19, 0, 3, 6, 7, 8,
+};
+
+static void test_simple_sw_config(void)
+{
+ struct abis_nm_sw_descr descr[1];
+ int rc;
+
+ rc = abis_nm_parse_sw_config(simple_config, ARRAY_SIZE(simple_config),
+ &descr[0], ARRAY_SIZE(descr));
+ if (rc != 1) {
+ printf("FAILED to parse the File Id/File version\n");
+ abort();
+ }
+
+ if (descr[0].len != 13) {
+ printf("WRONG SIZE: %d\n", descr[0].len);
+ abort();
+ }
+
+ printf("Start: %u len: %zu\n", descr[0].start - simple_config, descr[0].len);
+ printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
+ printf("file_ver: %s\n", osmo_hexdump(descr[0].file_ver, descr[0].file_ver_len));
+}
+
+static void test_simple_sw_short(void)
+{
+ struct abis_nm_sw_descr descr[1];
+ int i;
+
+ for (i = 1; i < ARRAY_SIZE(simple_config); ++i) {
+ int rc = abis_nm_parse_sw_config(simple_config,
+ ARRAY_SIZE(simple_config) - i, &descr[0],
+ ARRAY_SIZE(descr));
+ if (rc >= 1) {
+ printf("SHOULD not have parsed: %d\n", rc);
+ abort();
+ }
+ }
+}
+
+static void test_dual_sw_config(void)
+{
+ struct abis_nm_sw_descr descr[2];
+ int rc;
+
+ rc = abis_nm_parse_sw_config(dual_config, ARRAY_SIZE(dual_config),
+ &descr[0], ARRAY_SIZE(descr));
+ if (rc != 2) {
+ printf("FAILED to parse the File Id/File version\n");
+ abort();
+ }
+
+ if (descr[0].len != 13) {
+ printf("WRONG SIZE0: %d\n", descr[0].len);
+ abort();
+ }
+
+ if (descr[1].len != 13) {
+ printf("WRONG SIZE1: %d\n", descr[1].len);
+ abort();
+ }
+
+ printf("Start: %u len: %zu\n", descr[0].start - dual_config, descr[0].len);
+ printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
+ printf("file_ver: %s\n", osmo_hexdump(descr[0].file_ver, descr[0].file_ver_len));
+
+ printf("Start: %u len: %zu\n", descr[1].start - dual_config, descr[1].len);
+ printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len));
+ printf("file_ver: %s\n", osmo_hexdump(descr[1].file_ver, descr[1].file_ver_len));
+}
+
+int main(int argc, char **argv)
+{
+ osmo_init_logging(&log_info);
+ test_simple_sw_config();
+ test_simple_sw_short();
+ test_dual_sw_config();
+
+ return EXIT_SUCCESS;
+}
diff --git a/openbsc/tests/abis/abis_test.ok b/openbsc/tests/abis/abis_test.ok
new file mode 100644
index 000000000..64019880c
--- /dev/null
+++ b/openbsc/tests/abis/abis_test.ok
@@ -0,0 +1,9 @@
+Start: 0 len: 13
+file_id: 01 02 03
+file_ver: 03 04 05
+Start: 13 len: 26
+file_id: 01 02 03
+file_ver: 03 04 05
+Start: 26 len: 13
+file_id: 09 07 05
+file_ver: 06 07 08
diff --git a/openbsc/tests/testsuite.at b/openbsc/tests/testsuite.at
index 8e1277312..4c5de8d6a 100644
--- a/openbsc/tests/testsuite.at
+++ b/openbsc/tests/testsuite.at
@@ -43,3 +43,9 @@ AT_KEYWORDS([si])
cat $abs_srcdir/si/si_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/si/si_test], [], [expout], [ignore])
AT_CLEANUP
+
+AT_SETUP([abis])
+AT_KEYWORDS([abis])
+cat $abs_srcdir/abis/abis_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/abis/abis_test], [], [expout], [ignore])
+AT_CLEANUP