This test fills the queue by calling bts_agch_enqueue() with a
mix of IMM.ASS and IMM.ASS.REJ. Then it drains the queue by calling
bts_ccch_copy_msg(). After each of both steps, statistics are printed
out.

Sponsored-by: On-Waves ehf
---
 configure.ac            |    1 +
 tests/Makefile.am       |    2 +-
 tests/agch/Makefile.am  |    8 ++
 tests/agch/agch_test.c  |  220 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/agch/agch_test.ok |    4 +
 tests/testsuite.at      |    6 ++
 6 files changed, 240 insertions(+), 1 deletion(-)
 create mode 100644 tests/agch/Makefile.am
 create mode 100644 tests/agch/agch_test.c
 create mode 100644 tests/agch/agch_test.ok

diff --git a/configure.ac b/configure.ac
index 3411017..ff46b5a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ AC_OUTPUT(
     include/osmo-bts/Makefile
     tests/Makefile
     tests/paging/Makefile
+    tests/agch/Makefile
     tests/cipher/Makefile
     tests/sysmobts/Makefile
     Makefile)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5fb128f..b32241b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = paging cipher sysmobts
+SUBDIRS = paging cipher sysmobts agch
 
 # 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/agch/Makefile.am b/tests/agch/Makefile.am
new file mode 100644
index 0000000..a0c5eed
--- /dev/null
+++ b/tests/agch/Makefile.am
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) -lortp
+noinst_PROGRAMS = agch_test
+EXTRA_DIST = agch_test.ok
+
+agch_test_SOURCES = agch_test.c $(srcdir)/../stubs.c
+agch_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)
diff --git a/tests/agch/agch_test.c b/tests/agch/agch_test.c
new file mode 100644
index 0000000..7e87bcf
--- /dev/null
+++ b/tests/agch/agch_test.c
@@ -0,0 +1,220 @@
+/* testing the agch code */
+
+/* (C) 2011 by Holger Hans Peter Freyther
+ * (C) 2014 by Sysmocom sfmc GmbH
+ *
+ * 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 <osmocom/core/talloc.h>
+
+#include <osmo-bts/bts.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/gsm_data.h>
+
+#include <unistd.h>
+
+static struct gsm_bts *bts;
+static struct gsm_bts_role_bts *btsb;
+int pcu_direct = 0;
+
+static const uint8_t static_ilv[] = {
+       0x08, 0x59, 0x51, 0x30, 0x99, 0x00, 0x00, 0x00, 0x19
+};
+
+#define ASSERT_TRUE(rc) \
+       if (!(rc)) { \
+               printf("Assert failed in %s:%d.\n",  \
+                      __FILE__, __LINE__);          \
+               abort();                             \
+       }
+
+static int count_imm_ass_rej_refs(struct gsm48_imm_ass_rej *rej)
+{
+       int count = 0;
+       count++;
+
+       if (memcmp(&rej->req_ref1, &rej->req_ref2, sizeof(rej->req_ref2))) {
+               count++;
+       }
+
+       if (memcmp(&rej->req_ref1, &rej->req_ref3, sizeof(rej->req_ref3))
+           && memcmp(&rej->req_ref2, &rej->req_ref3, sizeof(rej->req_ref3))) {
+               count++;
+       }
+
+       if (memcmp(&rej->req_ref1, &rej->req_ref4, sizeof(rej->req_ref4))
+           && memcmp(&rej->req_ref2, &rej->req_ref4, sizeof(rej->req_ref4))
+           && memcmp(&rej->req_ref3, &rej->req_ref4, sizeof(rej->req_ref4))) {
+               count++;
+       }
+
+       return count;
+}
+
+static void put_imm_ass_rej(struct msgb *msg, int idx, uint8_t wait_ind)
+{
+       /* GSM CCCH - Immediate Assignment Reject */
+       static const unsigned char gsm_a_ccch_data[23] = {
+               0x4d, 0x06, 0x3a, 0x03, 0x25, 0x00, 0x00, 0x0a,
+               0x25, 0x00, 0x00, 0x0a, 0x25, 0x00, 0x00, 0x0a,
+               0x25, 0x00, 0x00, 0x0a, 0x2b, 0x2b, 0x2b
+       };
+
+       struct gsm48_imm_ass_rej *rej;
+       msg->l3h = msgb_put(msg, sizeof(gsm_a_ccch_data));
+       rej = (struct gsm48_imm_ass_rej *)msg->l3h;
+       memmove(msg->l3h, gsm_a_ccch_data, sizeof(gsm_a_ccch_data));
+
+       rej->req_ref1.t1 = idx;
+       rej->wait_ind1 = wait_ind;
+
+       rej->req_ref2.t1 = idx;
+       rej->req_ref3.t1 = idx;
+       rej->req_ref4.t1 = idx;
+}
+
+static void put_imm_ass(struct msgb *msg, int idx)
+{
+       /* GSM CCCH - Immediate Assignment */
+       static const unsigned char gsm_a_ccch_data[23] = {
+               0x2d, 0x06, 0x3f, 0x03, 0x0c, 0xe3, 0x69, 0x25,
+               0x00, 0x00, 0x00, 0x00, 0x2b, 0x2b, 0x2b, 0x2b,
+               0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b
+       };
+
+       struct gsm48_imm_ass *ima;
+       msg->l3h = msgb_put(msg, sizeof(gsm_a_ccch_data));
+       ima = (struct gsm48_imm_ass *)msg->l3h;
+       memmove(msg->l3h, gsm_a_ccch_data, sizeof(gsm_a_ccch_data));
+
+       ima->req_ref.t1 = idx;
+}
+
+static void test_agch_queue(void)
+{
+       int rc;
+       uint8_t out_buf[GSM_MACBLOCK_LEN];
+       struct gsm_time g_time;
+       const int num_rounds = 40;
+       const int num_ima_per_round = 2;
+       const int num_rej_per_round = 16;
+
+       int round, idx;
+       int count = 0;
+       struct msgb *msg = NULL;
+       int multiframes = 0;
+       int imm_ass_count = 0;
+       int imm_ass_rej_count = 0;
+       int imm_ass_rej_ref_count = 0;
+
+       g_time.fn = 0;
+       g_time.t1 = 0;
+       g_time.t2 = 0;
+       g_time.t3 = 6;
+
+       printf("Testing AGCH messages queue handling.\n");
+       btsb->agch_max_queue_length = 32;
+
+       for (round = 1; round <= num_rounds; round++) {
+               for (idx = 0; idx < num_ima_per_round; idx++) {
+                       msg = msgb_alloc(GSM_MACBLOCK_LEN, __FUNCTION__);
+                       put_imm_ass(msg, ++count);
+                       bts_agch_enqueue(bts, msg);
+                       imm_ass_count++;
+               }
+               for (idx = 0; idx < num_rej_per_round; idx++) {
+                       msg = msgb_alloc(GSM_MACBLOCK_LEN, __FUNCTION__);
+                       put_imm_ass_rej(msg, ++count, 10);
+                       bts_agch_enqueue(bts, msg);
+                       imm_ass_rej_count++;
+                       imm_ass_rej_ref_count++;
+               }
+       }
+
+       printf("AGCH filled: count %u, imm.ass %d, imm.ass.rej %d (refs %d), "
+              "queue limit %u, occupied %d, "
+              "dropped %llu, merged %llu, rejected %llu, "
+              "ag-res %llu, non-res %llu\n",
+              count, imm_ass_count, imm_ass_rej_count, imm_ass_rej_ref_count,
+              btsb->agch_max_queue_length, btsb->agch_queue_length,
+              btsb->agch_queue_dropped_msgs, btsb->agch_queue_merged_msgs,
+              btsb->agch_queue_rejected_msgs, btsb->agch_queue_agch_msgs,
+              btsb->agch_queue_pch_msgs);
+
+       imm_ass_count = 0;
+       imm_ass_rej_count = 0;
+       imm_ass_rej_ref_count = 0;
+
+       for (idx = 0; 1; idx++) {
+               struct gsm48_imm_ass *ima;
+               int is_agch = (idx % 3) == 0; /* 1 AG reserved, 2 PCH */
+               if (is_agch)
+                       multiframes++;
+
+               rc = bts_ccch_copy_msg(bts, out_buf, &g_time, is_agch);
+               ima = (struct gsm48_imm_ass *)out_buf;
+               switch (ima->msg_type) {
+               case GSM48_MT_RR_IMM_ASS:
+                       imm_ass_count++;
+                       break;
+               case GSM48_MT_RR_IMM_ASS_REJ:
+                       imm_ass_rej_count++;
+                       imm_ass_rej_ref_count +=
+                               count_imm_ass_rej_refs((struct 
gsm48_imm_ass_rej *)ima);
+                       break;
+               default:
+                       break;
+               }
+               if (is_agch && rc <= 0)
+                       break;
+
+       }
+
+       printf("AGCH drained: multiframes %u, imm.ass %d, imm.ass.rej %d (refs 
%d), "
+              "queue limit %u, occupied %d, "
+              "dropped %llu, merged %llu, rejected %llu, "
+              "ag-res %llu, non-res %llu\n",
+              multiframes, imm_ass_count, imm_ass_rej_count, 
imm_ass_rej_ref_count,
+              btsb->agch_max_queue_length, btsb->agch_queue_length,
+              btsb->agch_queue_dropped_msgs, btsb->agch_queue_merged_msgs,
+              btsb->agch_queue_rejected_msgs, btsb->agch_queue_agch_msgs,
+              btsb->agch_queue_pch_msgs);
+}
+
+int main(int argc, char **argv)
+{
+       void *tall_msgb_ctx;
+
+       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);
+
+       bts = gsm_bts_alloc(tall_bts_ctx);
+       if (bts_init(bts) < 0) {
+               fprintf(stderr, "unable to open bts\n");
+               exit(1);
+       }
+
+       btsb = bts_role_bts(bts);
+       test_agch_queue();
+       printf("Success\n");
+
+       return 0;
+}
+
diff --git a/tests/agch/agch_test.ok b/tests/agch/agch_test.ok
new file mode 100644
index 0000000..8442f07
--- /dev/null
+++ b/tests/agch/agch_test.ok
@@ -0,0 +1,4 @@
+Testing AGCH messages queue handling.
+AGCH filled: count 720, imm.ass 80, imm.ass.rej 640 (refs 640), queue limit 
32, occupied 720, dropped 0, merged 0, rejected 0, ag-res 0, non-res 0
+AGCH drained: multiframes 721, imm.ass 80, imm.ass.rej 640 (refs 640), queue 
limit 32, occupied 0, dropped 0, merged 0, rejected 0, ag-res 720, non-res 0
+Success
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 1297421..ec3021f 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -7,6 +7,12 @@ cat $abs_srcdir/paging/paging_test.ok > expout
 AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/paging/paging_test], [], 
[expout], [ignore])
 AT_CLEANUP
 
+AT_SETUP([agch])
+AT_KEYWORDS([agch])
+cat $abs_srcdir/agch/agch_test.ok > expout
+AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/agch/agch_test], [], [expout], 
[ignore])
+AT_CLEANUP
+
 AT_SETUP([cipher])
 AT_KEYWORDS([cipher])
 cat $abs_srcdir/cipher/cipher_test.ok > expout
-- 
1.7.9.5


Reply via email to