blob: 8ebf15943b4d571f4a74ee3a2376a188654e393f [file] [log] [blame]
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +02001/* AllocTest.cpp
2 *
3 * Copyright (C) 2013 by Holger Hans Peter Freyther
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include "gprs_rlcmac.h"
21#include "gprs_debug.h"
22#include "tbf.h"
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020023#include "tbf_ul.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020024#include "bts.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020025
26#include <string.h>
27#include <stdio.h>
28
29extern "C" {
Max9f460712018-01-23 20:57:08 +010030#include "mslot_class.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020031#include <osmocom/core/application.h>
32#include <osmocom/core/msgb.h>
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/utils.h>
35}
36
37/* globals used by the code */
38void *tall_pcu_ctx;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020039int16_t spoof_mnc = 0, spoof_mcc = 0;
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +010040bool spoof_mnc_3_digits = false;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020041
Daniel Willmann48aa0b02014-07-16 18:54:10 +020042static gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
Jacob Erlbecke2e004e2015-06-18 17:16:26 +020043 GprsMs *ms, gprs_rlcmac_tbf_direction dir,
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020044 uint8_t use_trx, bool single_slot)
Daniel Willmann48aa0b02014-07-16 18:54:10 +020045{
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020046 OSMO_ASSERT(ms != NULL);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +020047
Daniel Willmann48aa0b02014-07-16 18:54:10 +020048 if (dir == GPRS_RLCMAC_UL_TBF)
Pau Espin Pedrol17402a52020-05-08 17:44:33 +020049 return tbf_alloc_ul_tbf(bts, ms, use_trx, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020050 else
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020051 return tbf_alloc_dl_tbf(bts, ms, use_trx, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020052}
53
Jacob Erlbeck61205a72015-07-09 11:35:50 +020054static void check_tfi_usage(BTS *the_bts)
55{
56 int pdch_no;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020057
58 struct gprs_rlcmac_tbf *tfi_usage[8][8][2][32] = {{{{NULL}}}};
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010059 LListHead<gprs_rlcmac_tbf> *tbf_lists[2] = {
60 &the_bts->ul_tbfs(),
61 &the_bts->dl_tbfs()
Jacob Erlbeck61205a72015-07-09 11:35:50 +020062 };
63
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010064 LListHead<gprs_rlcmac_tbf> *pos;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020065 gprs_rlcmac_tbf *tbf;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020066 unsigned list_idx;
67 struct gprs_rlcmac_tbf **tbf_var;
68
69 for (list_idx = 0; list_idx < ARRAY_SIZE(tbf_lists); list_idx += 1)
70 {
71
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010072 llist_for_each(pos, tbf_lists[list_idx]) {
73 tbf = pos->entry();
Jacob Erlbeck61205a72015-07-09 11:35:50 +020074 for (pdch_no = 0; pdch_no < 8; pdch_no += 1) {
75 struct gprs_rlcmac_pdch *pdch = tbf->pdch[pdch_no];
76 if (pdch == NULL)
77 continue;
78
79 tbf_var = &tfi_usage
80 [tbf->trx->trx_no]
81 [pdch_no]
82 [tbf->direction]
83 [tbf->tfi()];
84
85 OSMO_ASSERT(*tbf_var == NULL);
86 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
87 OSMO_ASSERT(pdch->dl_tbf_by_tfi(
88 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020089 OSMO_ASSERT(the_bts->dl_tbf_by_tfi(
90 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020091 tbf->trx->trx_no,
92 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020093 } else {
94 OSMO_ASSERT(pdch->ul_tbf_by_tfi(
95 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020096 OSMO_ASSERT(the_bts->ul_tbf_by_tfi(
97 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020098 tbf->trx->trx_no,
99 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200100 }
101 *tbf_var = tbf;
Jacob Erlbeck47a57f62015-07-08 12:53:16 +0200102 OSMO_ASSERT(pdch->assigned_tfi(tbf->direction) &
103 (1 << tbf->tfi()));
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200104 }
105 }
106 }
107}
108
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200109static void test_alloc_a(gprs_rlcmac_tbf_direction dir,
110 uint8_t slots, const int count)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200111{
112 int tfi;
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200113 int i;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200114 uint8_t used_trx, tmp_trx;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200115 BTS the_bts;
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200116 GprsMs *ms;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200117 struct gprs_rlcmac_bts *bts;
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200118 struct gprs_rlcmac_tbf *tbfs[32*8+1] = { 0, };
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200119
120 printf("Testing alloc_a direction(%d)\n", dir);
121
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200122 bts = the_bts.bts_data();
123 bts->alloc_algorithm = alloc_algorithm_a;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200124
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200125 struct gprs_rlcmac_trx *trx = &bts->trx[0];
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200126 for (i = 0; i < 8; i += 1)
127 if (slots & (1 << i))
128 trx->pdch[i].enable();
129
130 OSMO_ASSERT(count >= 0 && count <= (int)ARRAY_SIZE(tbfs));
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200131
132 /**
133 * Currently alloc_a will only allocate from the first
134 * PDCH and all possible usf's. We run out of usf's before
135 * we are out of tfi's. Observe this and make sure that at
136 * least this part is working okay.
137 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200138 for (i = 0; i < (int)ARRAY_SIZE(tbfs); ++i) {
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200139 ms = bts->bts->ms_alloc(0, 0);
140 tbfs[i] = tbf_alloc(bts, ms, dir, -1, 0);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200141 if (tbfs[i] == NULL)
142 break;
143
144 used_trx = tbfs[i]->trx->trx_no;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200145 tfi = the_bts.tfi_find_free(dir, &tmp_trx, used_trx);
146 OSMO_ASSERT(tbfs[i]->tfi() != tfi);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200147 }
148
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200149 check_tfi_usage(&the_bts);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200150
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200151 OSMO_ASSERT(i == count);
152
153 for (i = 0; i < count; ++i)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200154 if (tbfs[i])
155 tbf_free(tbfs[i]);
156
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200157 ms = bts->bts->ms_alloc(0, 0);
158 tbfs[0] = tbf_alloc(bts, ms, dir, -1, 0);
Holger Hans Peter Freytherf3f1bde2016-02-22 15:14:01 +0100159 OSMO_ASSERT(tbfs[0]);
160 tbf_free(tbfs[0]);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200161}
162
163static void test_alloc_a()
164{
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200165 /* slots 2 - 3 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200166 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x0c, 32*2);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200167 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x0c, 14);
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200168
169 /* slots 1 - 5 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200170 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x1e, 32*4);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200171 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200172}
173
Max2ecf0fd2017-11-21 18:13:31 +0100174static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir, bool verbose)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100175{
Max2ecf0fd2017-11-21 18:13:31 +0100176 if (!verbose)
177 return;
178
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200179 for (size_t i = 0; i < ARRAY_SIZE(tbf->pdch); ++i)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100180 if (tbf->pdch[i])
Neels Hofmeyrd34646a2017-02-08 17:07:40 +0100181 printf("PDCH[%zu] is used for %s\n", i, dir);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100182 printf("PDCH[%d] is control_ts for %s\n", tbf->control_ts, dir);
183 printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir);
184}
185
Max2ecf0fd2017-11-21 18:13:31 +0100186#define ENABLE_PDCH(ts_no, enable_flag, trx) \
187 if (enable_flag) \
188 trx->pdch[ts_no].enable();
189
190static inline void enable_ts_on_bts(struct gprs_rlcmac_bts *bts,
191 bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100192{
Max2ecf0fd2017-11-21 18:13:31 +0100193 struct gprs_rlcmac_trx *trx = &bts->trx[0];
194
195 ENABLE_PDCH(0, ts0, trx);
196 ENABLE_PDCH(1, ts1, trx);
197 ENABLE_PDCH(2, ts2, trx);
198 ENABLE_PDCH(3, ts3, trx);
199 ENABLE_PDCH(4, ts4, trx);
200 ENABLE_PDCH(5, ts5, trx);
201 ENABLE_PDCH(6, ts6, trx);
202 ENABLE_PDCH(7, ts7, trx);
203}
204
205static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
206 uint8_t ms_class, bool verbose)
207{
208 BTS the_bts;
209 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200210 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100211 gprs_rlcmac_ul_tbf *ul_tbf;
212 gprs_rlcmac_dl_tbf *dl_tbf;
213
214 if (verbose)
215 printf("Testing UL then DL assignment.\n");
216
217 bts->alloc_algorithm = alloc_algorithm_b;
218
219 enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
220
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200221 ms = the_bts.ms_alloc(ms_class, 0);
222 ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, true);
Max2ecf0fd2017-11-21 18:13:31 +0100223 if (!ul_tbf)
224 return false;
225
226 OSMO_ASSERT(ul_tbf->ms());
227 OSMO_ASSERT(ul_tbf->ms()->current_trx());
228
229 dump_assignment(ul_tbf, "UL", verbose);
230
231 /* assume final ack has not been sent */
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200232 dl_tbf = tbf_alloc_dl_tbf(bts, ms, ms->current_trx()->trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100233 if (!dl_tbf)
234 return false;
235
236 dump_assignment(dl_tbf, "DL", verbose);
237
238 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
239
240 check_tfi_usage(&the_bts);
241
242 tbf_free(dl_tbf);
243 tbf_free(ul_tbf);
244
245 return true;
246}
247
248static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
249 uint8_t ms_class, bool verbose)
250{
251 BTS the_bts;
252 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200253 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100254 gprs_rlcmac_ul_tbf *ul_tbf;
255 gprs_rlcmac_dl_tbf *dl_tbf;
256
257 if (verbose)
258 printf("Testing DL then UL assignment followed by update\n");
259
260 bts->alloc_algorithm = alloc_algorithm_b;
261
262 enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
263
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200264 ms = the_bts.ms_alloc(ms_class, 0);
265 dl_tbf = tbf_alloc_dl_tbf(bts, ms, -1, true);
Max2ecf0fd2017-11-21 18:13:31 +0100266 if (!dl_tbf)
267 return false;
268
269 dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200270 OSMO_ASSERT(dl_tbf->ms() == ms);
Max2ecf0fd2017-11-21 18:13:31 +0100271 OSMO_ASSERT(dl_tbf->ms()->current_trx());
272
273 dump_assignment(dl_tbf, "DL", verbose);
274
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200275 ul_tbf = tbf_alloc_ul_tbf(bts, ms, ms->current_trx()->trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100276 if (!ul_tbf)
277 return false;
278
279 ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
280 ul_tbf->m_contention_resolution_done = 1;
281
282 dump_assignment(ul_tbf, "UL", verbose);
283
284 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
285
286 /* now update the dl_tbf */
287 dl_tbf->update();
288 dump_assignment(dl_tbf, "DL", verbose);
289 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
290
291 check_tfi_usage(&the_bts);
292
293 tbf_free(dl_tbf);
294 tbf_free(ul_tbf);
295
296 return true;
297}
298
299static inline bool test_alloc_b_jolly(uint8_t ms_class)
300{
301 BTS the_bts;
302 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200303 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100304 int tfi;
305 uint8_t trx_no;
306 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
307
308 printf("Testing jolly example\n");
309
310 bts->alloc_algorithm = alloc_algorithm_b;
311
312 enable_ts_on_bts(bts, false, true, true, true, true, false, false, false);
313
314 tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
315 OSMO_ASSERT(tfi >= 0);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200316 ms = the_bts.ms_alloc(ms_class, 0);
317 ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, false);
Max2ecf0fd2017-11-21 18:13:31 +0100318 if (!ul_tbf)
319 return false;
320
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200321 OSMO_ASSERT(ul_tbf->ms() == ms);
Max2ecf0fd2017-11-21 18:13:31 +0100322 OSMO_ASSERT(ul_tbf->ms()->current_trx());
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200323 trx_no = ms->current_trx()->trx_no;
Max2ecf0fd2017-11-21 18:13:31 +0100324 dump_assignment(ul_tbf, "UL", true);
325
326 /* assume final ack has not been sent */
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200327 dl_tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100328 if (!dl_tbf)
329 return false;
330
331 dump_assignment(dl_tbf, "DL", true);
332
333 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
334
335 check_tfi_usage(&the_bts);
336
337 tbf_free(dl_tbf);
338 tbf_free(ul_tbf);
339
340 return true;
341}
342
343static void test_alloc_b_for_ms(uint8_t ms_class)
344{
345 bool rc;
346
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100347 printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100348 /*
349 * PDCH is on TS 6,7,8 and we start with a UL allocation and
350 * then follow two DL allocations (once single, once normal).
351 *
352 * Uplink assigned and still available..
353 */
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100354
Max2ecf0fd2017-11-21 18:13:31 +0100355 rc = test_alloc_b_ul_dl(false, false, false, false, false, true, true, true, ms_class, true);
356 if (!rc)
357 return;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100358
359 /**
360 * Test with the other order.. first DL and then UL
361 */
Max2ecf0fd2017-11-21 18:13:31 +0100362 rc = test_alloc_b_dl_ul(false, false, false, false, false, true, true, true, ms_class, true);
363 if (!rc)
364 return;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100365
366 /* Andreas osmocom-pcu example */
Max2ecf0fd2017-11-21 18:13:31 +0100367 test_alloc_b_jolly(ms_class);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100368}
369
Max2ecf0fd2017-11-21 18:13:31 +0100370static void test_alloc_mass(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class)
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100371{
Max2ecf0fd2017-11-21 18:13:31 +0100372 bool rc;
373
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100374 /* we can test the allocation failures differently */
375 if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7)
376 return;
377
378 printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n",
379 ts0 ? 'O' : 'x',
380 ts1 ? 'O' : 'x',
381 ts2 ? 'O' : 'x',
382 ts3 ? 'O' : 'x',
383 ts4 ? 'O' : 'x',
384 ts5 ? 'O' : 'x',
385 ts6 ? 'O' : 'x',
386 ts7 ? 'O' : 'x', ms_class);
387 fflush(stdout);
388
Max2ecf0fd2017-11-21 18:13:31 +0100389 rc = test_alloc_b_ul_dl(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
390 if (!rc)
391 return;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100392
393 /**
394 * Test with the other order.. first DL and then UL
395 */
Max2ecf0fd2017-11-21 18:13:31 +0100396 test_alloc_b_dl_ul(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100397}
398
399static void test_all_alloc_b()
400{
401 /* it is a bit crazy... */
402 for (uint8_t ts0 = 0; ts0 < 2; ++ts0)
403 for (uint8_t ts1 = 0; ts1 < 2; ++ts1)
404 for (uint8_t ts2 = 0; ts2 < 2; ++ts2)
405 for (uint8_t ts3 = 0; ts3 < 2; ++ts3)
406 for (uint8_t ts4 = 0; ts4 < 2; ++ts4)
407 for (uint8_t ts5 = 0; ts5 < 2; ++ts5)
408 for (uint8_t ts6 = 0; ts6 < 2; ++ts6)
409 for (uint8_t ts7 = 0; ts7 < 2; ++ts7)
Max9f460712018-01-23 20:57:08 +0100410 for (int ms_class = 0; ms_class < mslot_class_max(); ++ms_class)
Max2ecf0fd2017-11-21 18:13:31 +0100411 test_alloc_mass(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100412}
413
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100414static void test_alloc_b()
415{
Max9f460712018-01-23 20:57:08 +0100416 for (int i = 0; i < mslot_class_max(); ++i)
Max2ecf0fd2017-11-21 18:13:31 +0100417 test_alloc_b_for_ms(i);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100418
419 test_all_alloc_b();
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100420}
421
Maxe9fe0e32017-09-28 15:56:05 +0200422typedef int (*algo_t)(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf, bool single,
423 int8_t use_trx);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200424
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200425static char get_dir_char(uint8_t mask, uint8_t tx, uint8_t rx, uint8_t busy)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200426{
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200427 int offs = busy ? 32 : 0;
428 return (mask & tx & rx) ? 'C' + offs :
429 (mask & tx) ? 'U' + offs :
430 (mask & rx) ? 'D' + offs :
Jacob Erlbecke5655642015-06-29 12:19:52 +0200431 '.';
432}
433
434enum test_mode {
435 TEST_MODE_UL_ONLY,
436 TEST_MODE_DL_ONLY,
437 TEST_MODE_UL_AND_DL,
438 TEST_MODE_DL_AND_UL,
439 TEST_MODE_DL_AFTER_UL,
440 TEST_MODE_UL_AFTER_DL,
441};
442
Maxc59ef122017-11-27 13:21:41 +0100443static inline char *test_mode_descr(enum test_mode t)
444{
445 switch (t) {
446 case TEST_MODE_UL_ONLY: return (char*)"UL only";
447 case TEST_MODE_DL_ONLY: return (char*)"DL only";
448 case TEST_MODE_UL_AND_DL: return (char*)"UL and DL";
449 case TEST_MODE_DL_AND_UL: return (char*)"DL and UL";
450 case TEST_MODE_DL_AFTER_UL: return (char*)"DL after UL";
451 case TEST_MODE_UL_AFTER_DL: return (char*)"UL after DL";
452 default: return NULL;
453 }
454}
455
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200456static GprsMs *alloc_tbfs(BTS *the_bts, GprsMs *ms, enum test_mode mode)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200457{
458 struct gprs_rlcmac_bts *bts;
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200459 uint8_t trx_no = -1;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200460
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200461 OSMO_ASSERT(ms != NULL);
462
Jacob Erlbecke5655642015-06-29 12:19:52 +0200463 bts = the_bts->bts_data();
464
465 gprs_rlcmac_tbf *tbf = NULL;
466
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200467 if (ms && ms->current_trx())
468 trx_no = ms->current_trx()->trx_no;
469
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200470 GprsMs::Guard guard1(ms);
471
Jacob Erlbecke5655642015-06-29 12:19:52 +0200472 /* Allocate what is needed first */
473 switch (mode) {
474 case TEST_MODE_UL_ONLY:
475 case TEST_MODE_DL_AFTER_UL:
476 case TEST_MODE_UL_AND_DL:
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200477 if (ms->ul_tbf())
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200478 tbf_free(ms->ul_tbf());
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200479 tbf = tbf_alloc_ul_tbf(bts, ms, trx_no, false);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200480 if (tbf == NULL)
481 return NULL;
482 break;
483 case TEST_MODE_DL_ONLY:
484 case TEST_MODE_UL_AFTER_DL:
485 case TEST_MODE_DL_AND_UL:
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200486 if (ms->dl_tbf())
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200487 tbf_free(ms->dl_tbf());
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200488 tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, false);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200489 if (tbf == NULL)
490 return NULL;
491 }
492
493 OSMO_ASSERT(tbf);
494 OSMO_ASSERT(tbf->ms());
495 OSMO_ASSERT(ms == NULL || ms == tbf->ms());
496 ms = tbf->ms();
497
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200498 GprsMs::Guard guard2(ms);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200499
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200500 /* Continue with what is needed next */
501 switch (mode) {
502 case TEST_MODE_UL_ONLY:
503 case TEST_MODE_DL_ONLY:
504 /* We are done */
505 break;
506
507 case TEST_MODE_DL_AFTER_UL:
508 case TEST_MODE_UL_AND_DL:
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200509 ms = alloc_tbfs(the_bts, ms, TEST_MODE_DL_ONLY);
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200510 break;
511
512 case TEST_MODE_UL_AFTER_DL:
513 case TEST_MODE_DL_AND_UL:
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200514 ms = alloc_tbfs(the_bts, ms, TEST_MODE_UL_ONLY);
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200515 break;
516 }
517
Jacob Erlbecke5655642015-06-29 12:19:52 +0200518 /* Optionally delete the TBF */
519 switch (mode) {
520 case TEST_MODE_DL_AFTER_UL:
521 case TEST_MODE_UL_AFTER_DL:
522 tbf_free(tbf);
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200523 tbf = NULL;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200524 break;
525
526 default:
527 break;
528 }
529
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200530 if (!ms && tbf)
531 tbf_free(tbf);
532
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200533 return guard2.is_idle() ? NULL : ms;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200534}
535
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200536static unsigned alloc_many_tbfs(BTS *the_bts, unsigned min_class,
537 unsigned max_class, enum test_mode mode)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200538{
Jacob Erlbecke5655642015-06-29 12:19:52 +0200539 unsigned counter;
540 unsigned ms_class = min_class;
541
Jacob Erlbecke5655642015-06-29 12:19:52 +0200542 for (counter = 0; 1; counter += 1) {
543 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
544 uint8_t ul_slots = 0;
545 uint8_t dl_slots = 0;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200546 uint8_t busy_slots = 0;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200547 unsigned i;
548 int tfi = -1;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200549 int tfi2;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200550 uint8_t trx_no2;
551 struct gprs_rlcmac_trx *trx;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200552 GprsMs *ms;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200553 enum gprs_rlcmac_tbf_direction dir;
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200554 uint32_t tlli = counter + 0xc0000000;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200555
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200556 ms = the_bts->ms_by_tlli(tlli);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200557 if (!ms)
558 ms = the_bts->ms_alloc(0, 0);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200559 ms->set_ms_class(ms_class);
560 ms = alloc_tbfs(the_bts, ms, mode);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200561 if (!ms)
562 break;
563
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200564 ms->set_tlli(tlli);
565
Jacob Erlbecke5655642015-06-29 12:19:52 +0200566 ul_tbf = ms->ul_tbf();
567 dl_tbf = ms->dl_tbf();
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200568 trx = ms->current_trx();
569
570 OSMO_ASSERT(ul_tbf || dl_tbf);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200571
572 if (ul_tbf) {
573 ul_slots = 1 << ul_tbf->first_common_ts;
574 tfi = ul_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200575 dir = GPRS_RLCMAC_UL_TBF;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200576 } else {
Jacob Erlbecke5655642015-06-29 12:19:52 +0200577 ul_slots = 1 << dl_tbf->first_common_ts;
578 tfi = dl_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200579 dir = GPRS_RLCMAC_DL_TBF;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200580 }
581
582 for (i = 0; dl_tbf && i < ARRAY_SIZE(dl_tbf->pdch); i += 1)
583 if (dl_tbf->pdch[i])
584 dl_slots |= 1 << i;
585
Max5b0df1f2017-09-11 10:38:59 +0200586 for (i = 0; ul_tbf && i < ARRAY_SIZE(ul_tbf->pdch); i += 1)
587 if (ul_tbf->pdch[i])
588 ul_slots |= 1 << i;
589
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200590 for (i = 0; trx && i < ARRAY_SIZE(trx->pdch); i += 1) {
591 struct gprs_rlcmac_pdch *pdch = &trx->pdch[i];
592
593 if (ul_tbf && dl_tbf)
594 continue;
595
596 if (ul_tbf &&
Maxd000d802017-09-20 17:55:28 +0200597 pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) != NO_FREE_TFI)
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200598 continue;
599
600 if (dl_tbf &&
Maxd000d802017-09-20 17:55:28 +0200601 pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) != NO_FREE_TFI)
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200602 continue;
603
604 busy_slots |= 1 << i;
605 }
606
Maxd000d802017-09-20 17:55:28 +0200607 printf(" TBF[%d] class %d reserves " OSMO_BIT_SPEC "\n",
Jacob Erlbecke5655642015-06-29 12:19:52 +0200608 tfi, ms_class,
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200609 get_dir_char(0x01, ul_slots, dl_slots, busy_slots),
610 get_dir_char(0x02, ul_slots, dl_slots, busy_slots),
611 get_dir_char(0x04, ul_slots, dl_slots, busy_slots),
612 get_dir_char(0x08, ul_slots, dl_slots, busy_slots),
613 get_dir_char(0x10, ul_slots, dl_slots, busy_slots),
614 get_dir_char(0x20, ul_slots, dl_slots, busy_slots),
615 get_dir_char(0x40, ul_slots, dl_slots, busy_slots),
616 get_dir_char(0x80, ul_slots, dl_slots, busy_slots));
Jacob Erlbecke5655642015-06-29 12:19:52 +0200617
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200618 if (tfi >= 0) {
619 OSMO_ASSERT(ms->current_trx());
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200620 tfi2 = the_bts->tfi_find_free(dir, &trx_no2,
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200621 ms->current_trx()->trx_no);
622 OSMO_ASSERT(tfi != tfi2);
Jacob Erlbeck7b3675b2015-07-16 18:28:22 +0200623 OSMO_ASSERT(tfi2 < 0 ||
624 trx_no2 == ms->current_trx()->trx_no);
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200625 }
626
Jacob Erlbecke5655642015-06-29 12:19:52 +0200627 ms_class += 1;
628 if (ms_class > max_class)
629 ms_class = min_class;
630 }
631
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200632 return counter;
633}
634
635static void test_successive_allocation(algo_t algo, unsigned min_class,
636 unsigned max_class, enum test_mode mode,
637 unsigned expect_num, const char *text)
638{
639 BTS the_bts;
640 struct gprs_rlcmac_bts *bts;
641 struct gprs_rlcmac_trx *trx;
642 unsigned counter;
643
Maxc59ef122017-11-27 13:21:41 +0100644 printf("Going to test assignment with many TBF, algorithm %s class %u..%u (%s)\n",
645 text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200646
647 bts = the_bts.bts_data();
648 bts->alloc_algorithm = algo;
649
650 trx = &bts->trx[0];
651 trx->pdch[3].enable();
652 trx->pdch[4].enable();
653 trx->pdch[5].enable();
654 trx->pdch[6].enable();
655 trx->pdch[7].enable();
656
657 counter = alloc_many_tbfs(&the_bts, min_class, max_class, mode);
658
Maxc59ef122017-11-27 13:21:41 +0100659 printf(" Successfully allocated %u UL TBFs, algorithm %s class %u..%u (%s)\n",
660 counter, text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200661 if (counter != expect_num)
Maxc59ef122017-11-27 13:21:41 +0100662 fprintf(stderr, " Expected %u TBFs (got %u), algorithm %s class %u..%u (%s)\n",
663 expect_num, counter, text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200664
Jacob Erlbeckec478752015-06-19 16:35:38 +0200665 OSMO_ASSERT(counter == expect_num);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200666
667 check_tfi_usage(&the_bts);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200668}
669
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200670static void test_many_connections(algo_t algo, unsigned expect_num,
671 const char *text)
672{
673 BTS the_bts;
674 struct gprs_rlcmac_bts *bts;
675 struct gprs_rlcmac_trx *trx;
676 int counter1, counter2 = -1;
677 unsigned i;
678 enum test_mode mode_seq[] = {
679 TEST_MODE_DL_AFTER_UL,
680 TEST_MODE_UL_ONLY,
681 TEST_MODE_DL_AFTER_UL,
682 TEST_MODE_DL_ONLY,
683 };
684
Maxc59ef122017-11-27 13:21:41 +0100685 printf("Going to test assignment with many connections, algorithm %s\n", text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200686
687 bts = the_bts.bts_data();
688 bts->alloc_algorithm = algo;
689
690 trx = &bts->trx[0];
691 trx->pdch[3].enable();
692 trx->pdch[4].enable();
693 trx->pdch[5].enable();
694 trx->pdch[6].enable();
695 trx->pdch[7].enable();
696
697 for (i = 0; i < ARRAY_SIZE(mode_seq); i += 1) {
Max9f460712018-01-23 20:57:08 +0100698 counter1 = alloc_many_tbfs(&the_bts, 1, mslot_class_max(), mode_seq[i]);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200699 fprintf(stderr, " Allocated %d TBFs (previously %d)\n",
700 counter1, counter2);
701
702 check_tfi_usage(&the_bts);
703
704 /* This will stop earlier due to USF shortage */
705 if (mode_seq[i] == TEST_MODE_UL_ONLY)
706 continue;
707
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200708 if (counter2 >= 0) {
709 if (counter1 < counter2)
710 fprintf(stderr, " Expected %d >= %d in %s\n",
711 counter1, counter2, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200712 OSMO_ASSERT(counter1 >= counter2);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200713 }
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200714
715 counter2 = counter1;
716 }
717
718 printf(" Successfully allocated %d TBFs\n", counter1);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200719 if (counter1 != (int)expect_num)
Maxc59ef122017-11-27 13:21:41 +0100720 fprintf(stderr, " Expected %d TBFs (got %d) for algorithm %s\n", expect_num, counter1, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200721
722 OSMO_ASSERT(expect_num == (unsigned)counter1);
723}
724
Maxc59ef122017-11-27 13:21:41 +0100725static inline void test_a_b_dyn(enum test_mode mode, uint8_t exp_A, uint8_t exp_B, uint8_t exp_dyn)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200726{
Maxc59ef122017-11-27 13:21:41 +0100727 test_successive_allocation(alloc_algorithm_a, 1, 1, mode, exp_A, "A");
728 test_successive_allocation(alloc_algorithm_b, 10, 10, mode, exp_B, "B");
729 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, mode, exp_dyn, "dynamic");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200730}
731
Maxc59ef122017-11-27 13:21:41 +0100732static void test_successive_allocations()
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200733{
Maxc59ef122017-11-27 13:21:41 +0100734 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AND_DL, 35, "A");
735 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AND_DL, 32, "B");
736 test_successive_allocation(alloc_algorithm_b, 12, 12, TEST_MODE_UL_AND_DL, 32, "B");
737
Max9f460712018-01-23 20:57:08 +0100738 test_successive_allocation(alloc_algorithm_b, 1, 12, TEST_MODE_UL_AND_DL, 32, "B");
Max01bd0cc2018-01-23 20:58:49 +0100739 test_successive_allocation(alloc_algorithm_b, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 32, "B");
Max9f460712018-01-23 20:57:08 +0100740 test_successive_allocation(alloc_algorithm_dynamic, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 35, "dynamic");
Maxc59ef122017-11-27 13:21:41 +0100741
742 test_a_b_dyn(TEST_MODE_DL_AND_UL, 35, 32, 32);
743 test_a_b_dyn(TEST_MODE_DL_AFTER_UL, 160, 32, 95);
744 test_a_b_dyn(TEST_MODE_UL_AFTER_DL, 35, 32, 35);
745 test_a_b_dyn(TEST_MODE_UL_ONLY, 35, 32, 35);
746 test_a_b_dyn(TEST_MODE_DL_ONLY, 160, 32, 101);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200747}
748
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530749static void test_2_consecutive_dl_tbfs()
750{
751 BTS the_bts;
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200752 GprsMs *ms;
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530753 struct gprs_rlcmac_bts *bts;
754 struct gprs_rlcmac_trx *trx;
755 uint8_t ms_class = 11;
756 uint8_t egprs_ms_class = 11;
757 gprs_rlcmac_tbf *dl_tbf1, *dl_tbf2;
758 uint8_t numTs1 = 0, numTs2 = 0;
759
760 printf("Testing DL TS allocation for Multi UEs\n");
761
762 bts = the_bts.bts_data();
763 bts->alloc_algorithm = alloc_algorithm_b;
764
765 trx = &bts->trx[0];
766 trx->pdch[4].enable();
767 trx->pdch[5].enable();
768 trx->pdch[6].enable();
769 trx->pdch[7].enable();
770
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200771 ms = the_bts.ms_alloc(ms_class, egprs_ms_class);
772 dl_tbf1 = tbf_alloc_dl_tbf(bts, ms, 0, false);
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530773 OSMO_ASSERT(dl_tbf1);
774
775 for (int i = 0; i < 8; i++) {
776 if (dl_tbf1->pdch[i])
777 numTs1++;
778 }
779 OSMO_ASSERT(numTs1 == 4);
780 printf("TBF1: numTs(%d)\n", numTs1);
781
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200782 ms = the_bts.ms_alloc(ms_class, egprs_ms_class);
783 dl_tbf2 = tbf_alloc_dl_tbf(bts, ms, 0, false);
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530784 OSMO_ASSERT(dl_tbf2);
785
786 for (int i = 0; i < 8; i++) {
787 if (dl_tbf2->pdch[i])
788 numTs2++;
789 }
790
791 /*
792 * TODO: currently 2nd DL TBF gets 3 TS
793 * This behaviour will be fixed in subsequent patch
794 */
795 printf("TBF2: numTs(%d)\n", numTs2);
796 OSMO_ASSERT(numTs2 == 3);
797
798 tbf_free(dl_tbf1);
799 tbf_free(dl_tbf2);
800}
801
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200802int main(int argc, char **argv)
803{
804 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
805 if (!tall_pcu_ctx)
806 abort();
807
Neels Hofmeyr78ce5912017-02-08 17:07:31 +0100808 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200809 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200810 log_set_use_color(osmo_stderr_target, 0);
811 log_set_print_filename(osmo_stderr_target, 0);
Philipp Maierde0e5582020-03-25 12:23:52 +0100812 log_set_category_filter(osmo_stderr_target, DTBF, 1, LOGL_INFO);
Jacob Erlbeck9ec49e22015-06-29 13:00:20 +0200813 if (getenv("LOGL_DEBUG"))
814 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200815
816 test_alloc_a();
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100817 test_alloc_b();
Maxc59ef122017-11-27 13:21:41 +0100818 test_successive_allocations();
819 test_many_connections(alloc_algorithm_a, 160, "A");
Max01bd0cc2018-01-23 20:58:49 +0100820 test_many_connections(alloc_algorithm_b, 32, "B");
Maxc59ef122017-11-27 13:21:41 +0100821 test_many_connections(alloc_algorithm_dynamic, 160, "dynamic");
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530822 test_2_consecutive_dl_tbfs();
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200823 return EXIT_SUCCESS;
824}
825
826/*
827 * stubs that should not be reached
828 */
829extern "C" {
830void l1if_pdch_req() { abort(); }
831void l1if_connect_pdch() { abort(); }
832void l1if_close_pdch() { abort(); }
833void l1if_open_pdch() { abort(); }
834}