aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-11-21 18:13:31 +0100
committerHarald Welte <laforge@gnumonks.org>2018-01-25 16:12:57 +0000
commit2ecf0fdfc26efd5f504c0bcec28f233bd06693d7 (patch)
tree824f0faac3a0ad47b66a380b8a0ef46f6409bce5 /tests
parent46fbfceac6dfa6641d3e00c1a102622550bb7190 (diff)
AllocTest: adjust test_alloc_b()
This function contains 3 independent test cases. Let's split them into separate functions to simplify further modifications: * split test cases into separate functions * use them for mass test as well * change function names to avoid confusion * make individual test cases return error instead of failing via assert on allocation failure The top-level test_alloc_b() is used as part of exhaustion tests in test_all_alloc_b() for example, so it's expected that allocation might fail (due to TFI or USF exhaustion for example) eventually. In this case it's better to indicate it to caller instead of failing entire program. The test output does not require any adjustements because we do not exhaust to the point of allocation failure yet. Change-Id: Id7e03a85ce96e7d617cecee963759bae589a3a1a Related: OS#2282
Diffstat (limited to 'tests')
-rw-r--r--tests/alloc/AllocTest.cpp355
1 files changed, 156 insertions, 199 deletions
diff --git a/tests/alloc/AllocTest.cpp b/tests/alloc/AllocTest.cpp
index a88f477..f84ee69 100644
--- a/tests/alloc/AllocTest.cpp
+++ b/tests/alloc/AllocTest.cpp
@@ -166,8 +166,11 @@ static void test_alloc_a()
test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28);
}
-static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir)
+static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir, bool verbose)
{
+ if (!verbose)
+ return;
+
for (size_t i = 0; i < ARRAY_SIZE(tbf->pdch); ++i)
if (tbf->pdch[i])
printf("PDCH[%zu] is used for %s\n", i, dir);
@@ -175,152 +178,189 @@ static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir)
printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir);
}
-static void test_alloc_b(int ms_class)
+#define ENABLE_PDCH(ts_no, enable_flag, trx) \
+ if (enable_flag) \
+ trx->pdch[ts_no].enable();
+
+static inline void enable_ts_on_bts(struct gprs_rlcmac_bts *bts,
+ bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7)
{
- printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class);
- /*
- * PDCH is on TS 6,7,8 and we start with a UL allocation and
- * then follow two DL allocations (once single, once normal).
- *
- * Uplink assigned and still available..
- */
- {
- BTS the_bts;
- struct gprs_rlcmac_bts *bts;
- struct gprs_rlcmac_trx *trx;
- uint8_t trx_no;
+ struct gprs_rlcmac_trx *trx = &bts->trx[0];
- gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
+ ENABLE_PDCH(0, ts0, trx);
+ ENABLE_PDCH(1, ts1, trx);
+ ENABLE_PDCH(2, ts2, trx);
+ ENABLE_PDCH(3, ts3, trx);
+ ENABLE_PDCH(4, ts4, trx);
+ ENABLE_PDCH(5, ts5, trx);
+ ENABLE_PDCH(6, ts6, trx);
+ ENABLE_PDCH(7, ts7, trx);
+}
+
+static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
+ uint8_t ms_class, bool verbose)
+{
+ BTS the_bts;
+ struct gprs_rlcmac_bts *bts = the_bts.bts_data();
+ gprs_rlcmac_ul_tbf *ul_tbf;
+ gprs_rlcmac_dl_tbf *dl_tbf;
+ if (verbose)
printf("Testing UL then DL assignment.\n");
- bts = the_bts.bts_data();
- bts->alloc_algorithm = alloc_algorithm_b;
+ bts->alloc_algorithm = alloc_algorithm_b;
- trx = &bts->trx[0];
- trx->pdch[5].enable();
- trx->pdch[6].enable();
- trx->pdch[7].enable();
+ enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
- ul_tbf = tbf_alloc_ul_tbf(bts, NULL, -1, ms_class, 0, 1);
- OSMO_ASSERT(ul_tbf);
- OSMO_ASSERT(ul_tbf->ms());
- OSMO_ASSERT(ul_tbf->ms()->current_trx());
- trx_no = ul_tbf->ms()->current_trx()->trx_no;
- dump_assignment(ul_tbf, "UL");
+ ul_tbf = tbf_alloc_ul_tbf(bts, NULL, -1, ms_class, 0, 1);
+ if (!ul_tbf)
+ return false;
- /* assume final ack has not been sent */
- dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0, 0);
- OSMO_ASSERT(dl_tbf);
- dump_assignment(dl_tbf, "DL");
+ OSMO_ASSERT(ul_tbf->ms());
+ OSMO_ASSERT(ul_tbf->ms()->current_trx());
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+ dump_assignment(ul_tbf, "UL", verbose);
- check_tfi_usage(&the_bts);
+ /* assume final ack has not been sent */
+ dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), ul_tbf->ms()->current_trx()->trx_no, ms_class, 0, 0);
+ if (!dl_tbf)
+ return false;
- tbf_free(dl_tbf);
- tbf_free(ul_tbf);
- }
+ dump_assignment(dl_tbf, "DL", verbose);
- /**
- * Test with the other order.. first DL and then UL
- */
- {
- BTS the_bts;
- struct gprs_rlcmac_bts *bts;
- struct gprs_rlcmac_trx *trx;
- uint8_t trx_no;
+ OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+
+ check_tfi_usage(&the_bts);
+
+ tbf_free(dl_tbf);
+ tbf_free(ul_tbf);
- gprs_rlcmac_ul_tbf *ul_tbf;
- gprs_rlcmac_dl_tbf *dl_tbf;
+ return true;
+}
+
+static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
+ uint8_t ms_class, bool verbose)
+{
+ BTS the_bts;
+ struct gprs_rlcmac_bts *bts = the_bts.bts_data();
+ gprs_rlcmac_ul_tbf *ul_tbf;
+ gprs_rlcmac_dl_tbf *dl_tbf;
+ if (verbose)
printf("Testing DL then UL assignment followed by update\n");
- bts = the_bts.bts_data();
- bts->alloc_algorithm = alloc_algorithm_b;
+ bts->alloc_algorithm = alloc_algorithm_b;
- trx = &bts->trx[0];
- trx->pdch[5].enable();
- trx->pdch[6].enable();
- trx->pdch[7].enable();
+ enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
- dl_tbf = tbf_alloc_dl_tbf(bts, NULL, -1, ms_class, 0, 1);
- dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
- OSMO_ASSERT(dl_tbf);
- OSMO_ASSERT(dl_tbf->ms());
- OSMO_ASSERT(dl_tbf->ms()->current_trx());
- trx_no = dl_tbf->ms()->current_trx()->trx_no;
- dump_assignment(dl_tbf, "DL");
+ dl_tbf = tbf_alloc_dl_tbf(bts, NULL, -1, ms_class, 0, 1);
+ if (!dl_tbf)
+ return false;
- ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf->ms(), trx_no, ms_class, 0, 0);
- ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
- ul_tbf->m_contention_resolution_done = 1;
- OSMO_ASSERT(ul_tbf);
- dump_assignment(ul_tbf, "UL");
+ dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+ OSMO_ASSERT(dl_tbf->ms());
+ OSMO_ASSERT(dl_tbf->ms()->current_trx());
- /* now update the dl_tbf */
- dl_tbf->update();
- dump_assignment(dl_tbf, "DL");
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+ dump_assignment(dl_tbf, "DL", verbose);
- check_tfi_usage(&the_bts);
+ ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf->ms(), dl_tbf->ms()->current_trx()->trx_no, ms_class, 0, 0);
+ if (!ul_tbf)
+ return false;
- tbf_free(dl_tbf);
- tbf_free(ul_tbf);
- }
+ ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
+ ul_tbf->m_contention_resolution_done = 1;
- /* Andreas osmocom-pcu example */
- {
- BTS the_bts;
- struct gprs_rlcmac_bts *bts;
- struct gprs_rlcmac_trx *trx;
- int tfi;
- uint8_t trx_no;
+ dump_assignment(ul_tbf, "UL", verbose);
- gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
+ OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
- printf("Testing jolly example\n");
+ /* now update the dl_tbf */
+ dl_tbf->update();
+ dump_assignment(dl_tbf, "DL", verbose);
+ OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
- bts = the_bts.bts_data();
- bts->alloc_algorithm = alloc_algorithm_b;
+ check_tfi_usage(&the_bts);
- trx = &bts->trx[0];
- trx->pdch[1].enable();
- trx->pdch[2].enable();
- trx->pdch[3].enable();
- trx->pdch[4].enable();
+ tbf_free(dl_tbf);
+ tbf_free(ul_tbf);
- tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
- OSMO_ASSERT(tfi >= 0);
- ul_tbf = tbf_alloc_ul_tbf(bts, NULL, .1, ms_class, 0, 0);
- OSMO_ASSERT(ul_tbf);
- OSMO_ASSERT(ul_tbf->ms());
- OSMO_ASSERT(ul_tbf->ms()->current_trx());
- trx_no = ul_tbf->ms()->current_trx()->trx_no;
- dump_assignment(ul_tbf, "UL");
+ return true;
+}
- /* assume final ack has not been sent */
- dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0, 0);
- OSMO_ASSERT(dl_tbf);
- dump_assignment(dl_tbf, "DL");
+static inline bool test_alloc_b_jolly(uint8_t ms_class)
+{
+ BTS the_bts;
+ struct gprs_rlcmac_bts *bts = the_bts.bts_data();
+ int tfi;
+ uint8_t trx_no;
+ gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+ printf("Testing jolly example\n");
- check_tfi_usage(&the_bts);
+ bts->alloc_algorithm = alloc_algorithm_b;
- tbf_free(dl_tbf);
- tbf_free(ul_tbf);
- }
+ enable_ts_on_bts(bts, false, true, true, true, true, false, false, false);
+
+ tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
+ OSMO_ASSERT(tfi >= 0);
+ ul_tbf = tbf_alloc_ul_tbf(bts, NULL, .1, ms_class, 0, 0);
+ if (!ul_tbf)
+ return false;
+
+ OSMO_ASSERT(ul_tbf->ms());
+ OSMO_ASSERT(ul_tbf->ms()->current_trx());
+ trx_no = ul_tbf->ms()->current_trx()->trx_no;
+ dump_assignment(ul_tbf, "UL", true);
+
+ /* assume final ack has not been sent */
+ dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0, 0);
+ if (!dl_tbf)
+ return false;
+
+ dump_assignment(dl_tbf, "DL", true);
+
+ OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
+
+ check_tfi_usage(&the_bts);
+
+ tbf_free(dl_tbf);
+ tbf_free(ul_tbf);
+
+ return true;
}
-#define ENABLE_PDCH(ts_no, enable_flag, trx) \
- if (enable_flag) \
- trx->pdch[ts_no].enable();
+static void test_alloc_b_for_ms(uint8_t ms_class)
+{
+ bool rc;
+
+ printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class);
+ /*
+ * PDCH is on TS 6,7,8 and we start with a UL allocation and
+ * then follow two DL allocations (once single, once normal).
+ *
+ * Uplink assigned and still available..
+ */
+
+ rc = test_alloc_b_ul_dl(false, false, false, false, false, true, true, true, ms_class, true);
+ if (!rc)
+ return;
+
+ /**
+ * Test with the other order.. first DL and then UL
+ */
+ rc = test_alloc_b_dl_ul(false, false, false, false, false, true, true, true, ms_class, true);
+ if (!rc)
+ return;
-static void test_alloc_b(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class)
+ /* Andreas osmocom-pcu example */
+ test_alloc_b_jolly(ms_class);
+}
+
+static void test_alloc_mass(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class)
{
+ bool rc;
+
/* we can test the allocation failures differently */
if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7)
return;
@@ -336,97 +376,14 @@ static void test_alloc_b(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool
ts7 ? 'O' : 'x', ms_class);
fflush(stdout);
- {
- BTS the_bts;
- struct gprs_rlcmac_bts *bts;
- struct gprs_rlcmac_trx *trx;
- uint8_t trx_no;
-
- gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
-
- bts = the_bts.bts_data();
- bts->alloc_algorithm = alloc_algorithm_b;
-
- trx = &bts->trx[0];
- ENABLE_PDCH(0, ts0, trx);
- ENABLE_PDCH(1, ts1, trx);
- ENABLE_PDCH(2, ts2, trx);
- ENABLE_PDCH(3, ts3, trx);
- ENABLE_PDCH(4, ts4, trx);
- ENABLE_PDCH(5, ts5, trx);
- ENABLE_PDCH(6, ts6, trx);
- ENABLE_PDCH(7, ts7, trx);
-
- ul_tbf = tbf_alloc_ul_tbf(bts, NULL, -1, ms_class, 0, 1);
- OSMO_ASSERT(ul_tbf->ms());
- OSMO_ASSERT(ul_tbf->ms()->current_trx());
- trx_no = ul_tbf->ms()->current_trx()->trx_no;
- OSMO_ASSERT(ul_tbf);
-
- /* assume final ack has not been sent */
- dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0, 0);
- OSMO_ASSERT(dl_tbf);
-
- /* verify that both are on the same ts */
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
-
- check_tfi_usage(&the_bts);
-
- tbf_free(dl_tbf);
- tbf_free(ul_tbf);
- }
+ rc = test_alloc_b_ul_dl(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
+ if (!rc)
+ return;
/**
* Test with the other order.. first DL and then UL
*/
- {
- BTS the_bts;
- struct gprs_rlcmac_bts *bts;
- struct gprs_rlcmac_trx *trx;
- uint8_t trx_no;
-
- gprs_rlcmac_ul_tbf *ul_tbf;
- gprs_rlcmac_dl_tbf *dl_tbf;
-
- bts = the_bts.bts_data();
- bts->alloc_algorithm = alloc_algorithm_b;
-
- trx = &bts->trx[0];
- ENABLE_PDCH(0, ts0, trx);
- ENABLE_PDCH(1, ts1, trx);
- ENABLE_PDCH(2, ts2, trx);
- ENABLE_PDCH(3, ts3, trx);
- ENABLE_PDCH(4, ts4, trx);
- ENABLE_PDCH(5, ts5, trx);
- ENABLE_PDCH(6, ts6, trx);
- ENABLE_PDCH(7, ts7, trx);
-
- dl_tbf = tbf_alloc_dl_tbf(bts, NULL, -1, ms_class, 0, 1);
- OSMO_ASSERT(dl_tbf);
- OSMO_ASSERT(dl_tbf->ms());
- OSMO_ASSERT(dl_tbf->ms()->current_trx());
- trx_no = dl_tbf->ms()->current_trx()->trx_no;
- dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
-
- ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf->ms(), trx_no, ms_class, 0, 0);
- OSMO_ASSERT(ul_tbf);
- ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
- ul_tbf->m_contention_resolution_done = 1;
-
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
-
- /* now update the dl_tbf */
- dl_tbf->update();
- OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
-
- OSMO_ASSERT(ul_tbf->ms_class() == ms_class);
- OSMO_ASSERT(dl_tbf->ms_class() == ms_class);
-
- check_tfi_usage(&the_bts);
-
- tbf_free(dl_tbf);
- tbf_free(ul_tbf);
- }
+ test_alloc_b_dl_ul(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
}
static void test_all_alloc_b()
@@ -441,13 +398,13 @@ static void test_all_alloc_b()
for (uint8_t ts6 = 0; ts6 < 2; ++ts6)
for (uint8_t ts7 = 0; ts7 < 2; ++ts7)
for (int ms_class = 0; ms_class < 30; ++ms_class)
- test_alloc_b(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class);
+ test_alloc_mass(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class);
}
static void test_alloc_b()
{
for (int i = 0; i < 30; ++i)
- test_alloc_b(i);
+ test_alloc_b_for_ms(i);
test_all_alloc_b();
}