blob: 2117b11a086274463917475b2d46230c1a826ab8 [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;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020036int16_t spoof_mnc = 0, spoof_mcc = 0;
37
38static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count)
39{
40 int tfi;
41 uint8_t used_trx;
42 struct gprs_rlcmac_bts bts;
43 struct gprs_rlcmac_tbf *tbfs[33] = { 0, };
44
45 printf("Testing alloc_a direction(%d)\n", dir);
46
47 memset(&bts, 0, sizeof(bts));
48 bts.alloc_algorithm = alloc_algorithm_a;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020049
50 struct gprs_rlcmac_trx *trx = &bts.trx[0];
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020051 trx->pdch[2].enable();
52 trx->pdch[3].enable();
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020053
54 /**
55 * Currently alloc_a will only allocate from the first
56 * PDCH and all possible usf's. We run out of usf's before
57 * we are out of tfi's. Observe this and make sure that at
58 * least this part is working okay.
59 */
60 for (int i = 0; i < count; ++i) {
61 struct gprs_rlcmac_tbf *tbf;
62
63 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
64 OSMO_ASSERT(tfi >= 0);
65 tbfs[i] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
66 }
67
68 /* Now check that there are still some TFIs */
69 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
70 switch (dir) {
71 case GPRS_RLCMAC_UL_TBF:
72 OSMO_ASSERT(tfi >= 0);
73 break;
74 case GPRS_RLCMAC_DL_TBF:
75 OSMO_ASSERT(tfi < 0);
76 break;
77 }
78 OSMO_ASSERT(!tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0));
79
80 for (int i = 0; i < ARRAY_SIZE(tbfs); ++i)
81 if (tbfs[i])
82 tbf_free(tbfs[i]);
83
84 tfi = tfi_find_free(&bts, dir, &used_trx, 0);
85 OSMO_ASSERT(tfi >= 0);
86
87 tbfs[tfi] = tbf_alloc(&bts, NULL, dir, tfi, used_trx, 0, 0);
88 OSMO_ASSERT(tbfs[tfi]);
89 tbf_free(tbfs[tfi]);
90}
91
92static void test_alloc_a()
93{
94 test_alloc_a(GPRS_RLCMAC_DL_TBF, 32);
95 test_alloc_a(GPRS_RLCMAC_UL_TBF, 7);
96}
97
98int main(int argc, char **argv)
99{
100 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
101 if (!tall_pcu_ctx)
102 abort();
103
104 msgb_set_talloc_ctx(tall_pcu_ctx);
105 osmo_init_logging(&gprs_log_info);
106 log_set_use_color(osmo_stderr_target, 0);
107 log_set_print_filename(osmo_stderr_target, 0);
108
109 test_alloc_a();
110 return EXIT_SUCCESS;
111}
112
113/*
114 * stubs that should not be reached
115 */
116extern "C" {
117void l1if_pdch_req() { abort(); }
118void l1if_connect_pdch() { abort(); }
119void l1if_close_pdch() { abort(); }
120void l1if_open_pdch() { abort(); }
121}