diff options
author | Harald Welte <laforge@gnumonks.org> | 2015-09-22 16:41:54 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2015-09-22 16:41:54 +0200 |
commit | f1fb0fa3af174c605f60458388bba61ef4f40fa8 (patch) | |
tree | 006e46f78dee0ac14ffd321e0bfae344d8160096 /tests | |
parent | 329085a8ff2c1162a32eb617068fa5614efcde06 (diff) | |
parent | caa648d92e48a05e676e87b48c21cb0b151c9b4e (diff) |
Merge branch '201509-trx-rebase'0.4.0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 10 | ||||
-rw-r--r-- | tests/bursts/Makefile.am | 14 | ||||
-rw-r--r-- | tests/bursts/bursts_test.c | 495 | ||||
-rw-r--r-- | tests/bursts/bursts_test.ok | 21 | ||||
-rw-r--r-- | tests/handover/Makefile.am | 8 | ||||
-rw-r--r-- | tests/handover/handover_test.c | 278 | ||||
-rw-r--r-- | tests/handover/handover_test.ok | 1 | ||||
-rw-r--r-- | tests/stubs.c | 3 | ||||
-rw-r--r-- | tests/sysmobts/sysmobts_test.c | 2 | ||||
-rw-r--r-- | tests/testsuite.at | 12 |
10 files changed, 843 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 633b6a4a..7904486d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,12 @@ -SUBDIRS = paging cipher sysmobts agch misc +SUBDIRS = paging cipher agch misc bursts handover + +if ENABLE_SYSMOBTS +SUBDIRS += sysmobts +endif + +if ENABLE_SYSMOBTS +SUBDIRS += sysmobts +endif # The `:;' works around a Bash 3.2 bug when the output is not writeable. $(srcdir)/package.m4: $(top_srcdir)/configure.ac diff --git a/tests/bursts/Makefile.am b/tests/bursts/Makefile.am new file mode 100644 index 00000000..462b7288 --- /dev/null +++ b/tests/bursts/Makefile.am @@ -0,0 +1,14 @@ +AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) +AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) +LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) +noinst_PROGRAMS = bursts_test +EXTRA_DIST = bursts_test.ok + +bursts_test_SOURCES = bursts_test.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_coding.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_conv.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_interleaving.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_mapping.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_tables.c \ + $(top_builddir)/src/osmo-bts-trx/gsm0503_parity.c +bursts_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD) diff --git a/tests/bursts/bursts_test.c b/tests/bursts/bursts_test.c new file mode 100644 index 00000000..cc0eacff --- /dev/null +++ b/tests/bursts/bursts_test.c @@ -0,0 +1,495 @@ +/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu> + * (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co> + * + * 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/gsm0503_coding.h" + +#include <osmo-bts/logging.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 == 0x23) { + ubits++; + sbits++; + continue; + } + 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]; + int n_errors, n_bits_total; + + printd("Encoding: %s\n", osmo_hexdump(l2, 23)); + + /* encode */ + xcch_encode(bursts_u, l2); + + printd("U-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57), + bursts_u[57], bursts_u[58]); + printd("%s\n", osmo_hexdump(bursts_u + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57), + bursts_u[57 + 116], bursts_u[58 + 116]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57), + bursts_u[57 + 232], bursts_u[58 + 232]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57), + bursts_u[57 + 348], bursts_u[58 + 348]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57)); + ubits2sbits(bursts_u, bursts_s, 116 * 4); + printd("S-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57), + (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57), + (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57), + (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57), + (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]); + printd("%s\n", 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, &n_errors, &n_bits_total); + + ASSERT_TRUE(n_bits_total == 456); + + printd("Decoded: %s\n", osmo_hexdump(result, 23)); + printf("xcch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n", + n_errors, n_bits_total, (float)n_errors/n_bits_total); + + 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"); +} + +static void test_fr(uint8_t *speech, int len) +{ + uint8_t result[33]; + ubit_t bursts_u[116 * 8]; + sbit_t bursts_s[116 * 8]; + int n_errors, n_bits_total; + int rc; + + memset(bursts_u, 0x23, sizeof(bursts_u)); + memset(bursts_s, 0, sizeof(bursts_s)); + + printd("Encoding: %s\n", osmo_hexdump(speech, len)); + + /* encode */ + tch_fr_encode(bursts_u, speech, len, 1); + + printd("U-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57), + bursts_u[57], bursts_u[58]); + printd("%s\n", osmo_hexdump(bursts_u + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57), + bursts_u[57 + 116], bursts_u[58 + 116]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57), + bursts_u[57 + 232], bursts_u[58 + 232]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57), + bursts_u[57 + 348], bursts_u[58 + 348]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 464, 57), + bursts_u[57 + 464], bursts_u[58 + 464]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 580, 57), + bursts_u[57 + 580], bursts_u[58 + 580]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 696, 57), + bursts_u[57 + 696], bursts_u[58 + 696]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 696, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 812, 57), + bursts_u[57 + 812], bursts_u[58 + 812]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 812, 57)); + ubits2sbits(bursts_u, bursts_s, 116 * 8); + printd("S-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57), + (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57), + (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57), + (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57), + (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 464, 57), + (uint8_t)bursts_s[57 + 464], (uint8_t)bursts_s[58 + 464]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 464, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 580, 57), + (uint8_t)bursts_s[57 + 580], (uint8_t)bursts_s[58 + 580]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 580, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 696, 57), + (uint8_t)bursts_s[57 + 696], (uint8_t)bursts_s[58 + 696]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 696, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 812, 57), + (uint8_t)bursts_s[57 + 812], (uint8_t)bursts_s[58 + 812]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 812, 57)); + + /* destroy */ + memset(bursts_s + 6, 0, 20); + + /* decode */ + rc = tch_fr_decode(result, bursts_s, 1, len == 31, &n_errors, &n_bits_total); + + ASSERT_TRUE(rc == len); + + printd("Decoded: %s\n", osmo_hexdump(result, len)); + printf("tch_fr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n", + n_errors, n_bits_total, (float)n_errors/n_bits_total); + + ASSERT_TRUE(!memcmp(speech, result, len)); + + printd("\n"); +} + +static void test_hr(uint8_t *speech, int len) +{ + uint8_t result[23]; + ubit_t bursts_u[116 * 6]; + sbit_t bursts_s[116 * 6]; + int n_errors, n_bits_total; + int rc; + + memset(bursts_u, 0x23, sizeof(bursts_u)); + memset(bursts_s, 0, sizeof(bursts_s)); + + printd("Encoding: %s\n", osmo_hexdump(speech, len)); + + /* encode */ + tch_hr_encode(bursts_u, speech, len); + + printd("U-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57), + bursts_u[57], bursts_u[58]); + printd("%s\n", osmo_hexdump(bursts_u + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57), + bursts_u[57 + 116], bursts_u[58 + 116]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57), + bursts_u[57 + 232], bursts_u[58 + 232]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57), + bursts_u[57 + 348], bursts_u[58 + 348]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 464, 57), + bursts_u[57 + 464], bursts_u[58 + 464]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 580, 57), + bursts_u[57 + 580], bursts_u[58 + 580]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57)); + ubits2sbits(bursts_u, bursts_s, 116 * 6); + printd("S-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57), + (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57), + (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57), + (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57), + (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 464, 57), + (uint8_t)bursts_s[57 + 464], (uint8_t)bursts_s[58 + 464]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 464, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 580, 57), + (uint8_t)bursts_s[57 + 580], (uint8_t)bursts_s[58 + 580]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 580, 57)); + + /* destroy */ + memset(bursts_s + 6, 0, 20); + + /* decode */ + rc = tch_hr_decode(result, bursts_s, 0, &n_errors, &n_bits_total); + + ASSERT_TRUE(rc == len); + + printd("Decoded: %s\n", osmo_hexdump(result, len)); + printf("tch_hr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n", + n_errors, n_bits_total, (float)n_errors/n_bits_total); + + ASSERT_TRUE(!memcmp(speech, result, len)); + + printd("\n"); +} + +static void test_pdtch(uint8_t *l2, int len) +{ + uint8_t result[len]; + ubit_t bursts_u[116 * 4]; + sbit_t bursts_s[116 * 4]; + int n_errors, n_bits_total; + int rc; + + /* zero the not coded tail bits */ + switch (len) { + case 34: + case 54: + l2[len - 1] &= 0x7f; + result[len - 1] &= 0x7f; + break; + case 40: + l2[len - 1] &= 0x07; + result[len - 1] &= 0x07; + break; + } + + printd("Encoding: %s\n", osmo_hexdump(l2, len)); + + /* encode */ + pdtch_encode(bursts_u, l2, len); + + printd("U-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57), + bursts_u[57], bursts_u[58]); + printd("%s\n", osmo_hexdump(bursts_u + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57), + bursts_u[57 + 116], bursts_u[58 + 116]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57), + bursts_u[57 + 232], bursts_u[58 + 232]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57), + bursts_u[57 + 348], bursts_u[58 + 348]); + printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57)); + ubits2sbits(bursts_u, bursts_s, 116 * 4); + printd("S-Bits:\n"); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57), + (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57), + (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57), + (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57)); + printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57), + (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]); + printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57)); + + /* decode */ + rc = pdtch_decode(result, bursts_s, NULL, &n_errors, &n_bits_total); + + ASSERT_TRUE(rc == len); + + printd("Decoded: %s\n", osmo_hexdump(result, len)); + printf("pdtch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n", + n_errors, n_bits_total, (float)n_errors/n_bits_total); + + ASSERT_TRUE(!memcmp(l2, result, len)); + + 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 }, +}; + +uint8_t test_macblock[][54] = { + /* 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, 0x42, + 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, + 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, + 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92, + 0xfa, 0x27, 0x5d, 0x71, 0x7a, 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 }, +}; + +uint8_t test_speech_fr[33]; +uint8_t test_speech_efr[31]; +uint8_t test_speech_hr[15]; + +int main(int argc, char **argv) +{ + int i; + + bts_log_init(NULL); + + 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]); + + for (i = 0; i < sizeof(test_speech_fr); i++) + test_speech_fr[i] = i; + test_speech_fr[0] = 0xd0; + test_fr(test_speech_fr, sizeof(test_speech_fr)); + + for (i = 0; i < sizeof(test_speech_efr); i++) + test_speech_efr[i] = i; + test_speech_efr[0] = 0xc0; + test_fr(test_speech_efr, sizeof(test_speech_efr)); + + for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++) + test_fr(test_l2[i], sizeof(test_l2[0])); + + for (i = 0; i < sizeof(test_speech_hr); i++) + test_speech_hr[i] = i*17; + test_speech_hr[0] = 0x00; + test_hr(test_speech_hr, sizeof(test_speech_hr)); + + for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++) + test_hr(test_l2[i], sizeof(test_l2[0])); + + for (i = 0; i < sizeof(test_macblock) / sizeof(test_macblock[0]); i++) { + test_pdtch(test_macblock[i], 23); + test_pdtch(test_macblock[i], 34); + test_pdtch(test_macblock[i], 40); + test_pdtch(test_macblock[i], 54); + } + + 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..41369055 --- /dev/null +++ b/tests/bursts/bursts_test.ok @@ -0,0 +1,21 @@ +xcch_decode: n_errors=60 n_bits_total=456 ber=0.13 +xcch_decode: n_errors=60 n_bits_total=456 ber=0.13 +xcch_decode: n_errors=60 n_bits_total=456 ber=0.13 +tch_fr_decode: n_errors=8 n_bits_total=378 ber=0.02 +tch_fr_decode: n_errors=8 n_bits_total=378 ber=0.02 +tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02 +tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02 +tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02 +tch_hr_decode: n_errors=11 n_bits_total=211 ber=0.05 +tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02 +tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02 +tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02 +pdtch_decode: n_errors=0 n_bits_total=456 ber=0.00 +pdtch_decode: n_errors=132 n_bits_total=588 ber=0.22 +pdtch_decode: n_errors=220 n_bits_total=676 ber=0.33 +pdtch_decode: n_errors=0 n_bits_total=444 ber=0.00 +pdtch_decode: n_errors=0 n_bits_total=456 ber=0.00 +pdtch_decode: n_errors=132 n_bits_total=588 ber=0.22 +pdtch_decode: n_errors=220 n_bits_total=676 ber=0.33 +pdtch_decode: n_errors=0 n_bits_total=444 ber=0.00 +Success diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am new file mode 100644 index 00000000..597ab2d9 --- /dev/null +++ b/tests/handover/Makefile.am @@ -0,0 +1,8 @@ +AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) +AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS) +LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) +noinst_PROGRAMS = handover_test +EXTRA_DIST = handover_test.ok + +handover_test_SOURCES = handover_test.c +handover_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD) diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c new file mode 100644 index 00000000..6d7e6d1e --- /dev/null +++ b/tests/handover/handover_test.c @@ -0,0 +1,278 @@ +#include <stdint.h> +#include <unistd.h> +#include <stdlib.h> +#include <errno.h> +#include <getopt.h> +#include <limits.h> +#include <sched.h> +#include <sys/signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> + +#include <netinet/in.h> +#include <arpa/inet.h> +#include <net/if.h> + +#include <osmocom/core/talloc.h> +#include <osmocom/core/application.h> +#include <osmocom/vty/telnet_interface.h> +#include <osmocom/vty/logging.h> +#include <osmocom/core/gsmtap.h> +#include <osmocom/core/gsmtap_util.h> +#include <osmocom/core/bits.h> +#include <osmocom/core/backtrace.h> +#include <osmocom/abis/abis.h> + +#include <osmo-bts/gsm_data.h> +#include <osmo-bts/logging.h> +#include <osmo-bts/abis.h> +#include <osmo-bts/bts.h> +#include <osmo-bts/vty.h> +#include <osmo-bts/bts_model.h> +#include <osmo-bts/pcu_if.h> +#include <osmo-bts/l1sap.h> +#include <osmo-bts/handover.h> + +uint8_t phys_info[] = { 0x03, 0x03, 0x0d, 0x06, 0x2d, 0x00, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b }; + +static struct gsm_bts *bts; +struct gsm_bts_trx *trx; +int quit = 0; +uint8_t abis_mac[6] = { 0, 1, 2, 3, 4, 5 }; +const int pcu_direct = 0; +int modify_count = 0; + +static void expect_phys_info(struct lapdm_entity *le) +{ + struct osmo_phsap_prim pp; + int rc; + + rc = lapdm_phsap_dequeue_prim(le, &pp); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(sizeof(phys_info) == pp.oph.msg->len); + OSMO_ASSERT(!memcmp(phys_info, pp.oph.msg->data, pp.oph.msg->len)); + msgb_free(pp.oph.msg); +} + +int main(int argc, char **argv) +{ + struct gsm_bts_role_bts *btsb; + void *tall_bts_ctx; + void *tall_msgb_ctx; + struct e1inp_line *line; + struct gsm_lchan *lchan; + struct osmo_phsap_prim nl1sap; + struct msgb *msg; + struct abis_rsl_dchan_hdr *rslh; + int i; + + tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context"); + tall_msgb_ctx = talloc_named_const(tall_bts_ctx, 1, "msgb"); + msgb_set_talloc_ctx(tall_msgb_ctx); + + bts_log_init(NULL); + osmo_stderr_target->categories[DHO].loglevel = LOGL_DEBUG; + + bts = gsm_bts_alloc(tall_bts_ctx); + if (!bts) { + fprintf(stderr, "Failed to create BTS structure\n"); + exit(1); + } + trx = gsm_bts_trx_alloc(bts); + if (!trx) { + fprintf(stderr, "Failed to TRX structure\n"); + exit(1); + } + + if (bts_init(bts) < 0) { + fprintf(stderr, "unable to to open bts\n"); + exit(1); + } + + btsb = bts_role_bts(bts); + + libosmo_abis_init(NULL); + + line = e1inp_line_create(0, "ipa"); + OSMO_ASSERT(line); + + e1inp_ts_config_sign(&line->ts[E1INP_SIGN_RSL-1], line); + trx->rsl_link = e1inp_sign_link_create(&line->ts[E1INP_SIGN_RSL-1], E1INP_SIGN_RSL, NULL, 0, 0); + OSMO_ASSERT(trx->rsl_link); + trx->rsl_link->trx = trx; + + fprintf(stderr, "test 1: without timeout\n"); + + /* create two lchans for handover */ + lchan = &trx->ts[1].lchan[0]; + l1sap_chan_act(lchan->ts->trx, 0x09, NULL); + lchan = &trx->ts[2].lchan[0]; + lchan->ho.active = HANDOVER_ENABLED; + lchan->ho.ref = 23; + l1sap_chan_act(lchan->ts->trx, 0x0a, NULL); + OSMO_ASSERT(msgb_dequeue(&trx->rsl_link->tx_list)); + OSMO_ASSERT(msgb_dequeue(&trx->rsl_link->tx_list)); + OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list)); + + /* send access burst with wrong ref */ + memset(&nl1sap, 0, sizeof(nl1sap)); + osmo_prim_init(&nl1sap.oph, SAP_GSM_PH, PRIM_PH_RACH, PRIM_OP_INDICATION, NULL); + nl1sap.u.rach_ind.chan_nr = 0x0a; + nl1sap.u.rach_ind.ra = 42; + l1sap_up(trx, &nl1sap); + + /* expect no action */ + OSMO_ASSERT(modify_count == 0); + OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list)); + + /* send access burst with correct ref */ + nl1sap.u.rach_ind.ra = 23; + l1sap_up(trx, &nl1sap); + OSMO_ASSERT(modify_count == 1); + + /* expect PHYS INFO */ + expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch); + + /* expect exactly one HO.DET */ + OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list)); + rslh = msgb_l2(msg); + OSMO_ASSERT(rslh->c.msg_type == RSL_MT_HANDO_DET); + OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list)); + + /* expect T3105 running */ + OSMO_ASSERT(osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105)) + + /* indicate frame */ + handover_frame(&trx->ts[2].lchan[0]); + + /* expect T3105 not running */ + OSMO_ASSERT(!osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105)) + + fprintf(stderr, "test 2: with timeout\n"); + + /* enable handover again */ + lchan = &trx->ts[2].lchan[0]; + lchan->ho.active = HANDOVER_ENABLED; + lchan->ho.ref = 23; + modify_count = 0; + + /* send access burst with correct ref */ + nl1sap.u.rach_ind.ra = 23; + l1sap_up(trx, &nl1sap); + OSMO_ASSERT(modify_count == 1); + + /* expect PHYS INFO */ + expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch); + + /* expect exactly one HO.DET */ + OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list)); + rslh = msgb_l2(msg); + OSMO_ASSERT(rslh->c.msg_type == RSL_MT_HANDO_DET); + OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list)); + + for (i = 0; i < btsb->ny1 - 1; i++) { + /* expect T3105 running */ + OSMO_ASSERT(osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105)) + + /* timeout T3105 */ + gettimeofday(&trx->ts[2].lchan[0].ho.t3105.timeout, NULL); + osmo_select_main(0); + + /* expect PHYS INFO */ + expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch); + } + + /* timeout T3105 */ + gettimeofday(&trx->ts[2].lchan[0].ho.t3105.timeout, NULL); + osmo_select_main(0); + + /* expect T3105 not running */ + OSMO_ASSERT(!osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105)) + + /* expect exactly one CONN.FAIL */ + OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list)); + rslh = msgb_l2(msg); + OSMO_ASSERT(rslh->c.msg_type == RSL_MT_CONN_FAIL); + OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list)); + +#if 0 + while (!quit) { + log_reset_context(); + osmo_select_main(0); + } +#endif + + printf("Success\n"); + + return 0; +} + +void bts_model_abis_close(struct gsm_bts *bts) +{ +} + +int bts_model_oml_estab(struct gsm_bts *bts) +{ + return 0; +} + +int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap) +{ + int rc = 0; + uint8_t chan_nr; + uint8_t tn, ss; + struct gsm_lchan *lchan; + struct msgb *msg = l1sap->oph.msg; + struct osmo_phsap_prim nl1sap; + + switch (OSMO_PRIM_HDR(&l1sap->oph)) { + case OSMO_PRIM(PRIM_MPH_INFO, PRIM_OP_REQUEST): + switch (l1sap->u.info.type) { + case PRIM_INFO_ACTIVATE: + chan_nr = l1sap->u.info.u.act_req.chan_nr; + tn = L1SAP_CHAN2TS(chan_nr); + ss = l1sap_chan2ss(chan_nr); + lchan = &trx->ts[tn].lchan[ss]; + + lchan_init_lapdm(lchan); + + lchan_set_state(lchan, LCHAN_S_ACTIVE); + + memset(&nl1sap, 0, sizeof(nl1sap)); + osmo_prim_init(&nl1sap.oph, SAP_GSM_PH, PRIM_MPH_INFO, PRIM_OP_CONFIRM, NULL); + nl1sap.u.info.type = PRIM_INFO_ACTIVATE; + nl1sap.u.info.u.act_cnf.chan_nr = chan_nr; + return l1sap_up(trx, &nl1sap); + case PRIM_INFO_MODIFY: + modify_count++; + break; + default: + LOGP(DL1C, LOGL_NOTICE, "unknown MPH-INFO.req %d\n", + l1sap->u.info.type); + rc = -EINVAL; + goto done; + } + break; + default: + LOGP(DL1C, LOGL_NOTICE, "unknown prim %d op %d\n", + l1sap->oph.primitive, l1sap->oph.operation); + rc = -EINVAL; + goto done; + } + +done: + if (msg) + msgb_free(msg); + return rc; +} + +int bts_model_check_oml(struct gsm_bts *bts, uint8_t msg_type, struct tlv_parsed *old_attr, struct tlv_parsed *new_attr, void *obj) { return 0; } +int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg, struct tlv_parsed *new_attr, int obj_kind, void *obj) { return 0; } +int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj) { return 0; } +int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj, uint8_t adm_state) { return 0; } +int bts_model_init(struct gsm_bts *bts) { return 0; } +int bts_model_trx_deact_rf(struct gsm_bts_trx *trx) { return 0; } +int bts_model_trx_close(struct gsm_bts_trx *trx) { return 0; } +void trx_get_hlayer1(void) {} +int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan) { return 0; } diff --git a/tests/handover/handover_test.ok b/tests/handover/handover_test.ok new file mode 100644 index 00000000..35821117 --- /dev/null +++ b/tests/handover/handover_test.ok @@ -0,0 +1 @@ +Success diff --git a/tests/stubs.c b/tests/stubs.c index 89ab8027..f1ba5cc7 100644 --- a/tests/stubs.c +++ b/tests/stubs.c @@ -59,3 +59,6 @@ int l1if_set_txpower(struct femtol1_hdl *fl1h, float tx_power) int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan) { return 0; } + +void bts_model_abis_close(struct gsm_bts *bts) +{ } diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c index 99fd4c7d..def7a819 100644 --- a/tests/sysmobts/sysmobts_test.c +++ b/tests/sysmobts/sysmobts_test.c @@ -265,3 +265,5 @@ int bts_model_init(struct gsm_bts *bts) { return 0; } int bts_model_oml_estab(struct gsm_bts *bts) { return 0; } +void bts_model_abis_close(struct gsm_bts *bts) +{ } diff --git a/tests/testsuite.at b/tests/testsuite.at index b528335f..171fade5 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -24,3 +24,15 @@ 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/bursts/bursts_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/bursts/bursts_test], [], [expout], [ignore]) +AT_CLEANUP + +AT_SETUP([handover]) +AT_KEYWORDS([handover]) +cat $abs_srcdir/handover/handover_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/handover/handover_test], [], [expout], [ignore]) +AT_CLEANUP |