aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-10-27 17:39:34 +0200
committerHarald Welte <laforge@gnumonks.org>2017-10-27 18:00:12 +0200
commitdb736f432aafb54a6b9469cabf5fa3cbbe359e9f (patch)
tree3be6beb54949e919e99446a53f40d31a04b808bd /tests
parent212d0c4c7614c2ec2796dd21ab240c2d70743a1e (diff)
implement unit tests for osmo_sccp_addr_{parse,encode}()
The recent bug with chopped-off point codes in SCCP Address handling has shown that this code could need proper test cases. This patch adds a testsuite for SCCP address encoding and decoding. Related: OS#2441 Change-Id: I612352736ab33462ca0dd97798a2c437eadccb86
Diffstat (limited to 'tests')
-rw-r--r--tests/testsuite.at3
-rw-r--r--tests/xua/Makefile.am2
-rw-r--r--tests/xua/xua_test.c181
-rw-r--r--tests/xua/xua_test.err2
-rw-r--r--tests/xua/xua_test.ok73
5 files changed, 259 insertions, 2 deletions
diff --git a/tests/testsuite.at b/tests/testsuite.at
index b810bdf..ebc43e7 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -22,7 +22,8 @@ AT_CLEANUP
AT_SETUP([xua])
AT_KEYWORDS([xua])
cat $abs_srcdir/xua/xua_test.ok > expout
-AT_CHECK([$abs_top_builddir/tests/xua/xua_test], [], [expout], [ignore])
+cat $abs_srcdir/xua/xua_test.err > experr
+AT_CHECK([$abs_top_builddir/tests/xua/xua_test], [], [expout], [experr])
AT_CLEANUP
AT_SETUP([ss7])
diff --git a/tests/xua/Makefile.am b/tests/xua/Makefile.am
index c6a9955..f56692b 100644
--- a/tests/xua/Makefile.am
+++ b/tests/xua/Makefile.am
@@ -5,7 +5,7 @@ AM_LDFLAGS = -static
LDADD = $(top_builddir)/src/libosmo-sigtran.la \
$(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS)
-EXTRA_DIST = xua_test.ok
+EXTRA_DIST = xua_test.ok xua_test.err
noinst_HEADERS = sccp_test_data.h
noinst_PROGRAMS = xua_test
diff --git a/tests/xua/xua_test.c b/tests/xua/xua_test.c
index c496cc4..5a9d0ab 100644
--- a/tests/xua/xua_test.c
+++ b/tests/xua/xua_test.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <errno.h>
static void test_isup_parse(void)
{
@@ -140,6 +141,183 @@ static void test_sccp_addr_parser(void)
}
}
+struct sccp_addr_enc_testcase {
+ const char *name;
+ struct osmo_sccp_addr addr_in;
+ int rc;
+ char *exp_out;
+};
+
+static const struct sccp_addr_enc_testcase enc_cases[] = {
+ {
+ .name = "NOGT-PC1024",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_SSN_PC,
+ .presence = OSMO_SCCP_ADDR_T_PC,
+ .pc = 1024,
+ },
+ .rc = 3,
+ .exp_out = "410004",
+ }, {
+ .name = "NOGT-PC16383",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_SSN_PC,
+ .presence = OSMO_SCCP_ADDR_T_PC,
+ .pc = 16383,
+ },
+ .rc = 3,
+ .exp_out = "41ff3f",
+ }, {
+ .name = "NOGT-PC16383-SSN90",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_SSN_PC,
+ .presence = OSMO_SCCP_ADDR_T_PC | OSMO_SCCP_ADDR_T_SSN,
+ .pc = 16383,
+ .ssn = 0x5A,
+ },
+ .rc = 4,
+ .exp_out = "43ff3f5a",
+ }, {
+ .name = "GT-PC16383-NAIONLY",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_SSN_PC,
+ .presence = OSMO_SCCP_ADDR_T_PC | OSMO_SCCP_ADDR_T_GT,
+ .pc = 16383,
+ .gt.gti = OSMO_SCCP_GTI_NAI_ONLY,
+ .gt.nai = 0x7f,
+ },
+ .rc = 4,
+ .exp_out = "45ff3f7f",
+ }, {
+ .name = "GT-NOPC-NAIONLY",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_NAI_ONLY,
+ .gt.nai = 0x03,
+ },
+ .rc = 2,
+ .exp_out = "0403",
+ }, {
+ .name = "GT-NOPC-TTONLY",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_TT_ONLY,
+ .gt.tt = 0x03,
+ },
+ .rc = -EINVAL,
+ }, {
+ .name = "GT-NOPC-TT_NPL_ENC-ODD",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_TT_NPL_ENC,
+ .gt.tt = 0x03,
+ .gt.npi = 1,
+ .gt.digits = "123",
+ },
+ .rc = 5,
+ .exp_out = "0c03112103",
+ }, {
+ .name = "GT-NOPC-TT_NPL_ENC-EVEN",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_TT_NPL_ENC,
+ .gt.tt = 0x03,
+ .gt.npi = 1,
+ .gt.digits = "1234",
+ },
+ .rc = 5,
+ .exp_out = "0c03122143",
+ }, {
+ .name = "GT-NOPC-TT_NPL_ENC_NAI-EVEN",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_TT_NPL_ENC_NAI,
+ .gt.tt = 0x03,
+ .gt.npi = 1,
+ .gt.nai = 4,
+ .gt.digits = "1234",
+ },
+ .rc = 6,
+ .exp_out = "100312042143",
+ }, {
+ .name = "GT-NOPC-GTI_INVALID",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = 23,
+ .gt.tt = 0x03,
+ .gt.npi = 1,
+ .gt.nai = 4,
+ .gt.digits = "1234",
+ },
+ .rc = -EINVAL,
+ }, {
+ .name = "GT-NOPC-TT_NPL_ENC_NAI-EVEN-NONNUM",
+ .addr_in = {
+ .ri = OSMO_SCCP_RI_GT,
+ .presence = OSMO_SCCP_ADDR_T_GT,
+ .gt.gti = OSMO_SCCP_GTI_TT_NPL_ENC_NAI,
+ .gt.tt = 0x03,
+ .gt.npi = 1,
+ .gt.nai = 4,
+ .gt.digits = "1ABF",
+ },
+ .rc = 6,
+ .exp_out = "10031204a1fb",
+ },
+
+};
+
+static void testcase_sccp_addr_encdec(const struct sccp_addr_enc_testcase *tcase)
+{
+ struct msgb *msg = msgb_alloc(1024, "encdec");
+ struct osmo_sccp_addr out;
+ char *str;
+ int rc;
+
+ printf("\n=> %s\n", tcase->name);
+
+ printf("input addr: %s\n", osmo_sccp_addr_dump(&tcase->addr_in));
+ rc = osmo_sccp_addr_encode(msg, &tcase->addr_in);
+ printf("rc=%d, expected rc=%d\n", rc, tcase->rc);
+ OSMO_ASSERT(rc == tcase->rc);
+
+ if (rc <= 0) {
+ msgb_free(msg);
+ return;
+ }
+
+ str = osmo_hexdump_nospc(msg->data, msg->len);
+ printf("encoded addr: %s\n", str);
+ if (tcase->exp_out) {
+ printf("expected addr: %s\n", tcase->exp_out);
+ OSMO_ASSERT(!strcmp(tcase->exp_out, str));
+ }
+
+ rc = osmo_sccp_addr_parse(&out, msg->data, msg->len);
+ printf("decod addr: %s\n", osmo_sccp_addr_dump(&out));
+
+ OSMO_ASSERT(!memcmp(&out, &tcase->addr_in, sizeof(out)));
+
+ msgb_free(msg);
+}
+
+static void test_sccp_addr_encdec(void)
+{
+ int i;
+
+ printf("Testing SCCP Address Encode/Decode\n");
+ for (i = 0; i < ARRAY_SIZE(enc_cases); i++) {
+ testcase_sccp_addr_encdec(&enc_cases[i]);
+ }
+ printf("\n");
+}
+
/* sccp_addr_testcases[0].expected.gt transcoded into a SUA Global Title IE */
static const uint8_t expected_sua_gt[] = {
0x80, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04,
@@ -408,12 +586,15 @@ int main(int argc, char **argv)
log_init(&log_info, NULL);
stderr_target = log_target_create_stderr();
log_add_target(stderr_target);
+ log_set_use_color(stderr_target, 0);
+ log_set_print_filename(stderr_target, 0);
test_isup_parse();
test_sccp_addr_parser();
test_helpers();
test_sccp2sua();
test_rkm();
+ test_sccp_addr_encdec();
printf("All tests passed.\n");
return 0;
diff --git a/tests/xua/xua_test.err b/tests/xua/xua_test.err
new file mode 100644
index 0000000..17870ee
--- /dev/null
+++ b/tests/xua/xua_test.err
@@ -0,0 +1,2 @@
+Unsupported Translation Type 2requested
+Unsupported GTI 23 requested
diff --git a/tests/xua/xua_test.ok b/tests/xua/xua_test.ok
index 12d817d..6b0cb33 100644
--- a/tests/xua/xua_test.ok
+++ b/tests/xua/xua_test.ok
@@ -132,4 +132,77 @@ Re-Encoding decoded SUA to SCCP
SCCP Output: 09 81 03 0d 18 0a 12 07 00 12 04 53 84 09 00 17 0b 12 06 00 12 04 44 87 20 00 20 65 9a 65 81 97 48 04 26 00 01 98 49 04 51 01 03 df 6c 81 88 a1 81 85 02 01 44 02 01 07 30 80 a7 80 a0 80 04 01 2b 30 80 30 12 83 01 10 84 01 07 85 07 91 44 57 76 67 16 97 86 01 20 30 06 82 01 18 84 01 04 00 00 00 00 a3 06 04 01 42 84 01 05 a3 06 04 01 51 84 01 05 a3 06 04 01 31 84 01 05 a3 09 04 01 12 84 01 05 82 01 02 a3 09 04 01 11 84 01 05 81 01 01 a3 06 04 01 14 84 01 00 a3 0b 04 01 41 84 01 04 30 03 83 01 10 a3 0b 04 01 41 84 01 04 30 03 82 01 18 00 00 00 00
Parsing M3UA Message
Parsing Nested M3UA Routing Key IE
+Testing SCCP Address Encode/Decode
+
+=> NOGT-PC1024
+input addr: RI=2,PC=1024,GTI=0
+rc=3, expected rc=3
+encoded addr: 410004
+expected addr: 410004
+decod addr: RI=2,PC=1024,GTI=0
+
+=> NOGT-PC16383
+input addr: RI=2,PC=16383,GTI=0
+rc=3, expected rc=3
+encoded addr: 41ff3f
+expected addr: 41ff3f
+decod addr: RI=2,PC=16383,GTI=0
+
+=> NOGT-PC16383-SSN90
+input addr: RI=2,PC=16383,SSN=90,GTI=0
+rc=4, expected rc=4
+encoded addr: 43ff3f5a
+expected addr: 43ff3f5a
+decod addr: RI=2,PC=16383,SSN=90,GTI=0
+
+=> GT-PC16383-NAIONLY
+input addr: RI=2,PC=16383,GTI=1,GT=()
+rc=4, expected rc=4
+encoded addr: 45ff3f7f
+expected addr: 45ff3f7f
+decod addr: RI=2,PC=16383,GTI=1,GT=()
+
+=> GT-NOPC-NAIONLY
+input addr: RI=1,GTI=1,GT=()
+rc=2, expected rc=2
+encoded addr: 0403
+expected addr: 0403
+decod addr: RI=1,GTI=1,GT=()
+
+=> GT-NOPC-TTONLY
+input addr: RI=1,GTI=2,GT=(TT=3,DIG=)
+rc=-22, expected rc=-22
+
+=> GT-NOPC-TT_NPL_ENC-ODD
+input addr: RI=1,GTI=3,GT=(TT=3,NPL=1,DIG=123)
+rc=5, expected rc=5
+encoded addr: 0c03112103
+expected addr: 0c03112103
+decod addr: RI=1,GTI=3,GT=(TT=3,NPL=1,DIG=123)
+
+=> GT-NOPC-TT_NPL_ENC-EVEN
+input addr: RI=1,GTI=3,GT=(TT=3,NPL=1,DIG=1234)
+rc=5, expected rc=5
+encoded addr: 0c03122143
+expected addr: 0c03122143
+decod addr: RI=1,GTI=3,GT=(TT=3,NPL=1,DIG=1234)
+
+=> GT-NOPC-TT_NPL_ENC_NAI-EVEN
+input addr: RI=1,GTI=4,GT=(TT=3,NPL=1,NAI=4,DIG=1234)
+rc=6, expected rc=6
+encoded addr: 100312042143
+expected addr: 100312042143
+decod addr: RI=1,GTI=4,GT=(TT=3,NPL=1,NAI=4,DIG=1234)
+
+=> GT-NOPC-GTI_INVALID
+input addr: RI=1,GTI=23,GT=(DIG=1234)
+rc=-22, expected rc=-22
+
+=> GT-NOPC-TT_NPL_ENC_NAI-EVEN-NONNUM
+input addr: RI=1,GTI=4,GT=(TT=3,NPL=1,NAI=4,DIG=1ABF)
+rc=6, expected rc=6
+encoded addr: 10031204a1fb
+expected addr: 10031204a1fb
+decod addr: RI=1,GTI=4,GT=(TT=3,NPL=1,NAI=4,DIG=1ABF)
+
All tests passed.