blob: 5790ade10325ef2d518dea9a0cf95d63ecce4a66 [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"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020023#include "bts.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020024
25#include <string.h>
26#include <stdio.h>
27
28extern "C" {
29#include <osmocom/core/application.h>
30#include <osmocom/core/msgb.h>
31#include <osmocom/core/talloc.h>
32#include <osmocom/core/utils.h>
33}
34
35/* globals used by the code */
36void *tall_pcu_ctx;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020037int16_t spoof_mnc = 0, spoof_mcc = 0;
38
39static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count)
40{
41 int tfi;
42 uint8_t used_trx;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020043 BTS the_bts;
44 struct gprs_rlcmac_bts *bts;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020045 struct gprs_rlcmac_tbf *tbfs[33] = { 0, };
46
47 printf("Testing alloc_a direction(%d)\n", dir);
48
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020049 bts = the_bts.bts_data();
50 bts->alloc_algorithm = alloc_algorithm_a;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020051
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020052 struct gprs_rlcmac_trx *trx = &bts->trx[0];
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020053 trx->pdch[2].enable();
54 trx->pdch[3].enable();
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020055
56 /**
57 * Currently alloc_a will only allocate from the first
58 * PDCH and all possible usf's. We run out of usf's before
59 * we are out of tfi's. Observe this and make sure that at
60 * least this part is working okay.
61 */
62 for (int i = 0; i < count; ++i) {
63 struct gprs_rlcmac_tbf *tbf;
64
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +020065 tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020066 OSMO_ASSERT(tfi >= 0);
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020067 tbfs[i] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020068 }
69
70 /* Now check that there are still some TFIs */
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +020071 tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020072 switch (dir) {
73 case GPRS_RLCMAC_UL_TBF:
74 OSMO_ASSERT(tfi >= 0);
75 break;
76 case GPRS_RLCMAC_DL_TBF:
77 OSMO_ASSERT(tfi < 0);
78 break;
79 }
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020080 OSMO_ASSERT(!tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0));
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020081
82 for (int i = 0; i < ARRAY_SIZE(tbfs); ++i)
83 if (tbfs[i])
84 tbf_free(tbfs[i]);
85
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +020086 tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020087 OSMO_ASSERT(tfi >= 0);
88
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020089 tbfs[tfi] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020090 OSMO_ASSERT(tbfs[tfi]);
91 tbf_free(tbfs[tfi]);
92}
93
94static void test_alloc_a()
95{
96 test_alloc_a(GPRS_RLCMAC_DL_TBF, 32);
97 test_alloc_a(GPRS_RLCMAC_UL_TBF, 7);
98}
99
100int main(int argc, char **argv)
101{
102 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
103 if (!tall_pcu_ctx)
104 abort();
105
106 msgb_set_talloc_ctx(tall_pcu_ctx);
107 osmo_init_logging(&gprs_log_info);
108 log_set_use_color(osmo_stderr_target, 0);
109 log_set_print_filename(osmo_stderr_target, 0);
110
111 test_alloc_a();
112 return EXIT_SUCCESS;
113}
114
115/*
116 * stubs that should not be reached
117 */
118extern "C" {
119void l1if_pdch_req() { abort(); }
120void l1if_connect_pdch() { abort(); }
121void l1if_close_pdch() { abort(); }
122void l1if_open_pdch() { abort(); }
123}