aboutsummaryrefslogtreecommitdiffstats
path: root/tests/alloc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-16 17:29:31 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-30 21:20:44 +0100
commitbfdd5f285b5c3577d57946886f484b9474abed77 (patch)
treefe44c8dcd29bf9638eee112252b5f99d02615ae2 /tests/alloc
parent948a3d62b1bd918a71613db0a3c6489251795c70 (diff)
alloc: Add very basic test case for the alloc_a algorithm
Diffstat (limited to 'tests/alloc')
-rw-r--r--tests/alloc/AllocTest.cpp123
-rw-r--r--tests/alloc/AllocTest.err2
-rw-r--r--tests/alloc/AllocTest.ok2
3 files changed, 127 insertions, 0 deletions
diff --git a/tests/alloc/AllocTest.cpp b/tests/alloc/AllocTest.cpp
new file mode 100644
index 00000000..3d58f509
--- /dev/null
+++ b/tests/alloc/AllocTest.cpp
@@ -0,0 +1,123 @@
+/* AllocTest.cpp
+ *
+ * Copyright (C) 2013 by Holger Hans Peter Freyther
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "gprs_rlcmac.h"
+#include "gprs_debug.h"
+#include "tbf.h"
+
+#include <string.h>
+#include <stdio.h>
+
+extern "C" {
+#include <osmocom/core/application.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+}
+
+/* globals used by the code */
+void *tall_pcu_ctx;
+struct gprs_rlcmac_bts *gprs_rlcmac_bts;
+int16_t spoof_mnc = 0, spoof_mcc = 0;
+
+static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count)
+{
+ int tfi;
+ uint8_t used_trx;
+ struct gprs_rlcmac_bts bts;
+ struct gprs_rlcmac_tbf *tbfs[33] = { 0, };
+
+ printf("Testing alloc_a direction(%d)\n", dir);
+
+ memset(&bts, 0, sizeof(bts));
+ bts.alloc_algorithm = alloc_algorithm_a;
+ gprs_rlcmac_bts = &bts;
+
+ struct gprs_rlcmac_trx *trx = &bts.trx[0];
+ trx->pdch[2].enable = 1;
+ trx->pdch[3].enable = 1;
+
+ /**
+ * Currently alloc_a will only allocate from the first
+ * PDCH and all possible usf's. We run out of usf's before
+ * we are out of tfi's. Observe this and make sure that at
+ * least this part is working okay.
+ */
+ for (int i = 0; i < count; ++i) {
+ struct gprs_rlcmac_tbf *tbf;
+
+ tfi = tfi_find_free(&bts, dir, &used_trx, 0);
+ OSMO_ASSERT(tfi >= 0);
+ tbfs[i] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
+ }
+
+ /* Now check that there are still some TFIs */
+ tfi = tfi_find_free(&bts, dir, &used_trx, 0);
+ switch (dir) {
+ case GPRS_RLCMAC_UL_TBF:
+ OSMO_ASSERT(tfi >= 0);
+ break;
+ case GPRS_RLCMAC_DL_TBF:
+ OSMO_ASSERT(tfi < 0);
+ break;
+ }
+ OSMO_ASSERT(!tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0));
+
+ for (int i = 0; i < ARRAY_SIZE(tbfs); ++i)
+ if (tbfs[i])
+ tbf_free(tbfs[i]);
+
+ tfi = tfi_find_free(&bts, dir, &used_trx, 0);
+ OSMO_ASSERT(tfi >= 0);
+
+ tbfs[tfi] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
+ OSMO_ASSERT(tbfs[tfi]);
+ tbf_free(tbfs[tfi]);
+}
+
+static void test_alloc_a()
+{
+ test_alloc_a(GPRS_RLCMAC_DL_TBF, 32);
+ test_alloc_a(GPRS_RLCMAC_UL_TBF, 7);
+}
+
+int main(int argc, char **argv)
+{
+ tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
+ if (!tall_pcu_ctx)
+ abort();
+
+ msgb_set_talloc_ctx(tall_pcu_ctx);
+ osmo_init_logging(&gprs_log_info);
+ log_set_use_color(osmo_stderr_target, 0);
+ log_set_print_filename(osmo_stderr_target, 0);
+
+ test_alloc_a();
+ return EXIT_SUCCESS;
+}
+
+/*
+ * stubs that should not be reached
+ */
+extern "C" {
+void l1if_pdch_req() { abort(); }
+void l1if_connect_pdch() { abort(); }
+void l1if_close_pdch() { abort(); }
+void l1if_open_pdch() { abort(); }
+}
diff --git a/tests/alloc/AllocTest.err b/tests/alloc/AllocTest.err
new file mode 100644
index 00000000..3f285a46
--- /dev/null
+++ b/tests/alloc/AllocTest.err
@@ -0,0 +1,2 @@
+No TFI available.
+- Failed allocating TS=2, no USF available
diff --git a/tests/alloc/AllocTest.ok b/tests/alloc/AllocTest.ok
new file mode 100644
index 00000000..86a8c193
--- /dev/null
+++ b/tests/alloc/AllocTest.ok
@@ -0,0 +1,2 @@
+Testing alloc_a direction(0)
+Testing alloc_a direction(1)