aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2013-02-05 11:52:38 +0100
committerHarald Welte <laforge@gnumonks.org>2015-09-22 16:41:24 +0200
commit1de7085d3181b8d29929e80f29448e2c7d6eda3b (patch)
treea5f00a7961c940928f508506df2b7095d358395a /tests
parentacc71ffb4b61b3354bbb2fa14981e4e6a46946e6 (diff)
Add test code for testing GSM burst transcoding
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/bursts/Makefile.am8
-rw-r--r--tests/bursts/bursts_test.c210
-rw-r--r--tests/bursts/bursts_test.ok1
-rw-r--r--tests/testsuite.at6
5 files changed, 226 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 955d8f37..70055909 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = paging cipher agch misc
+SUBDIRS = paging cipher agch misc bursts
if ENABLE_SYSMOBTS
SUBDIRS += sysmobts
diff --git a/tests/bursts/Makefile.am b/tests/bursts/Makefile.am
new file mode 100644
index 00000000..9f88f9b9
--- /dev/null
+++ b/tests/bursts/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS)
+noinst_PROGRAMS = bursts_test
+EXTRA_DIST = bursts_test.ok
+
+bursts_test_SOURCES = bursts_test.c $(top_builddir)/src/osmo-bts-trx/xcch.c $(top_builddir)/src/osmo-bts-trx/rach.c $(top_builddir)/src/osmo-bts-trx/sch.c
+bursts_test_LDADD = $(LDADD)
diff --git a/tests/bursts/bursts_test.c b/tests/bursts/bursts_test.c
new file mode 100644
index 00000000..07769133
--- /dev/null
+++ b/tests/bursts/bursts_test.c
@@ -0,0 +1,210 @@
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/utils.h>
+
+#include "../../src/osmo-bts-trx/xcch.h"
+#include "../../src/osmo-bts-trx/rach.h"
+#include "../../src/osmo-bts-trx/sch.h"
+
+
+#define ASSERT_TRUE(rc) \
+ if (!(rc)) { \
+ printf("Assert failed in %s:%d.\n", \
+ __FILE__, __LINE__); \
+ abort(); \
+ }
+
+/* set condition to 1, to show debugging */
+#define printd if (0) printf
+
+static int ubits2sbits(ubit_t *ubits, sbit_t *sbits, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if ((*ubits++) & 1)
+ *sbits++ = -127;
+ else
+ *sbits++ = 127;
+ }
+
+ return count;
+}
+
+static void test_xcch(uint8_t *l2)
+{
+ uint8_t result[23];
+ ubit_t bursts_u[116 * 4];
+ sbit_t bursts_s[116 * 4];
+
+ printd("Encoding: %s\n", osmo_hexdump(l2, 23));
+
+ /* encode */
+ xcch_encode(bursts_u, l2);
+
+ printd("U-Bits:\n");
+ printd("%s %02x %02x %s\n", osmo_hexdump(bursts_u, 57),
+ bursts_u[57], bursts_u[58],
+ osmo_hexdump(bursts_u + 59, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump(bursts_u + 116, 57),
+ bursts_u[57 + 116], bursts_u[58 + 116],
+ osmo_hexdump(bursts_u + 59 + 116, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump(bursts_u + 232, 57),
+ bursts_u[57 + 232], bursts_u[58 + 232],
+ osmo_hexdump(bursts_u + 59 + 232, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump(bursts_u + 348, 57),
+ bursts_u[57 + 348], bursts_u[58 + 348],
+ osmo_hexdump(bursts_u + 59 + 348, 57));
+ ubits2sbits(bursts_u, bursts_s, 116 * 4);
+ printd("S-Bits:\n");
+ printd("%s %02x %02x %s\n", osmo_hexdump((uint8_t *)bursts_s, 57),
+ (uint8_t)bursts_s[57], (uint8_t)bursts_s[58],
+ osmo_hexdump((uint8_t *)bursts_s + 59, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump((uint8_t *)bursts_s + 116, 57),
+ (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116],
+ osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump((uint8_t *)bursts_s + 232, 57),
+ (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232],
+ osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57));
+ printd("%s %02x %02x %s\n", osmo_hexdump((uint8_t *)bursts_s + 348, 57),
+ (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348],
+ osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57));
+
+ /* destroy */
+ memset(bursts_s, 0, 30);
+ memset(bursts_s + 116, 0, 30);
+
+ /* decode */
+ xcch_decode(result, bursts_s);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, 23));
+
+ ASSERT_TRUE(!memcmp(l2, result, 23));
+
+ printd("\n");
+}
+
+static void test_rach(uint8_t bsic, uint8_t ra)
+{
+ uint8_t result;
+ ubit_t bursts_u[36];
+ sbit_t bursts_s[36];
+
+ printd("Encoding: %02x\n", ra);
+
+ /* encode */
+ rach_encode(bursts_u, &ra, bsic);
+
+ printd("U-Bits:\n");
+ printd("%s\n", osmo_hexdump(bursts_u, 36));
+ ubits2sbits(bursts_u, bursts_s, 36);
+ printd("S-Bits:\n");
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s, 36));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 8);
+
+ /* decode */
+ rach_decode(&result, bursts_s, bsic);
+
+ printd("Decoded: %02x\n", result);
+
+ ASSERT_TRUE(ra == result);
+
+ printd("\n");
+}
+
+static void test_sch(uint8_t *info)
+{
+ uint8_t result[4];
+ ubit_t bursts_u[78];
+ sbit_t bursts_s[78];
+
+ /* zero bits 25 and above */
+ info[3] &= 1;
+ result[3] = 0;
+
+ printd("Encoding: %s\n", osmo_hexdump(info, 4));
+
+ /* encode */
+ sch_encode(bursts_u, info);
+
+ printd("U-Bits:\n");
+ printd("%s\n", osmo_hexdump(bursts_u, 78));
+ ubits2sbits(bursts_u, bursts_s, 78);
+ printd("S-Bits:\n");
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s, 78));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 10);
+
+ /* decode */
+ sch_decode(result, bursts_s);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, 4));
+
+ ASSERT_TRUE(!memcmp(info, result, 4));
+
+ printd("\n");
+}
+
+uint8_t test_l2[][23] = {
+ /* dummy frame */
+ { 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ /* random frame */
+ { 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab,
+ 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92,
+ 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0x59, 0xa8 },
+ /* jolly frame */
+ { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
+};
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_xcch(test_l2[i]);
+
+ for (i = 0; i < 256; i++) {
+ test_rach(0x3f, i);
+ test_rach(0x00, i);
+ test_rach(0x1a, i);
+ }
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_sch(test_l2[i]);
+
+ printf("Success\n");
+
+ return 0;
+}
+
diff --git a/tests/bursts/bursts_test.ok b/tests/bursts/bursts_test.ok
new file mode 100644
index 00000000..35821117
--- /dev/null
+++ b/tests/bursts/bursts_test.ok
@@ -0,0 +1 @@
+Success
diff --git a/tests/testsuite.at b/tests/testsuite.at
index b528335f..e8f5d168 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -24,3 +24,9 @@ AT_KEYWORDS([misc])
cat $abs_srcdir/misc/misc_test.ok > expout
AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/misc/misc_test], [], [expout], [ignore])
AT_CLEANUP
+
+AT_SETUP([bursts])
+AT_KEYWORDS([bursts])
+cat $abs_srcdir/cipher/bursts_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/bursts/bursts_test], [], [expout], [ignore])
+AT_CLEANUP