blob: 8910e52a1f18eccfab552841649f299a06115284 [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{
65 BTS the_bts;
66 struct gprs_rlcmac_bts *bts;
67 struct gprs_rlcmac_trx *trx;
68 int i;
69
70 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
71
72 bts = the_bts.bts_data();
73
74 trx = &bts->trx[0];
75
76 for (i = 0; i < 8; i++) {
77 printf(" Enabled PDCH %u for multislot tests...\n", i);
78 trx->pdch[i].enable();
79
80 test_all_classes(trx, seq);
81 }
82}
83
84static inline void test_multislot_total_descending(bool seq)
85{
86 BTS the_bts;
87 struct gprs_rlcmac_bts *bts;
88 struct gprs_rlcmac_trx *trx;
89 int i;
90
91 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
92
93 bts = the_bts.bts_data();
94
95 trx = &bts->trx[0];
96
97 for (i = 7; i >= 0; i--) {
98 printf(" Enabled PDCH %u for multislot tests...\n", i);
99 trx->pdch[i].enable();
100
101 test_all_classes(trx, seq);
102 }
103}
104
105static inline void test_multislot_middle(bool seq)
106{
107 BTS the_bts;
108 struct gprs_rlcmac_bts *bts;
109 struct gprs_rlcmac_trx *trx;
110
111 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
112
113 bts = the_bts.bts_data();
114
115 trx = &bts->trx[0];
116
117 trx->pdch[2].enable();
118 trx->pdch[3].enable();
119 trx->pdch[4].enable();
120
121 test_all_classes(trx, seq);
122}
123
124static inline void test_multislot_ends(bool seq)
125{
126 BTS the_bts;
127 struct gprs_rlcmac_bts *bts;
128 struct gprs_rlcmac_trx *trx;
129
130 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
131
132 bts = the_bts.bts_data();
133
134 trx = &bts->trx[0];
135
136 trx->pdch[0].enable();
137 trx->pdch[7].enable();
138
139 test_all_classes(trx, seq);
140}
141
Max731e2bb2018-02-05 16:15:30 +0100142static inline void test_window_wrapper()
143{
144 uint16_t i;
145 for (i = 0; i < 256 * 2 + 1; i++)
146 printf("W[%03u] -> %3u %s\n",
147 i, mslot_wrap_window(i), mslot_wrap_window(i) < 256 ? "OK" : "FAIL");
148}
Max46fbfce2017-11-01 19:22:25 +0100149
150int main(int argc, char **argv)
151{
152 tall_pcu_ctx = talloc_named_const(NULL, 1, "MslotTest context");
153 if (!tall_pcu_ctx)
154 abort();
155
156 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
157
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200158 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Max46fbfce2017-11-01 19:22:25 +0100159 log_set_use_color(osmo_stderr_target, 0);
160 log_set_print_filename(osmo_stderr_target, 0);
161 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
162
163 test_multislot_total_ascending(true);
164 test_multislot_total_ascending(false);
165
166 test_multislot_total_descending(true);
167 test_multislot_total_descending(false);
168
169 test_multislot_middle(true);
170 test_multislot_middle(false);
171
172 test_multislot_ends(true);
173 test_multislot_ends(false);
174
Max731e2bb2018-02-05 16:15:30 +0100175 test_window_wrapper();
176
Max46fbfce2017-11-01 19:22:25 +0100177 return EXIT_SUCCESS;
178}
179
180/*
181 * stubs that should not be reached
182 */
183extern "C" {
184void l1if_pdch_req() { abort(); }
185void l1if_connect_pdch() { abort(); }
186void l1if_close_pdch() { abort(); }
187void l1if_open_pdch() { abort(); }
188}