pespin has uploaded this change for review.
tests/llc: Test gprs_llc_is_retransmit()
Imported from osmo-sgsn.git 4398ac073b7fc8363882b5f7414470b73d4f446a
./tests/gprs/gprs_test.c.
Change-Id: I4104ee9cc458b7d169ee9761e02369442058675a
---
M tests/llc/Makefile.am
A tests/llc/llc_test.c
A tests/llc/llc_test.err
A tests/llc/llc_test.ok
M tests/testsuite.at
5 files changed, 121 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-gprs refs/changes/13/30813/1
diff --git a/tests/llc/Makefile.am b/tests/llc/Makefile.am
index aa7e3e7..ee57c5f 100644
--- a/tests/llc/Makefile.am
+++ b/tests/llc/Makefile.am
@@ -10,12 +10,15 @@
$(NULL)
check_PROGRAMS = \
+ llc_test \
llc_prim_test \
pdu_codec_test \
xid_codec_test \
$(NULL)
EXTRA_DIST = \
+ llc_test.err \
+ llc_test.ok \
llc_prim_test.err \
llc_prim_test.ok \
pdu_codec_test.ok \
@@ -24,6 +27,13 @@
xid_codec_test.err \
$(NULL)
+llc_test_SOURCES = llc_test.c
+llc_test_LDADD = \
+ $(LIBOSMOCORE_LIBS) \
+ $(LIBOSMOGSM_LIBS) \
+ $(top_builddir)/src/llc/libosmo-gprs-llc.la \
+ $(NULL)
+
llc_prim_test_SOURCES = llc_prim_test.c
llc_prim_test_LDADD = \
$(LIBOSMOCORE_LIBS) \
diff --git a/tests/llc/llc_test.c b/tests/llc/llc_test.c
new file mode 100644
index 0000000..c5711d7
--- /dev/null
+++ b/tests/llc/llc_test.c
@@ -0,0 +1,89 @@
+/* LLC PDU codec tests
+ *
+ * (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * 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.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+
+#include <osmocom/gprs/llc/llc.h>
+#include <osmocom/gprs/llc/llc_private.h>
+
+static void *tall_ctx = NULL;
+
+#define ASSERT_FALSE(x) if (x) { printf("Should have returned false.\n"); abort(); }
+#define ASSERT_TRUE(x) if (!x) { printf("Should have returned true.\n"); abort(); }
+
+/**
+ * GSM 04.64 8.4.2 Receipt of unacknowledged information
+ */
+static int nu_is_retransmission(uint16_t nu, uint16_t vur)
+{
+ int ret = gprs_llc_is_retransmit(nu, vur);
+ printf("N(U) = %d, V(UR) = %d => %s\n", nu, vur,
+ ret == 1 ? "retransmit" : "new");
+ return ret;
+}
+
+static void test_8_4_2(void)
+{
+ printf("Testing gprs_llc_is_retransmit.\n");
+
+ ASSERT_FALSE(nu_is_retransmission(0, 0));
+ ASSERT_TRUE (nu_is_retransmission(0, 1));
+
+ /* expect 1... check for retransmissions */
+ ASSERT_TRUE (nu_is_retransmission(0, 1));
+ ASSERT_TRUE (nu_is_retransmission(511, 1));
+ ASSERT_TRUE (nu_is_retransmission(483, 1));
+ ASSERT_TRUE (nu_is_retransmission(482, 1));
+ ASSERT_FALSE(nu_is_retransmission(481, 1));
+
+ /* expect 511... check for retransmissions */
+ ASSERT_FALSE(nu_is_retransmission(0, 240)); // ahead
+ ASSERT_FALSE(nu_is_retransmission(0, 511)); // ahead
+ ASSERT_FALSE(nu_is_retransmission(1, 511)); // ahead
+ ASSERT_FALSE(nu_is_retransmission(511, 511)); // same
+ ASSERT_TRUE (nu_is_retransmission(510, 511)); // behind
+ ASSERT_TRUE (nu_is_retransmission(481, 511)); // behind
+ ASSERT_FALSE(nu_is_retransmission(479, 511)); // wrapped
+}
+
+static const struct log_info_cat test_log_categories[] = { };
+static const struct log_info test_log_info = {
+ .cat = test_log_categories,
+ .num_cat = ARRAY_SIZE(test_log_categories),
+};
+
+int main(int argc, char *argv[])
+{
+ tall_ctx = talloc_named_const(NULL, 1, __FILE__);
+
+ osmo_init_logging2(tall_ctx, &test_log_info);
+ log_parse_category_mask(osmo_stderr_target, "DLGLOBAL,1:");
+
+ log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
+ log_set_print_category_hex(osmo_stderr_target, 0);
+ log_set_print_category(osmo_stderr_target, 1);
+ log_set_print_level(osmo_stderr_target, 1);
+ log_set_use_color(osmo_stderr_target, 0);
+
+ test_8_4_2();
+
+ talloc_free(tall_ctx);
+}
diff --git a/tests/llc/llc_test.err b/tests/llc/llc_test.err
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/llc/llc_test.err
diff --git a/tests/llc/llc_test.ok b/tests/llc/llc_test.ok
new file mode 100644
index 0000000..9f54523
--- /dev/null
+++ b/tests/llc/llc_test.ok
@@ -0,0 +1,15 @@
+Testing gprs_llc_is_retransmit.
+N(U) = 0, V(UR) = 0 => new
+N(U) = 0, V(UR) = 1 => retransmit
+N(U) = 0, V(UR) = 1 => retransmit
+N(U) = 511, V(UR) = 1 => retransmit
+N(U) = 483, V(UR) = 1 => retransmit
+N(U) = 482, V(UR) = 1 => retransmit
+N(U) = 481, V(UR) = 1 => new
+N(U) = 0, V(UR) = 240 => new
+N(U) = 0, V(UR) = 511 => new
+N(U) = 1, V(UR) = 511 => new
+N(U) = 511, V(UR) = 511 => new
+N(U) = 510, V(UR) = 511 => retransmit
+N(U) = 481, V(UR) = 511 => retransmit
+N(U) = 479, V(UR) = 511 => new
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 5bbedf5..84cbb4e 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -1,6 +1,13 @@
AT_INIT
AT_BANNER([Regression tests])
+AT_SETUP([llc/llc])
+AT_KEYWORDS([llc llc])
+cat $abs_srcdir/llc/llc_test.ok > expout
+cat $abs_srcdir/llc/llc_test.err > experr
+AT_CHECK([$abs_top_builddir/tests/llc/llc_test], [0], [expout], [experr])
+AT_CLEANUP
+
AT_SETUP([llc/llc_prim])
AT_KEYWORDS([llc llc_prim])
cat $abs_srcdir/llc/llc_prim_test.ok > expout
To view, visit change 30813. To unsubscribe, or for help writing mail filters, visit settings.