blob: 3d58f5091b64d6c679bf2697d4d9938410e7b01e [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"
23
24#include <string.h>
25#include <stdio.h>
26
27extern "C" {
28#include <osmocom/core/application.h>
29#include <osmocom/core/msgb.h>
30#include <osmocom/core/talloc.h>
31#include <osmocom/core/utils.h>
32}
33
34/* globals used by the code */
35void *tall_pcu_ctx;
36struct gprs_rlcmac_bts *gprs_rlcmac_bts;
37int16_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;
43 struct gprs_rlcmac_bts bts;
44 struct gprs_rlcmac_tbf *tbfs[33] = { 0, };
45
46 printf("Testing alloc_a direction(%d)\n", dir);
47
48 memset(&bts, 0, sizeof(bts));
49 bts.alloc_algorithm = alloc_algorithm_a;
50 gprs_rlcmac_bts = &bts;
51
52 struct gprs_rlcmac_trx *trx = &bts.trx[0];
53 trx->pdch[2].enable = 1;
54 trx->pdch[3].enable = 1;
55
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
65 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
66 OSMO_ASSERT(tfi >= 0);
67 tbfs[i] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
68 }
69
70 /* Now check that there are still some TFIs */
71 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
72 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 }
80 OSMO_ASSERT(!tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0));
81
82 for (int i = 0; i < ARRAY_SIZE(tbfs); ++i)
83 if (tbfs[i])
84 tbf_free(tbfs[i]);
85
86 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
87 OSMO_ASSERT(tfi >= 0);
88
89 tbfs[tfi] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
90 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}