summaryrefslogtreecommitdiffstats
path: root/Src/osmolib/src/shared/libosmocore/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Src/osmolib/src/shared/libosmocore/tests')
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/Makefile.am43
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/a5/Makefile.am6
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.c98
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.ok6
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/auth/Makefile.am8
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.c78
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.ok8
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/bits/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/bits/bitrev_test.ok24
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/conv/Makefile.am6
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.c486
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.ok55
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/gsm0808/Makefile.am6
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c269
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok15
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/lapd/Makefile.am9
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.c319
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.ok20
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/msgfile/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/msgfile/msgfile_test.ok1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/sms/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/sms/sms_test.ok2
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/smscb/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/smscb/smscb_test.ok4
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/testsuite.at73
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/timer/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.c182
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.ok2
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/ussd/Makefile.am1
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.c6
-rw-r--r--Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.ok53
31 files changed, 1750 insertions, 35 deletions
diff --git a/Src/osmolib/src/shared/libosmocore/tests/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/Makefile.am
index 6c3cb33..eff1ac4 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/Makefile.am
@@ -1,6 +1,47 @@
if ENABLE_TESTS
-SUBDIRS = timer sms ussd smscb bits
+SUBDIRS = timer sms ussd smscb bits a5 conv auth lapd gsm0808
if ENABLE_MSGFILE
SUBDIRS += msgfile
endif
+
+
+# The `:;' works around a Bash 3.2 bug when the output is not writeable.
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ :;{ \
+ echo '# Signature of the current package.' && \
+ echo 'm4_define([AT_PACKAGE_NAME],' && \
+ echo ' [$(PACKAGE_NAME)])' && \
+ echo 'm4_define([AT_PACKAGE_TARNAME],' && \
+ echo ' [$(PACKAGE_TARNAME)])' && \
+ echo 'm4_define([AT_PACKAGE_VERSION],' && \
+ echo ' [$(PACKAGE_VERSION)])' && \
+ echo 'm4_define([AT_PACKAGE_STRING],' && \
+ echo ' [$(PACKAGE_STRING)])' && \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
+ echo ' [$(PACKAGE_BUGREPORT)])'; \
+ echo 'm4_define([AT_PACKAGE_URL],' && \
+ echo ' [$(PACKAGE_URL)])'; \
+ } >'$(srcdir)/package.m4'
+
+EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE)
+TESTSUITE = $(srcdir)/testsuite
+
+check-local: atconfig $(TESTSUITE)
+ $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+
+installcheck-local: atconfig $(TESTSUITE)
+ $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
+ $(TESTSUITEFLAGS)
+
+clean-local:
+ test ! -f '$(TESTSUITE)' || \
+ $(SHELL) '$(TESTSUITE)' --clean
+ $(RM) -f atconfig
+
+AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
+ $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
+ mv $@.tmp $@
+
endif
diff --git a/Src/osmolib/src/shared/libosmocore/tests/a5/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/a5/Makefile.am
new file mode 100644
index 0000000..3c6e6ba
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/a5/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = a5_test
+EXTRA_DIST = a5_test.ok
+
+a5_test_SOURCES = a5_test.c
+a5_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.c b/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.c
new file mode 100644
index 0000000..14436f1
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.c
@@ -0,0 +1,98 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gsm/a5.h>
+
+static const uint8_t key[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
+static const uint32_t fn = 123456;
+static const uint8_t dl[] = {
+ /* A5/0 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ /* A5/1 */
+ 0xcb, 0xa2, 0x55, 0x76, 0x17, 0x5d, 0x3b, 0x1c,
+ 0x7b, 0x2f, 0x29, 0xa8, 0xc1, 0xb6, 0x00,
+
+ /* A5/2 */
+ 0x45, 0x9c, 0x88, 0xc3, 0x82, 0xb7, 0xff, 0xb3,
+ 0x98, 0xd2, 0xf9, 0x6e, 0x0f, 0x14, 0x80,
+};
+static const uint8_t ul[] = {
+ /* A5/0 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ /* A5/1 */
+ 0xd9, 0x03, 0x5e, 0x0f, 0x2a, 0xec, 0x13, 0x9a,
+ 0x05, 0xd4, 0xa8, 0x7b, 0xb1, 0x64, 0x80,
+
+ /* A5/2 */
+ 0xf0, 0x3a, 0xac, 0xde, 0xe3, 0x5b, 0x5e, 0x65,
+ 0x80, 0xba, 0xab, 0xc0, 0x59, 0x26, 0x40,
+};
+
+static const char *
+binstr(ubit_t *d, int n)
+{
+ static char str[256];
+ int i;
+
+ for (i=0; i<n; i++)
+ str[i] = d[i] ? '1' : '0';
+
+ str[i] = '\0';
+
+ return str;
+}
+
+int main(int argc, char **argv)
+{
+ ubit_t exp[114];
+ ubit_t out[114];
+ int n, i;
+
+ for (n=0; n<3; n++) {
+ /* "Randomize" */
+ for (i=0; i<114; i++)
+ out[i] = i & 1;
+
+ /* DL */
+ osmo_pbit2ubit(exp, &dl[15*n], 114);
+
+ osmo_a5(n, key, fn, out, NULL);
+
+ printf("A5/%d - DL: %s", n, binstr(out, 114));
+
+ if (!memcmp(exp, out, 114))
+ printf(" => OK\n");
+ else {
+ printf(" => BAD\n");
+ printf(" Expected: %s", binstr(out, 114));
+ fprintf(stderr, "[!] A5/%d DL failed", n);
+ exit(1);
+ }
+
+ /* UL */
+ osmo_pbit2ubit(exp, &ul[15*n], 114);
+
+ osmo_a5(n, key, fn, NULL, out);
+
+ printf("A5/%d - UL: %s", n, binstr(out, 114));
+
+ if (!memcmp(exp, out, 114))
+ printf(" => OK\n");
+ else {
+ printf(" => BAD\n");
+ printf(" Expected: %s", binstr(out, 114));
+ fprintf(stderr, "[!] A5/%d UL failed", n);
+ exit(1);
+ }
+ }
+
+ return 0;
+}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.ok b/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.ok
new file mode 100644
index 0000000..4497e14
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/a5/a5_test.ok
@@ -0,0 +1,6 @@
+A5/0 - DL: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 => OK
+A5/0 - UL: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 => OK
+A5/1 - DL: 110010111010001001010101011101100001011101011101001110110001110001111011001011110010100110101000110000011011011000 => OK
+A5/1 - UL: 110110010000001101011110000011110010101011101100000100111001101000000101110101001010100001111011101100010110010010 => OK
+A5/2 - DL: 010001011001110010001000110000111000001010110111111111111011001110011000110100101111100101101110000011110001010010 => OK
+A5/2 - UL: 111100000011101010101100110111101110001101011011010111100110010110000000101110101010101111000000010110010010011001 => OK
diff --git a/Src/osmolib/src/shared/libosmocore/tests/auth/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/auth/Makefile.am
new file mode 100644
index 0000000..52976d0
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/auth/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = milenage_test
+EXTRA_DIST = milenage_test.ok
+
+milenage_test_SOURCES = milenage_test.c
+milenage_test_LDADD = $(top_builddir)/src/libosmocore.la \
+ $(top_builddir)/src/gsm/libosmogsm.la
+
diff --git a/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.c b/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.c
new file mode 100644
index 0000000..da7c800
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.c
@@ -0,0 +1,78 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <osmocom/crypt/auth.h>
+#include <osmocom/core/utils.h>
+
+static void dump_auth_vec(struct osmo_auth_vector *vec)
+{
+ printf("RAND:\t%s\n", osmo_hexdump(vec->rand, sizeof(vec->rand)));
+
+ if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) {
+ printf("AUTN:\t%s\n", osmo_hexdump(vec->autn, sizeof(vec->autn)));
+ printf("IK:\t%s\n", osmo_hexdump(vec->ik, sizeof(vec->ik)));
+ printf("CK:\t%s\n", osmo_hexdump(vec->ck, sizeof(vec->ck)));
+ printf("RES:\t%s\n", osmo_hexdump(vec->res, vec->res_len));
+ }
+
+ if (vec->auth_types & OSMO_AUTH_TYPE_GSM) {
+ printf("SRES:\t%s\n", osmo_hexdump(vec->sres, sizeof(vec->sres)));
+ printf("Kc:\t%s\n", osmo_hexdump(vec->kc, sizeof(vec->kc)));
+ }
+}
+
+static struct osmo_sub_auth_data test_aud = {
+ .type = OSMO_AUTH_TYPE_UMTS,
+ .algo = OSMO_AUTH_ALG_MILENAGE,
+ .u.umts = {
+ .opc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .k = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ .amf = { 0x00, 0x00 },
+ .sqn = 0x22,
+ },
+};
+
+int main(int argc, char **argv)
+{
+ struct osmo_auth_vector _vec;
+ struct osmo_auth_vector *vec = &_vec;
+ uint8_t _rand[16];
+ int rc;
+
+#if 0
+ srand(time(NULL));
+ *(uint32_t *)&_rand[0] = rand();
+ *(uint32_t *)(&_rand[4]) = rand();
+ *(uint32_t *)(&_rand[8]) = rand();
+ *(uint32_t *)(&_rand[12]) = rand();
+#else
+ memset(_rand, 0, sizeof(_rand));
+#endif
+ memset(vec, 0, sizeof(*vec));
+
+ rc = osmo_auth_gen_vec(vec, &test_aud, _rand);
+ if (rc < 0) {
+ fprintf(stderr, "error generating auth vector\n");
+ exit(1);
+ }
+
+ dump_auth_vec(vec);
+
+ const uint8_t auts[14] = { 0x87, 0x11, 0xa0, 0xec, 0x9e, 0x16, 0x37, 0xdf,
+ 0x17, 0xf8, 0x0b, 0x38, 0x4e, 0xe4 };
+
+ rc = osmo_auth_gen_vec_auts(vec, &test_aud, auts, _rand, _rand);
+ if (rc < 0) {
+ printf("AUTS failed\n");
+ } else {
+ printf("AUTS success: SEQ.MS = %lu\n", test_aud.u.umts.sqn);
+ }
+
+ exit(0);
+
+}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.ok b/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.ok
new file mode 100644
index 0000000..66337ca
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/auth/milenage_test.ok
@@ -0,0 +1,8 @@
+RAND: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+AUTN: ec 93 20 c2 c2 12 00 00 c8 b7 de 2a 34 49 f1 bd
+IK: 12 cb 2d d3 e0 ec 83 78 f6 fc 1d 60 6c 61 9f 47
+CK: 72 00 a1 84 d8 f2 c7 58 fb df 87 90 0d db f2 75
+RES: e9 fc 88 cc c8 a3 53 81
+SRES: 21 5f db 4d
+Kc: 6d e8 16 a7 59 a4 29 12
+AUTS success: SEQ.MS = 33
diff --git a/Src/osmolib/src/shared/libosmocore/tests/bits/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/bits/Makefile.am
index dd03e83..d6fb2f2 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/bits/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/bits/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = bitrev_test
+EXTRA_DIST = bitrev_test.ok
bitrev_test_SOURCES = bitrev_test.c
bitrev_test_LDADD = $(top_builddir)/src/libosmocore.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/bits/bitrev_test.ok b/Src/osmolib/src/shared/libosmocore/tests/bits/bitrev_test.ok
new file mode 100644
index 0000000..47f402f
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/bits/bitrev_test.ok
@@ -0,0 +1,24 @@
+INORDER: 01 02 04 08 10 20 40 80
+REVERSED: 80 40 20 10 08 04 02 01
+
+INORDER: 02 04 08 10 20 40 80
+REVERSED: 40 20 10 08 04 02 01
+
+INORDER: 04 08 10 20 40 80
+REVERSED: 20 10 08 04 02 01
+
+INORDER: 08 10 20 40 80
+REVERSED: 10 08 04 02 01
+
+INORDER: 10 20 40 80
+REVERSED: 08 04 02 01
+
+INORDER: 20 40 80
+REVERSED: 04 02 01
+
+INORDER: 40 80
+REVERSED: 02 01
+
+INORDER: 80
+REVERSED: 01
+
diff --git a/Src/osmolib/src/shared/libosmocore/tests/conv/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/conv/Makefile.am
new file mode 100644
index 0000000..75cfec8
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/conv/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = conv_test
+EXTRA_DIST = conv_test.ok
+
+conv_test_SOURCES = conv_test.c
+conv_test_LDADD = $(top_builddir)/src/libosmocore.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.c b/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.c
new file mode 100644
index 0000000..54e043e
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.c
@@ -0,0 +1,486 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/conv.h>
+#include <osmocom/core/utils.h>
+
+#define MAX_LEN_BITS 512
+#define MAX_LEN_BYTES (512/8)
+
+
+/* ------------------------------------------------------------------------ */
+/* Test codes */
+/* ------------------------------------------------------------------------ */
+
+/* GSM xCCH -> Non-recursive code, flushed, not punctured */
+static const uint8_t conv_gsm_xcch_next_output[][2] = {
+ { 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
+ { 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 },
+ { 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 },
+};
+
+static const uint8_t conv_gsm_xcch_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+};
+
+static const struct osmo_conv_code conv_gsm_xcch = {
+ .N = 2,
+ .K = 5,
+ .len = 224,
+ .term = CONV_TERM_FLUSH,
+ .next_output = conv_gsm_xcch_next_output,
+ .next_state = conv_gsm_xcch_next_state,
+};
+
+
+/* GSM TCH/AFS 7.95 -> Recursive code, flushed, with puncturing */
+static const uint8_t conv_gsm_tch_afs_7_95_next_output[][2] = {
+ { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 },
+ { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 },
+ { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 },
+ { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 },
+ { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 },
+ { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 },
+ { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 },
+ { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 },
+};
+
+static const uint8_t conv_gsm_tch_afs_7_95_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 5, 4 }, { 7, 6 },
+ { 9, 8 }, { 11, 10 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 21, 20 }, { 23, 22 },
+ { 25, 24 }, { 27, 26 }, { 28, 29 }, { 30, 31 },
+ { 33, 32 }, { 35, 34 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 45, 44 }, { 47, 46 },
+ { 49, 48 }, { 51, 50 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 61, 60 }, { 63, 62 },
+ { 1, 0 }, { 3, 2 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 13, 12 }, { 15, 14 },
+ { 17, 16 }, { 19, 18 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 29, 28 }, { 31, 30 },
+ { 32, 33 }, { 34, 35 }, { 37, 36 }, { 39, 38 },
+ { 41, 40 }, { 43, 42 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 53, 52 }, { 55, 54 },
+ { 57, 56 }, { 59, 58 }, { 60, 61 }, { 62, 63 },
+};
+
+static const uint8_t conv_gsm_tch_afs_7_95_next_term_output[] = {
+ 0, 3, 5, 6, 5, 6, 0, 3, 3, 0, 6, 5, 6, 5, 3, 0,
+ 4, 7, 1, 2, 1, 2, 4, 7, 7, 4, 2, 1, 2, 1, 7, 4,
+ 7, 4, 2, 1, 2, 1, 7, 4, 4, 7, 1, 2, 1, 2, 4, 7,
+ 3, 0, 6, 5, 6, 5, 3, 0, 0, 3, 5, 6, 5, 6, 0, 3,
+};
+
+static const uint8_t conv_gsm_tch_afs_7_95_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
+ 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
+ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
+ 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
+};
+
+static int conv_gsm_tch_afs_7_95_puncture[] = {
+ 1, 2, 4, 5, 8, 22, 70, 118, 166, 214, 262, 310,
+ 317, 319, 325, 332, 334, 341, 343, 349, 356, 358, 365, 367,
+ 373, 380, 382, 385, 389, 391, 397, 404, 406, 409, 413, 415,
+ 421, 428, 430, 433, 437, 439, 445, 452, 454, 457, 461, 463,
+ 469, 476, 478, 481, 485, 487, 490, 493, 500, 502, 503, 505,
+ 506, 508, 509, 511, 512,
+ -1, /* end */
+};
+
+static const struct osmo_conv_code conv_gsm_tch_afs_7_95 = {
+ .N = 3,
+ .K = 7,
+ .len = 165,
+ .term = CONV_TERM_FLUSH,
+ .next_output = conv_gsm_tch_afs_7_95_next_output,
+ .next_state = conv_gsm_tch_afs_7_95_next_state,
+ .next_term_output = conv_gsm_tch_afs_7_95_next_term_output,
+ .next_term_state = conv_gsm_tch_afs_7_95_next_term_state,
+ .puncture = conv_gsm_tch_afs_7_95_puncture,
+};
+
+
+/* GMR-1 TCH3 Speech -> Non recursive code, tail-biting, punctured */
+static const uint8_t conv_gmr1_tch3_speech_next_output[][2] = {
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+};
+
+static const uint8_t conv_gmr1_tch3_speech_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+static const int conv_gmr1_tch3_speech_puncture[] = {
+ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47,
+ 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95,
+ -1, /* end */
+};
+
+static const struct osmo_conv_code conv_gmr1_tch3_speech = {
+ .N = 2,
+ .K = 7,
+ .len = 48,
+ .term = CONV_TERM_TAIL_BITING,
+ .next_output = conv_gmr1_tch3_speech_next_output,
+ .next_state = conv_gmr1_tch3_speech_next_state,
+ .puncture = conv_gmr1_tch3_speech_puncture,
+};
+
+
+/* WiMax FCH -> Non recursive code, tail-biting, non-punctured */
+static const uint8_t conv_wimax_fch_next_output[][2] = {
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+};
+
+static const uint8_t conv_wimax_fch_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+static const struct osmo_conv_code conv_wimax_fch = {
+ .N = 2,
+ .K = 7,
+ .len = 48,
+ .term = CONV_TERM_TAIL_BITING,
+ .next_output = conv_wimax_fch_next_output,
+ .next_state = conv_wimax_fch_next_state,
+};
+
+
+/* Random code -> Non recursive code, direct truncation, non-punctured */
+static const struct osmo_conv_code conv_trunc = {
+ .N = 2,
+ .K = 5,
+ .len = 224,
+ .term = CONV_TERM_TRUNCATION,
+ .next_output = conv_gsm_xcch_next_output,
+ .next_state = conv_gsm_xcch_next_state,
+};
+
+
+/* ------------------------------------------------------------------------ */
+/* Test vectors */
+/* ------------------------------------------------------------------------ */
+
+struct conv_test_vector {
+ const char *name;
+ const struct osmo_conv_code *code;
+ int in_len;
+ int out_len;
+ int has_vec;
+ pbit_t vec_in[MAX_LEN_BYTES];
+ pbit_t vec_out[MAX_LEN_BYTES];
+};
+
+static const struct conv_test_vector tests[] = {
+ {
+ .name = "GSM xCCH (non-recursive, flushed, not punctured)",
+ .code = &conv_gsm_xcch,
+ .in_len = 224,
+ .out_len = 456,
+ .has_vec = 1,
+ .vec_in = { 0xf3, 0x1d, 0xb4, 0x0c, 0x4d, 0x1d, 0x9d, 0xae,
+ 0xc0, 0x0a, 0x42, 0x57, 0x13, 0x60, 0x80, 0x96,
+ 0xef, 0x23, 0x7e, 0x4c, 0x1d, 0x96, 0x24, 0x19,
+ 0x17, 0xf2, 0x44, 0x99 },
+ .vec_out = { 0xe9, 0x4d, 0x70, 0xab, 0xa2, 0x87, 0xf0, 0xe7,
+ 0x04, 0x14, 0x7c, 0xab, 0xaf, 0x6b, 0xa1, 0x16,
+ 0xeb, 0x30, 0x00, 0xde, 0xc8, 0xfd, 0x0b, 0x85,
+ 0x80, 0x41, 0x4a, 0xcc, 0xd3, 0xc0, 0xd0, 0xb6,
+ 0x26, 0xe5, 0x4e, 0x32, 0x49, 0x69, 0x38, 0x17,
+ 0x33, 0xab, 0xaf, 0xb6, 0xc1, 0x08, 0xf3, 0x9f,
+ 0x8c, 0x75, 0x6a, 0x4e, 0x08, 0xc4, 0x20, 0x5f,
+ 0x8f },
+ },
+ {
+ .name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)",
+ .code = &conv_gsm_tch_afs_7_95,
+ .in_len = 165,
+ .out_len = 448,
+ .has_vec = 1,
+ .vec_in = { 0x87, 0x66, 0xc3, 0x58, 0x09, 0xd4, 0x06, 0x59,
+ 0x10, 0xbf, 0x6b, 0x7f, 0xc8, 0xed, 0x72, 0xaa,
+ 0xc1, 0x3d, 0xf3, 0x1e, 0xb0 },
+ .vec_out = { 0x92, 0xbc, 0xde, 0xa0, 0xde, 0xbe, 0x01, 0x2f,
+ 0xbe, 0xe4, 0x61, 0x32, 0x4d, 0x4f, 0xdc, 0x41,
+ 0x43, 0x0d, 0x15, 0xe0, 0x23, 0xdd, 0x18, 0x91,
+ 0xe5, 0x36, 0x2d, 0xb7, 0xd9, 0x78, 0xb8, 0xb1,
+ 0xb7, 0xcb, 0x2f, 0xc0, 0x52, 0x8f, 0xe2, 0x8c,
+ 0x6f, 0xa6, 0x79, 0x88, 0xed, 0x0c, 0x2e, 0x9e,
+ 0xa1, 0x5f, 0x45, 0x4a, 0xfb, 0xe6, 0x5a, 0x9c },
+ },
+ {
+ .name = "GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)",
+ .code = &conv_gmr1_tch3_speech,
+ .in_len = 48,
+ .out_len = 72,
+ .has_vec = 1,
+ .vec_in = { 0x4d, 0xcb, 0xfc, 0x72, 0xf4, 0x8c },
+ .vec_out = { 0xc0, 0x86, 0x63, 0x4b, 0x8b, 0xd4, 0x6a, 0x76, 0xb2 },
+ },
+ {
+ .name = "WiMax FCH (non-recursive, tail-biting, not punctured)",
+ .code = &conv_wimax_fch,
+ .in_len = 48,
+ .out_len = 96,
+ .has_vec = 1,
+ .vec_in = { 0xfc, 0xa0, 0xa0, 0xfc, 0xa0, 0xa0 },
+ .vec_out = { 0x19, 0x42, 0x8a, 0xed, 0x21, 0xed, 0x19, 0x42,
+ 0x8a, 0xed, 0x21, 0xed },
+ },
+ {
+ .name = "??? (non-recursive, direct truncation, not punctured)",
+ .code = &conv_trunc,
+ .in_len = 224,
+ .out_len = 448,
+ .has_vec = 1,
+ .vec_in = { 0xe5, 0xe0, 0x85, 0x7e, 0xf7, 0x08, 0x19, 0x5a,
+ 0xb9, 0xad, 0x82, 0x37, 0x98, 0x8b, 0x26, 0xb9,
+ 0x81, 0x26, 0x9c, 0x75, 0xaf, 0xf3, 0xcb, 0x07,
+ 0xac, 0x63, 0xe2, 0x9c,
+ },
+ .vec_out = { 0xea, 0x3b, 0x55, 0x0c, 0xd3, 0xf7, 0x85, 0x69,
+ 0xe5, 0x79, 0x83, 0xd3, 0xc3, 0x9f, 0xb8, 0x61,
+ 0x21, 0x63, 0x51, 0x18, 0xac, 0xcd, 0x32, 0x49,
+ 0x53, 0x5c, 0x13, 0x1d, 0xbe, 0x05, 0x11, 0x63,
+ 0x5c, 0xc3, 0x42, 0x05, 0x1c, 0x68, 0x0a, 0xb4,
+ 0x61, 0x15, 0xaa, 0x4d, 0x94, 0xed, 0xb3, 0x3a,
+ 0x5d, 0x1b, 0x09, 0xc2, 0x99, 0x01, 0xec, 0x68 },
+ },
+ { /* end */ },
+};
+
+
+
+
+/* ------------------------------------------------------------------------ */
+/* Main */
+/* ------------------------------------------------------------------------ */
+
+static void
+fill_random(ubit_t *b, int n)
+{
+ int i;
+ for (i=0; i<n; i++)
+ b[i] = random() & 1;
+}
+
+static void
+ubit_to_sbit(sbit_t *dst, ubit_t *src, int n)
+{
+ int i;
+ for (i=0; i<n; i++)
+ dst[i] = src[i] ? -127 : 127;
+}
+
+static void
+sbit_to_ubit(ubit_t *dst, sbit_t *src, int n)
+{
+ int i;
+ for (i=0; i<n; i++)
+ dst[i] = src[i] < 0;
+}
+
+
+int main(int argc, char argv[])
+{
+ const struct conv_test_vector *tst;
+ ubit_t *bu0, *bu1;
+ sbit_t *bs;
+
+ srandom(time(NULL));
+
+ bu0 = malloc(sizeof(ubit_t) * MAX_LEN_BITS);
+ bu1 = malloc(sizeof(ubit_t) * MAX_LEN_BITS);
+ bs = malloc(sizeof(sbit_t) * MAX_LEN_BITS);
+
+ for (tst=tests; tst->name; tst++)
+ {
+ int i,l;
+
+ /* Test name */
+ printf("[+] Testing: %s\n", tst->name);
+
+ /* Check length */
+ l = osmo_conv_get_input_length(tst->code, 0);
+ printf("[.] Input length : ret = %3d exp = %3d -> %s\n",
+ l, tst->in_len, l == tst->in_len ? "OK" : "Bad !");
+
+ if (l != tst->in_len) {
+ fprintf(stderr, "[!] Failure for input length computation\n");
+ return -1;
+ }
+
+ l = osmo_conv_get_output_length(tst->code, 0);
+ printf("[.] Output length : ret = %3d exp = %3d -> %s\n",
+ l, tst->out_len, l == tst->out_len ? "OK" : "Bad !");
+
+ if (l != tst->out_len) {
+ fprintf(stderr, "[!] Failure for output length computation\n");
+ return -1;
+ }
+
+ /* Check pre-computed vector */
+ if (tst->has_vec) {
+ printf("[.] Pre computed vector checks:\n");
+
+ printf("[..] Encoding: ");
+
+ osmo_pbit2ubit(bu0, tst->vec_in, tst->in_len);
+
+ l = osmo_conv_encode(tst->code, bu0, bu1);
+ if (l != tst->out_len) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed encoding length check\n");
+ return -1;
+ }
+
+ osmo_pbit2ubit(bu0, tst->vec_out, tst->out_len);
+
+ if (memcmp(bu0, bu1, tst->out_len)) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed encoding: Results don't match\n");
+ return -1;
+ };
+
+ printf("OK\n");
+
+
+ printf("[..] Decoding: ");
+
+ ubit_to_sbit(bs, bu0, l);
+
+ l = osmo_conv_decode(tst->code, bs, bu1);
+ if (l != 0) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", l);
+ return -1;
+ }
+
+ osmo_pbit2ubit(bu0, tst->vec_in, tst->in_len);
+
+ if (memcmp(bu0, bu1, tst->in_len)) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed decoding: Results don't match\n");
+ return -1;
+ }
+
+ printf("OK\n");
+ }
+
+ /* Check random vector */
+ printf("[.] Random vector checks:\n");
+
+ for (i=0; i<3; i++) {
+ printf("[..] Encoding / Decoding cycle : ");
+
+ fill_random(bu0, tst->in_len);
+
+ l = osmo_conv_encode(tst->code, bu0, bu1);
+ if (l != tst->out_len) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed encoding length check\n");
+ return -1;
+ }
+
+ ubit_to_sbit(bs, bu1, l);
+
+ l = osmo_conv_decode(tst->code, bs, bu1);
+ if (l != 0) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", l);
+ return -1;
+ }
+
+ if (memcmp(bu0, bu1, tst->in_len)) {
+ printf("ERROR !\n");
+ fprintf(stderr, "[!] Failed decoding: Results don't match\n");
+ return -1;
+ }
+
+ printf("OK\n");
+ }
+
+ /* Spacing */
+ printf("\n");
+ }
+
+ free(bs);
+ free(bu1);
+ free(bu0);
+
+ return 0;
+}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.ok b/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.ok
new file mode 100644
index 0000000..2122961
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/conv/conv_test.ok
@@ -0,0 +1,55 @@
+[+] Testing: GSM xCCH (non-recursive, flushed, not punctured)
+[.] Input length : ret = 224 exp = 224 -> OK
+[.] Output length : ret = 456 exp = 456 -> OK
+[.] Pre computed vector checks:
+[..] Encoding: OK
+[..] Decoding: OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AFS 7.95 (recursive, flushed, punctured)
+[.] Input length : ret = 165 exp = 165 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Pre computed vector checks:
+[..] Encoding: OK
+[..] Decoding: OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)
+[.] Input length : ret = 48 exp = 48 -> OK
+[.] Output length : ret = 72 exp = 72 -> OK
+[.] Pre computed vector checks:
+[..] Encoding: OK
+[..] Decoding: OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: WiMax FCH (non-recursive, tail-biting, not punctured)
+[.] Input length : ret = 48 exp = 48 -> OK
+[.] Output length : ret = 96 exp = 96 -> OK
+[.] Pre computed vector checks:
+[..] Encoding: OK
+[..] Decoding: OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: ??? (non-recursive, direct truncation, not punctured)
+[.] Input length : ret = 224 exp = 224 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Pre computed vector checks:
+[..] Encoding: OK
+[..] Decoding: OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
diff --git a/Src/osmolib/src/shared/libosmocore/tests/gsm0808/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/Makefile.am
new file mode 100644
index 0000000..a238e7f
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = gsm0808_test
+EXTRA_DIST = gsm0808_test.ok
+
+gsm0808_test_SOURCES = gsm0808_test.c
+gsm0808_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c
new file mode 100644
index 0000000..7e5e97b
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c
@@ -0,0 +1,269 @@
+/*
+ * (C) 2012 by Holger Hans Peter Freyther
+ * All Rights Reserved
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <osmocom/gsm/gsm0808.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define VERIFY(msg, data, len) \
+ if (msgb_l3len(msg) != len) { \
+ printf("%s:%d Length don't match: %d vs. %d. %s\n", \
+ __func__, __LINE__, msgb_l3len(msg), len, \
+ osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
+ abort(); \
+ } else if (memcmp(msg->l3h, data, len) != 0) { \
+ printf("%s:%d didn't match: got: %s\n", \
+ __func__, __LINE__, \
+ osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
+ abort(); \
+ }
+
+
+static void test_create_layer3(void)
+{
+ static const uint8_t res[] = {
+ 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
+ 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
+ struct msgb *msg, *in_msg;
+ printf("Testing creating Layer3\n");
+
+ in_msg = msgb_alloc_headroom(512, 128, "foo");
+ in_msg->l3h = in_msg->data;
+ msgb_v_put(in_msg, 0x23);
+
+ msg = gsm0808_create_layer3(in_msg, 0x1122, 0x2244, 0x3366, 0x4488);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+ msgb_free(in_msg);
+}
+
+static void test_create_reset()
+{
+ static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
+ struct msgb *msg;
+
+ printf("Testing creating Reset\n");
+ msg = gsm0808_create_reset();
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_clear_command()
+{
+ static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
+ struct msgb *msg;
+
+ printf("Testing creating Clear Command\n");
+ msg = gsm0808_create_clear_command(0x23);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_clear_complete()
+{
+ static const uint8_t res[] = { 0x00, 0x01, 0x21 };
+ struct msgb *msg;
+
+ printf("Testing creating Clear Complete\n");
+ msg = gsm0808_create_clear_complete();
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_cipher_complete()
+{
+ static const uint8_t res1[] = {
+ 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
+ static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
+ struct msgb *l3, *msg;
+
+ printf("Testing creating Cipher Complete\n");
+ l3 = msgb_alloc_headroom(512, 128, "l3h");
+ l3->l3h = l3->data;
+ msgb_v_put(l3, 0x23);
+ msgb_v_put(l3, 0x42);
+ msgb_v_put(l3, 0x21);
+
+ /* with l3 data */
+ msg = gsm0808_create_cipher_complete(l3, 4);
+ VERIFY(msg, res1, ARRAY_SIZE(res1));
+ msgb_free(msg);
+
+ /* with l3 data but short */
+ l3->len -= 1;
+ l3->tail -= 1;
+ msg = gsm0808_create_cipher_complete(l3, 4);
+ VERIFY(msg, res2, ARRAY_SIZE(res2));
+ msgb_free(msg);
+
+ /* without l3 data */
+ msg = gsm0808_create_cipher_complete(NULL, 4);
+ VERIFY(msg, res2, ARRAY_SIZE(res2));
+ msgb_free(msg);
+
+
+ msgb_free(l3);
+}
+
+static void test_create_cipher_reject()
+{
+ static const uint8_t res[] = { 0x00, 0x02, 0x59, 0x23 };
+ struct msgb *msg;
+
+ printf("Testing creating Cipher Reject\n");
+ msg = gsm0808_create_cipher_reject(0x23);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_cm_u()
+{
+ static const uint8_t res[] = {
+ 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
+ static const uint8_t res2o[] = {
+ 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
+ struct msgb *msg;
+ const uint8_t cm2 = 0x23;
+ const uint8_t cm3 = 0x42;
+
+ printf("Testing creating CM U\n");
+ msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+
+ msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
+ VERIFY(msg, res2o, ARRAY_SIZE(res2o));
+
+ msgb_free(msg);
+}
+
+static void test_create_sapi_reject()
+{
+ static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 };
+ struct msgb *msg;
+
+ printf("Testing creating SAPI Reject\n");
+ msg = gsm0808_create_sapi_reject(3);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_ass_compl()
+{
+ static const uint8_t res1[] = {
+ 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
+ 0x11, 0x40, 0x22 };
+ static const uint8_t res2[] = {
+ 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
+ struct msgb *msg;
+
+ printf("Testing creating Assignment Complete\n");
+ msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
+ VERIFY(msg, res1, ARRAY_SIZE(res1));
+ msgb_free(msg);
+
+ msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
+ VERIFY(msg, res2, ARRAY_SIZE(res2));
+ msgb_free(msg);
+}
+
+static void test_create_ass_fail()
+{
+ static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
+ static const uint8_t res2[] = {
+ 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
+ uint8_t rr_res = 2;
+ struct msgb *msg;
+
+ printf("Testing creating Assignment Failure\n");
+ msg = gsm0808_create_assignment_failure(0x23, NULL);
+ VERIFY(msg, res1, ARRAY_SIZE(res1));
+ msgb_free(msg);
+
+ msg = gsm0808_create_assignment_failure(0x23, &rr_res);
+ VERIFY(msg, res2, ARRAY_SIZE(res2));
+ msgb_free(msg);
+}
+
+static void test_create_clear_rqst()
+{
+ static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
+ struct msgb *msg;
+
+ printf("Testing creating Clear Request\n");
+ msg = gsm0808_create_clear_rqst(0x23);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+}
+
+static void test_create_dtap()
+{
+ static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
+ struct msgb *msg, *l3;
+
+ printf("Testing creating DTAP\n");
+ l3 = msgb_alloc_headroom(512, 128, "test");
+ l3->l3h = l3->data;
+ msgb_v_put(l3, 0x23);
+ msgb_v_put(l3, 0x42);
+
+ msg = gsm0808_create_dtap(l3, 0x3);
+ VERIFY(msg, res, ARRAY_SIZE(res));
+ msgb_free(msg);
+ msgb_free(l3);
+}
+
+static void test_prepend_dtap()
+{
+ static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
+ struct msgb *in_msg;
+
+ printf("Testing prepend DTAP\n");
+
+ in_msg = msgb_alloc_headroom(512, 128, "test");
+ msgb_v_put(in_msg, 0x23);
+ msgb_v_put(in_msg, 0x42);
+
+ gsm0808_prepend_dtap_header(in_msg, 0x3);
+ in_msg->l3h = in_msg->data;
+ VERIFY(in_msg, res, ARRAY_SIZE(res));
+ msgb_free(in_msg);
+}
+
+int main(int argc, char **argv)
+{
+ printf("Testing generation of GSM0808 messages\n");
+ test_create_layer3();
+ test_create_reset();
+ test_create_clear_command();
+ test_create_clear_complete();
+ test_create_cipher_complete();
+ test_create_cipher_reject();
+ test_create_cm_u();
+ test_create_sapi_reject();
+ test_create_ass_compl();
+ test_create_ass_fail();
+ test_create_clear_rqst();
+ test_create_dtap();
+ test_prepend_dtap();
+
+ printf("Done\n");
+ return EXIT_SUCCESS;
+}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok
new file mode 100644
index 0000000..eb43126
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok
@@ -0,0 +1,15 @@
+Testing generation of GSM0808 messages
+Testing creating Layer3
+Testing creating Reset
+Testing creating Clear Command
+Testing creating Clear Complete
+Testing creating Cipher Complete
+Testing creating Cipher Reject
+Testing creating CM U
+Testing creating SAPI Reject
+Testing creating Assignment Complete
+Testing creating Assignment Failure
+Testing creating Clear Request
+Testing creating DTAP
+Testing prepend DTAP
+Done
diff --git a/Src/osmolib/src/shared/libosmocore/tests/lapd/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/lapd/Makefile.am
new file mode 100644
index 0000000..f7e2ab0
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/lapd/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+AM_FLAGS = -Wall -O0
+noinst_PROGRAMS = lapd_test
+EXTRA_DIST = lapd_test.ok
+
+lapd_test_SOURCES = lapd_test.c
+lapd_test_LDADD = \
+ $(top_builddir)/src/libosmocore.la \
+ $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.c b/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.c
new file mode 100644
index 0000000..d58bec6
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.c
@@ -0,0 +1,319 @@
+/*
+ * (C) 2011 by Holger Hans Peter Freyther
+ * (C) 2011 by On-Waves
+ * All Rights Reserved
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <osmocom/core/logging.h>
+#include <osmocom/gsm/lapdm.h>
+#include <osmocom/gsm/rsl.h>
+
+#include <errno.h>
+
+#include <string.h>
+
+#define CHECK_RC(rc) \
+ if (rc != 0) { \
+ printf("Operation failed rc=%d on %s:%d\n", rc, __FILE__, __LINE__); \
+ abort(); \
+ }
+
+#define ASSERT(exp) \
+ if (!(exp)) { \
+ printf("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
+ abort(); \
+ }
+
+
+static struct log_info info = {};
+
+struct lapdm_polling_state {
+ struct lapdm_channel *bts;
+ int bts_read;
+
+ struct lapdm_channel *ms;
+ int ms_read;
+};
+
+static struct msgb *msgb_from_array(const uint8_t *data, int len)
+{
+ struct msgb *msg = msgb_alloc_headroom(4096, 128, "data");
+ msg->l3h = msgb_put(msg, len);
+ memcpy(msg->l3h, data, len);
+ return msg;
+}
+
+/*
+ * Test data is below...
+ */
+static const uint8_t cm[] = {
+ 0x05, 0x24, 0x31, 0x03, 0x50, 0x18, 0x93, 0x08,
+ 0x29, 0x47, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80,
+};
+
+static const uint8_t cm_padded[] = {
+ 0x05, 0x24, 0x31, 0x03, 0x50, 0x18, 0x93, 0x08,
+ 0x29, 0x47, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x2b, 0x2b, 0x2b, 0x2b
+};
+
+static const uint8_t mm[] = {
+ 0x00, 0x0c, 0x00, 0x03, 0x01, 0x01, 0x20, 0x02,
+ 0x00, 0x0b, 0x00, 0x03, 0x05, 0x04, 0x0d
+};
+
+static const uint8_t dummy1[] = {
+ 0xab, 0x03, 0x30, 0x60, 0x06,
+};
+
+static struct msgb *create_cm_serv_req(void)
+{
+ struct msgb *msg;
+
+ msg = msgb_from_array(cm, sizeof(cm));
+ rsl_rll_push_l3(msg, RSL_MT_EST_REQ, 0, 0, 1);
+ return msg;
+}
+
+static struct msgb *create_mm_id_req(void)
+{
+ struct msgb *msg;
+
+ msg = msgb_from_array(mm, sizeof(mm));
+ msg->l2h = msg->data + 3;
+ ASSERT(msgb_l2len(msg) == 12);
+ msg->l3h = msg->l2h + 6;
+ ASSERT(msgb_l3len(msg) == 6);
+
+ return msg;
+}
+
+static struct msgb *create_empty_msg(void)
+{
+ struct msgb *msg;
+
+ msg = msgb_from_array(NULL, 0);
+ ASSERT(msgb_l3len(msg) == 0);
+ rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, 0, 0, 1);
+ return msg;
+}
+
+static struct msgb *create_dummy_data_req(void)
+{
+ struct msgb *msg;
+
+ msg = msgb_from_array(dummy1, sizeof(dummy1));
+ rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, 0, 0, 1);
+ return msg;
+}
+
+static int send(struct msgb *in_msg, struct lapdm_channel *chan)
+{
+ struct osmo_phsap_prim pp;
+ struct msgb *msg;
+ int rc;
+
+ msg = msgb_alloc_headroom(128, 64, "PH-DATA.ind");
+ osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA,
+ PRIM_OP_INDICATION, msg);
+ /* copy over actual MAC block */
+ msg->l2h = msgb_put(msg, msgb_l2len(in_msg));
+ memcpy(msg->l2h, in_msg->l2h, msgb_l2len(in_msg));
+
+ /* LAPDm requires those... */
+ pp.u.data.chan_nr = 0;
+ pp.u.data.link_id = 0;
+ /* feed into the LAPDm code of libosmogsm */
+ rc = lapdm_phsap_up(&pp.oph, &chan->lapdm_dcch);
+ ASSERT(rc == 0 || rc == -EBUSY);
+ return 0;
+}
+
+/*
+ * I get called from the LAPDm code when something was sent my way...
+ */
+static int bts_to_ms_tx_cb(struct msgb *in_msg, struct lapdm_entity *le, void *_ctx)
+{
+ struct lapdm_polling_state *state = _ctx;
+
+
+ printf("%s: MS->BTS(us) message %d\n", __func__, msgb_length(in_msg));
+
+
+ if (state->bts_read == 0) {
+ printf("BTS: Verifying CM request.\n");
+ ASSERT(msgb_l3len(in_msg) == ARRAY_SIZE(cm_padded));
+ ASSERT(memcmp(in_msg->l3h, cm_padded, ARRAY_SIZE(cm_padded)) == 0);
+ } else if (state->bts_read == 1) {
+ printf("BTS: Verifying dummy message.\n");
+ ASSERT(msgb_l3len(in_msg) == ARRAY_SIZE(dummy1));
+ ASSERT(memcmp(in_msg->l3h, dummy1, ARRAY_SIZE(dummy1)) == 0);
+ } else {
+ printf("BTS: Do not know to verify: %d\n", state->bts_read);
+ }
+
+ state->bts_read += 1;
+ msgb_free(in_msg);
+
+ return 0;
+}
+
+static int ms_to_bts_l1_cb(struct osmo_prim_hdr *oph, void *_ctx)
+{
+ int rc;
+ struct lapdm_polling_state *state = _ctx;
+ printf("%s: MS(us) -> BTS prim message\n", __func__);
+
+ /* i stuff it into the LAPDm channel of the BTS */
+ rc = send(oph->msg, state->bts);
+ msgb_free(oph->msg);
+}
+
+static int ms_to_bts_tx_cb(struct msgb *msg, struct lapdm_entity *le, void *_ctx)
+{
+ struct lapdm_polling_state *state = _ctx;
+
+ printf("%s: BTS->MS(us) message %d\n", __func__, msgb_length(msg));
+
+ if (state->ms_read == 0) {
+ struct abis_rsl_rll_hdr hdr;
+
+ printf("MS: Verifying incoming primitive.\n");
+ ASSERT(msg->len == sizeof(struct abis_rsl_rll_hdr) + 3);
+
+ /* verify the header */
+ memset(&hdr, 0, sizeof(hdr));
+ rsl_init_rll_hdr(&hdr, RSL_MT_EST_CONF);
+ hdr.c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
+ ASSERT(memcmp(msg->data, &hdr, sizeof(hdr)) == 0);
+
+ /* Verify the added RSL_IE_L3_INFO but we have a bug here */
+ ASSERT(msg->data[6] == RSL_IE_L3_INFO);
+ #warning "RSL_IE_L3_INFO 16 bit length is wrong"
+ /* ASSERT(msg->data[7] == 0x0 && msg->data[8] == 0x9c); */
+ /* this should be 0x0 and 0x0... but we have a bug */
+ } else if (state->ms_read == 1) {
+ printf("MS: Verifying incoming MM message: %d\n", msgb_l3len(msg));
+ ASSERT(msgb_l3len(msg) == 3);
+ ASSERT(memcmp(msg->l3h, &mm[12], msgb_l3len(msg)) == 0);
+ } else {
+ printf("MS: Do not know to verify: %d\n", state->ms_read);
+ }
+
+ state->ms_read += 1;
+ msgb_free(msg);
+ return 0;
+}
+
+static void test_lapdm_polling()
+{
+ printf("I do some very simple LAPDm test.\n");
+
+ int rc;
+ struct lapdm_polling_state test_state;
+ struct osmo_phsap_prim pp;
+
+ /* Configure LAPDm on both sides */
+ struct lapdm_channel bts_to_ms_channel;
+ struct lapdm_channel ms_to_bts_channel;
+ memset(&bts_to_ms_channel, 0, sizeof(bts_to_ms_channel));
+ memset(&ms_to_bts_channel, 0, sizeof(ms_to_bts_channel));
+
+ memset(&test_state, 0, sizeof(test_state));
+ test_state.bts = &bts_to_ms_channel;
+ test_state.ms = &ms_to_bts_channel;
+
+ /* BTS to MS in polling mode */
+ lapdm_channel_init(&bts_to_ms_channel, LAPDM_MODE_BTS);
+ lapdm_channel_set_flags(&bts_to_ms_channel, LAPDM_ENT_F_POLLING_ONLY);
+ lapdm_channel_set_l1(&bts_to_ms_channel, NULL, &test_state);
+ lapdm_channel_set_l3(&bts_to_ms_channel, bts_to_ms_tx_cb, &test_state);
+
+ /* MS to BTS in direct mode */
+ lapdm_channel_init(&ms_to_bts_channel, LAPDM_MODE_MS);
+ lapdm_channel_set_l1(&ms_to_bts_channel, ms_to_bts_l1_cb, &test_state);
+ lapdm_channel_set_l3(&ms_to_bts_channel, ms_to_bts_tx_cb, &test_state);
+
+ /*
+ * We try to send messages from the MS to the BTS to the MS..
+ */
+ /* 1. Start with MS -> BTS, BTS should have a pending message */
+ printf("Establishing link.\n");
+ lapdm_rslms_recvmsg(create_cm_serv_req(), &ms_to_bts_channel);
+
+ /* 2. Poll on the BTS for sending out a confirmation */
+ printf("\nConfirming\n");
+ ASSERT(test_state.bts_read == 1)
+ rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
+ CHECK_RC(rc);
+ ASSERT(pp.oph.msg->data == pp.oph.msg->l2h);
+ send(pp.oph.msg, &ms_to_bts_channel);
+ msgb_free(pp.oph.msg);
+ ASSERT(test_state.ms_read == 1);
+
+ /* 3. Send some data to the MS */
+ printf("\nSending back to MS\n");
+ lapdm_rslms_recvmsg(create_mm_id_req(), &bts_to_ms_channel);
+ rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
+ CHECK_RC(rc);
+ send(pp.oph.msg, &ms_to_bts_channel);
+ msgb_free(pp.oph.msg);
+ ASSERT(test_state.ms_read == 2);
+
+ /* verify that there is nothing more to poll */
+ rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
+ ASSERT(rc < 0);
+
+ /* 3. And back to the BTS */
+ printf("\nSending back to BTS\n");
+ ASSERT(test_state.ms_read == 2);
+ lapdm_rslms_recvmsg(create_dummy_data_req(), &ms_to_bts_channel);
+
+
+ /* 4. And back to the MS, but let's move data/l2h apart */
+ ASSERT(test_state.bts_read == 2)
+ ASSERT(test_state.ms_read == 2);
+ rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
+ CHECK_RC(rc);
+ send(pp.oph.msg, &ms_to_bts_channel);
+ ASSERT(test_state.ms_read == 2);
+ msgb_free(pp.oph.msg);
+
+ /* verify that there is nothing more to poll */
+ rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
+ ASSERT(rc < 0);
+
+ /* check sending an empty L3 message fails */
+ rc = lapdm_rslms_recvmsg(create_empty_msg(), &bts_to_ms_channel);
+ ASSERT(rc == -1);
+ ASSERT(test_state.ms_read == 2);
+
+ /* clean up */
+ lapdm_channel_exit(&bts_to_ms_channel);
+ lapdm_channel_exit(&ms_to_bts_channel);
+}
+
+int main(int argc, char **argv)
+{
+ osmo_init_logging(&info);
+
+ test_lapdm_polling();
+ printf("Success.\n");
+
+ return 0;
+}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.ok b/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.ok
new file mode 100644
index 0000000..d67a0a8
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/lapd/lapd_test.ok
@@ -0,0 +1,20 @@
+I do some very simple LAPDm test.
+Establishing link.
+ms_to_bts_l1_cb: MS(us) -> BTS prim message
+bts_to_ms_tx_cb: MS->BTS(us) message 29
+BTS: Verifying CM request.
+
+Confirming
+ms_to_bts_tx_cb: BTS->MS(us) message 9
+MS: Verifying incoming primitive.
+
+Sending back to MS
+ms_to_bts_tx_cb: BTS->MS(us) message 12
+MS: Verifying incoming MM message: 3
+ms_to_bts_l1_cb: MS(us) -> BTS prim message
+
+Sending back to BTS
+ms_to_bts_l1_cb: MS(us) -> BTS prim message
+bts_to_ms_tx_cb: MS->BTS(us) message 14
+BTS: Verifying dummy message.
+Success.
diff --git a/Src/osmolib/src/shared/libosmocore/tests/msgfile/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/msgfile/Makefile.am
index c9f4bec..88c355d 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/msgfile/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/msgfile/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = msgfile_test
+EXTRA_DIST = msgfile_test.ok msgconfig.cfg
msgfile_test_SOURCES = msgfile_test.c
msgfile_test_LDADD = $(top_builddir)/src/libosmocore.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/msgfile/msgfile_test.ok b/Src/osmolib/src/shared/libosmocore/tests/msgfile/msgfile_test.ok
new file mode 100644
index 0000000..c47cd74
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/msgfile/msgfile_test.ok
@@ -0,0 +1 @@
+Entry '*:*::Hello Welt'
diff --git a/Src/osmolib/src/shared/libosmocore/tests/sms/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/sms/Makefile.am
index fa4e387..02860af 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/sms/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/sms/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = sms_test
+EXTRA_DIST = sms_test.ok
sms_test_SOURCES = sms_test.c
sms_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/sms/sms_test.ok b/Src/osmolib/src/shared/libosmocore/tests/sms/sms_test.ok
new file mode 100644
index 0000000..d0e0983
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/sms/sms_test.ok
@@ -0,0 +1,2 @@
+SMS testing
+OK
diff --git a/Src/osmolib/src/shared/libosmocore/tests/smscb/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/smscb/Makefile.am
index 9a6fb4f..7045ea7 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/smscb/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/smscb/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = smscb_test
+EXTRA_DIST = smscb_test.ok
smscb_test_SOURCES = smscb_test.c
smscb_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/smscb/smscb_test.ok b/Src/osmolib/src/shared/libosmocore/tests/smscb/smscb_test.ok
new file mode 100644
index 0000000..347037f
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/smscb/smscb_test.ok
@@ -0,0 +1,4 @@
+(srl) GS: 1 MSG_CODE: 1 UPDATE: 0
+(msg) msg_id: 1293
+(dcs) group: 1 language: 0
+(pge) page total: 1 current: 1
diff --git a/Src/osmolib/src/shared/libosmocore/tests/testsuite.at b/Src/osmolib/src/shared/libosmocore/tests/testsuite.at
new file mode 100644
index 0000000..69624c1
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/testsuite.at
@@ -0,0 +1,73 @@
+AT_INIT
+AT_BANNER([Regression tests.])
+
+
+# todo.. create one macro for it
+AT_SETUP([a5])
+AT_KEYWORDS([a5])
+cat $abs_srcdir/a5/a5_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/a5/a5_test], [], [expout])
+AT_CLEANUP
+
+AT_SETUP([bits])
+AT_KEYWORDS([bits])
+cat $abs_srcdir/bits/bitrev_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/bits/bitrev_test], [], [expout])
+AT_CLEANUP
+
+AT_SETUP([conv])
+AT_KEYWORDS([conv])
+cat $abs_srcdir/conv/conv_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/conv/conv_test], [], [expout])
+AT_CLEANUP
+
+if ENABLE_MSGFILE
+AT_SETUP([msgfile])
+AT_KEYWORDS([msgfile])
+cp $abs_srcdir/msgfile/msgconfig.cfg .
+cat $abs_srcdir/msgfile/msgfile_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/msgfile/msgfile_test], [], [expout])
+AT_CLEANUP
+endif
+
+AT_SETUP([sms])
+AT_KEYWORDS([sms])
+cat $abs_srcdir/sms/sms_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/sms/sms_test], [], [expout])
+AT_CLEANUP
+
+AT_SETUP([smscb])
+AT_KEYWORDS([smscb])
+cat $abs_srcdir/smscb/smscb_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/smscb/smscb_test], [], [expout])
+AT_CLEANUP
+
+AT_SETUP([timer])
+AT_KEYWORDS([timer])
+cat $abs_srcdir/timer/timer_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/timer/timer_test -s 5], [], [expout], [ignore])
+AT_CLEANUP
+
+AT_SETUP([ussd])
+AT_KEYWORDS([ussd])
+cat $abs_srcdir/ussd/ussd_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/ussd/ussd_test], [], [expout], [ignore])
+AT_CLEANUP
+
+AT_SETUP([auth])
+AT_KEYWORDS([auth])
+cat $abs_srcdir/auth/milenage_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/auth/milenage_test], [], [expout], [ignore])
+AT_CLEANUP
+
+AT_SETUP([lapd])
+AT_KEYWORDS([lapd])
+cat $abs_srcdir/lapd/lapd_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/lapd/lapd_test], [], [expout], [ignore])
+AT_CLEANUP
+
+AT_SETUP([gsm0808])
+AT_KEYWORDS([gsm0808])
+cat $abs_srcdir/gsm0808/gsm0808_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/gsm0808/gsm0808_test], [], [expout], [ignore])
+AT_CLEANUP
diff --git a/Src/osmolib/src/shared/libosmocore/tests/timer/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/timer/Makefile.am
index d3decf5..062d81b 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/timer/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/timer/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = timer_test
+EXTRA_DIST = timer_test.ok
timer_test_SOURCES = timer_test.c
timer_test_LDADD = $(top_builddir)/src/libosmocore.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.c b/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.c
index 240bc48..3775151 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.c
+++ b/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.c
@@ -1,7 +1,11 @@
/*
* (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011 by Harald Welte <laforge@gnumonks.org>
* All Rights Reserved
*
+ * Authors: Holger Hans Peter Freyther <zecke@selfish.org>
+ * Pablo Neira Ayuso <pablo@gnumonks.org>
+ *
* 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
@@ -19,59 +23,169 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <getopt.h>
+#include <osmocom/core/talloc.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/select.h>
+#include <osmocom/core/linuxlist.h>
#include "../../config.h"
-static void timer_fired(void *data);
+static void main_timer_fired(void *data);
+static void secondary_timer_fired(void *data);
-static struct osmo_timer_list timer_one = {
- .cb = timer_fired,
- .data = (void*)1,
+static unsigned int main_timer_step = 0;
+static struct osmo_timer_list main_timer = {
+ .cb = main_timer_fired,
+ .data = &main_timer_step,
};
-static struct osmo_timer_list timer_two = {
- .cb = timer_fired,
- .data = (void*)2,
-};
+static LLIST_HEAD(timer_test_list);
-static struct osmo_timer_list timer_three = {
- .cb = timer_fired,
- .data = (void*)3,
+struct test_timer {
+ struct llist_head head;
+ struct osmo_timer_list timer;
+ struct timeval start;
+ struct timeval stop;
};
-static void timer_fired(void *_data)
+/* number of test steps. We add fact(steps) timers in the whole test. */
+#define MAIN_TIMER_NSTEPS 16
+
+/* time between two steps, in secs. */
+#define TIME_BETWEEN_STEPS 1
+
+/* timer imprecision that we accept for this test: 10 milliseconds. */
+#define TIMER_PRES_SECS 0
+#define TIMER_PRES_USECS 10000
+
+static int timer_nsteps = MAIN_TIMER_NSTEPS;
+static unsigned int expired_timers = 0;
+static unsigned int total_timers = 0;
+static unsigned int too_late = 0;
+
+static void main_timer_fired(void *data)
{
- unsigned long data = (unsigned long) _data;
- printf("Fired timer: %lu\n", data);
-
- if (data == 1) {
- osmo_timer_schedule(&timer_one, 3, 0);
- osmo_timer_del(&timer_two);
- } else if (data == 2) {
- printf("Should not be fired... bug in del_timer\n");
- } else if (data == 3) {
- printf("Timer fired not registering again\n");
- } else {
- printf("wtf... wrong data\n");
- }
+ unsigned int *step = data;
+ unsigned int add_in_this_step;
+ int i;
+
+ if (*step == timer_nsteps) {
+ fprintf(stderr, "Main timer has finished, please, "
+ "wait a bit for the final report.\n");
+ return;
+ }
+ /* add 2^step pair of timers per step. */
+ add_in_this_step = (1 << *step);
+
+ for (i=0; i<add_in_this_step; i++) {
+ struct test_timer *v;
+
+ v = talloc_zero(NULL, struct test_timer);
+ if (v == NULL) {
+ fprintf(stderr, "timer_test: OOM!\n");
+ return;
+ }
+ gettimeofday(&v->start, NULL);
+ v->timer.cb = secondary_timer_fired;
+ v->timer.data = v;
+ unsigned int seconds = (random() % 10) + 1;
+ v->stop.tv_sec = v->start.tv_sec + seconds;
+ osmo_timer_schedule(&v->timer, seconds, 0);
+ llist_add(&v->head, &timer_test_list);
+ }
+ fprintf(stderr, "added %d timers in step %u (expired=%u)\n",
+ add_in_this_step, *step, expired_timers);
+ total_timers += add_in_this_step;
+ osmo_timer_schedule(&main_timer, TIME_BETWEEN_STEPS, 0);
+ (*step)++;
}
-int main(int argc, char** argv)
+static void secondary_timer_fired(void *data)
{
- printf("Starting... timer\n");
+ struct test_timer *v = data, *this, *tmp;
+ struct timeval current, res, precision = { 1, 0 };
+
+ gettimeofday(&current, NULL);
+
+ timersub(&current, &v->stop, &res);
+ if (timercmp(&res, &precision, >)) {
+ fprintf(stderr, "ERROR: timer %p has expired too late!\n",
+ v->timer);
+ too_late++;
+ }
+
+ llist_del(&v->head);
+ talloc_free(data);
+ expired_timers++;
+ if (expired_timers == total_timers) {
+ fprintf(stdout, "test over: added=%u expired=%u too_late=%u \n",
+ total_timers, expired_timers, too_late);
+ exit(EXIT_SUCCESS);
+ }
+
+ /* randomly (10%) deletion of timers. */
+ llist_for_each_entry_safe(this, tmp, &timer_test_list, head) {
+ if ((random() % 100) < 10) {
+ osmo_timer_del(&this->timer);
+ llist_del(&this->head);
+ talloc_free(this);
+ expired_timers++;
+ }
+ }
+}
+
+static void alarm_handler(int signum)
+{
+ fprintf(stderr, "ERROR: We took too long to run the timer test, "
+ "something seems broken, aborting.\n");
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char *argv[])
+{
+ int c;
+
+ if (signal(SIGALRM, alarm_handler) == SIG_ERR) {
+ perror("cannot register signal handler");
+ exit(EXIT_FAILURE);
+ }
+
+ while ((c = getopt_long(argc, argv, "s:", NULL, NULL)) != -1) {
+ switch(c) {
+ case 's':
+ timer_nsteps = atoi(optarg);
+ if (timer_nsteps <= 0) {
+ fprintf(stderr, "%s: steps must be > 0\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ fprintf(stdout, "Running timer test for %u steps, accepting "
+ "imprecision of %u.%.6u seconds\n",
+ timer_nsteps, TIMER_PRES_SECS, TIMER_PRES_USECS);
+
+ osmo_timer_schedule(&main_timer, 1, 0);
- osmo_timer_schedule(&timer_one, 3, 0);
- osmo_timer_schedule(&timer_two, 5, 0);
- osmo_timer_schedule(&timer_three, 4, 0);
+ /* if the test takes too long, we may consider that the timer scheduler
+ * has hung. We set some maximum wait time which is the double of the
+ * maximum timeout randomly set (10 seconds, worst case) plus the
+ * number of steps (since some of them are reset each step). */
+ alarm(2 * (10 + timer_nsteps));
#ifdef HAVE_SYS_SELECT_H
- while (1) {
- osmo_select_main(0);
- }
+ while (1) {
+ osmo_select_main(0);
+ }
#else
- printf("Select not supported on this platform!\n");
+ fprintf(stdout, "Select not supported on this platform!\n");
#endif
}
diff --git a/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.ok b/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.ok
new file mode 100644
index 0000000..b4e0e11
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/timer/timer_test.ok
@@ -0,0 +1,2 @@
+Running timer test for 5 steps, accepting imprecision of 0.010000 seconds
+test over: added=31 expired=31 too_late=0
diff --git a/Src/osmolib/src/shared/libosmocore/tests/ussd/Makefile.am b/Src/osmolib/src/shared/libosmocore/tests/ussd/Makefile.am
index ef9aa49..de9ff89 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/ussd/Makefile.am
+++ b/Src/osmolib/src/shared/libosmocore/tests/ussd/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
noinst_PROGRAMS = ussd_test
+EXTRA_DIST = ussd_test.ok
ussd_test_SOURCES = ussd_test.c
ussd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.c b/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.c
index 6d2a8c9..55384f1 100644
--- a/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.c
+++ b/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.c
@@ -19,6 +19,8 @@
*
*/
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
#include <osmocom/gsm/gsm0480.h>
#include <stdio.h>
#include <stdlib.h>
@@ -64,12 +66,16 @@ static int parse_mangle_ussd(const uint8_t *_data, int len)
return rc;
}
+struct log_info info = {};
+
int main(int argc, char **argv)
{
struct ussd_request req;
const int size = sizeof(ussd_request);
int i;
+ osmo_init_logging(&info);
+
gsm0480_decode_ussd_request((struct gsm48_hdr *) ussd_request, size, &req);
printf("Tested if it still works. Text was: %s\n", req.text);
diff --git a/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.ok b/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.ok
new file mode 100644
index 0000000..1b6316e
--- /dev/null
+++ b/Src/osmolib/src/shared/libosmocore/tests/ussd/ussd_test.ok
@@ -0,0 +1,53 @@
+Tested if it still works. Text was: **321#
+Testing parsing a USSD request and truncated versions
+Result for 1 is 28
+Result for 1 is 27
+Result for 1 is 26
+Result for 1 is 25
+Result for 0 is 24
+Result for 0 is 23
+Result for 0 is 22
+Result for 0 is 21
+Result for 0 is 20
+Result for 0 is 19
+Result for 0 is 18
+Result for 0 is 17
+Result for 0 is 16
+Result for 0 is 15
+Result for 0 is 14
+Result for 0 is 13
+Result for 0 is 12
+Result for 0 is 11
+Result for 0 is 10
+Result for 0 is 9
+Result for 0 is 8
+Result for 0 is 7
+Result for 0 is 6
+Result for 0 is 5
+Result for 0 is 4
+Result for 0 is 3
+Mangling the container now
+Result for 0 is 28
+Result for 0 is 27
+Result for 1 is 26
+Result for 1 is 25
+Result for 0 is 24
+Result for 0 is 23
+Result for 0 is 22
+Result for 0 is 21
+Result for 0 is 20
+Result for 0 is 19
+Result for 0 is 18
+Result for 0 is 17
+Result for 0 is 16
+Result for 0 is 15
+Result for 0 is 14
+Result for 0 is 13
+Result for 0 is 12
+Result for 0 is 11
+Result for 0 is 10
+Result for 0 is 9
+Result for 0 is 8
+Result for 0 is 7
+Result for 0 is 6
+Result for 1 is 5