blob: b32a828a8445120cf8dcc3db21d88eec02c705e6 [file] [log] [blame]
Max46fbfce2017-11-01 19:22:25 +01001/* MslotTest.cpp
2 *
3 * Copyright (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
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#include "bts.h"
24
25#include <string.h>
26#include <stdio.h>
27#include <errno.h>
28
29extern "C" {
Max731e2bb2018-02-05 16:15:30 +010030 #include "mslot_class.h"
Max46fbfce2017-11-01 19:22:25 +010031#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;
39int16_t spoof_mnc = 0, spoof_mcc = 0;
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +010040bool spoof_mnc_3_digits = false;
Max46fbfce2017-11-01 19:22:25 +010041
42static inline void test_all_classes(struct gprs_rlcmac_trx *trx, bool clear_masks)
43{
44 int i, rc;
45 uint8_t dl_slots = 0, ul_slots = 0;
46
47 for (i = 0; i < 64; i++) {
48 rc = find_multi_slots(trx, i, &ul_slots, &dl_slots);
49
50 printf(" [%s] multislot class %3u - UL: " OSMO_BIT_SPEC " DL: " OSMO_BIT_SPEC " [%d]\n",
51 clear_masks ? "SEQ" : "ACC", i, OSMO_BIT_PRINT(ul_slots), OSMO_BIT_PRINT(dl_slots), rc);
52
53 if (rc == -EINVAL)
54 return;
55
56 if (clear_masks) {
57 dl_slots = 0;
58 ul_slots = 0;
59 }
60 }
61}
62
63static inline void test_multislot_total_ascending(bool seq)
64{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010065 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
Max46fbfce2017-11-01 19:22:25 +010066 struct gprs_rlcmac_trx *trx;
67 int i;
68
69 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
70
Max46fbfce2017-11-01 19:22:25 +010071 trx = &bts->trx[0];
72
73 for (i = 0; i < 8; i++) {
74 printf(" Enabled PDCH %u for multislot tests...\n", i);
75 trx->pdch[i].enable();
76
77 test_all_classes(trx, seq);
78 }
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010079 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +010080}
81
82static inline void test_multislot_total_descending(bool seq)
83{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010084 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
Max46fbfce2017-11-01 19:22:25 +010085 struct gprs_rlcmac_trx *trx;
86 int i;
87
88 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
89
Max46fbfce2017-11-01 19:22:25 +010090 trx = &bts->trx[0];
91
92 for (i = 7; i >= 0; i--) {
93 printf(" Enabled PDCH %u for multislot tests...\n", i);
94 trx->pdch[i].enable();
95
96 test_all_classes(trx, seq);
97 }
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010098 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +010099}
100
101static inline void test_multislot_middle(bool seq)
102{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100103 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
Max46fbfce2017-11-01 19:22:25 +0100104 struct gprs_rlcmac_trx *trx;
105
106 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
107
Max46fbfce2017-11-01 19:22:25 +0100108 trx = &bts->trx[0];
109
110 trx->pdch[2].enable();
111 trx->pdch[3].enable();
112 trx->pdch[4].enable();
113
114 test_all_classes(trx, seq);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100115 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +0100116}
117
118static inline void test_multislot_ends(bool seq)
119{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100120 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
Max46fbfce2017-11-01 19:22:25 +0100121 struct gprs_rlcmac_trx *trx;
122
123 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
124
Max46fbfce2017-11-01 19:22:25 +0100125 trx = &bts->trx[0];
126
127 trx->pdch[0].enable();
128 trx->pdch[7].enable();
129
130 test_all_classes(trx, seq);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100131 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +0100132}
133
Max731e2bb2018-02-05 16:15:30 +0100134static inline void test_window_wrapper()
135{
136 uint16_t i;
137 for (i = 0; i < 256 * 2 + 1; i++)
138 printf("W[%03u] -> %3u %s\n",
139 i, mslot_wrap_window(i), mslot_wrap_window(i) < 256 ? "OK" : "FAIL");
140}
Max46fbfce2017-11-01 19:22:25 +0100141
142int main(int argc, char **argv)
143{
144 tall_pcu_ctx = talloc_named_const(NULL, 1, "MslotTest context");
145 if (!tall_pcu_ctx)
146 abort();
147
148 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
149
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200150 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Max46fbfce2017-11-01 19:22:25 +0100151 log_set_use_color(osmo_stderr_target, 0);
152 log_set_print_filename(osmo_stderr_target, 0);
153 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
154
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100155 the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
156
Max46fbfce2017-11-01 19:22:25 +0100157 test_multislot_total_ascending(true);
158 test_multislot_total_ascending(false);
159
160 test_multislot_total_descending(true);
161 test_multislot_total_descending(false);
162
163 test_multislot_middle(true);
164 test_multislot_middle(false);
165
166 test_multislot_ends(true);
167 test_multislot_ends(false);
168
Max731e2bb2018-02-05 16:15:30 +0100169 test_window_wrapper();
170
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100171 talloc_free(the_pcu);
172
Max46fbfce2017-11-01 19:22:25 +0100173 return EXIT_SUCCESS;
174}
175
176/*
177 * stubs that should not be reached
178 */
179extern "C" {
180void l1if_pdch_req() { abort(); }
181void l1if_connect_pdch() { abort(); }
182void l1if_close_pdch() { abort(); }
183void l1if_open_pdch() { abort(); }
184}