blob: 1b06b0b8ffd8ff9583b80c75382026cc2acb0958 [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.
Max46fbfce2017-11-01 19:22:25 +010014 */
15
16#include "gprs_rlcmac.h"
17#include "gprs_debug.h"
18#include "tbf.h"
19#include "bts.h"
20
21#include <string.h>
22#include <stdio.h>
23#include <errno.h>
24
25extern "C" {
Max731e2bb2018-02-05 16:15:30 +010026 #include "mslot_class.h"
Max46fbfce2017-11-01 19:22:25 +010027#include <osmocom/core/application.h>
28#include <osmocom/core/msgb.h>
29#include <osmocom/core/talloc.h>
30#include <osmocom/core/utils.h>
31}
32
33/* globals used by the code */
34void *tall_pcu_ctx;
35int16_t spoof_mnc = 0, spoof_mcc = 0;
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +010036bool spoof_mnc_3_digits = false;
Max46fbfce2017-11-01 19:22:25 +010037
38static inline void test_all_classes(struct gprs_rlcmac_trx *trx, bool clear_masks)
39{
40 int i, rc;
41 uint8_t dl_slots = 0, ul_slots = 0;
42
43 for (i = 0; i < 64; i++) {
44 rc = find_multi_slots(trx, i, &ul_slots, &dl_slots);
45
46 printf(" [%s] multislot class %3u - UL: " OSMO_BIT_SPEC " DL: " OSMO_BIT_SPEC " [%d]\n",
47 clear_masks ? "SEQ" : "ACC", i, OSMO_BIT_PRINT(ul_slots), OSMO_BIT_PRINT(dl_slots), rc);
48
49 if (rc == -EINVAL)
50 return;
51
52 if (clear_masks) {
53 dl_slots = 0;
54 ul_slots = 0;
55 }
56 }
57}
58
59static inline void test_multislot_total_ascending(bool seq)
60{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010061 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
Max46fbfce2017-11-01 19:22:25 +010062 struct gprs_rlcmac_trx *trx;
63 int i;
64
65 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
66
Max46fbfce2017-11-01 19:22:25 +010067 trx = &bts->trx[0];
68
69 for (i = 0; i < 8; i++) {
70 printf(" Enabled PDCH %u for multislot tests...\n", i);
71 trx->pdch[i].enable();
72
73 test_all_classes(trx, seq);
74 }
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010075 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +010076}
77
78static inline void test_multislot_total_descending(bool seq)
79{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010080 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
Max46fbfce2017-11-01 19:22:25 +010081 struct gprs_rlcmac_trx *trx;
82 int i;
83
84 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
85
Max46fbfce2017-11-01 19:22:25 +010086 trx = &bts->trx[0];
87
88 for (i = 7; i >= 0; i--) {
89 printf(" Enabled PDCH %u for multislot tests...\n", i);
90 trx->pdch[i].enable();
91
92 test_all_classes(trx, seq);
93 }
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010094 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +010095}
96
97static inline void test_multislot_middle(bool seq)
98{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010099 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
Max46fbfce2017-11-01 19:22:25 +0100100 struct gprs_rlcmac_trx *trx;
101
102 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
103
Max46fbfce2017-11-01 19:22:25 +0100104 trx = &bts->trx[0];
105
106 trx->pdch[2].enable();
107 trx->pdch[3].enable();
108 trx->pdch[4].enable();
109
110 test_all_classes(trx, seq);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100111 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +0100112}
113
114static inline void test_multislot_ends(bool seq)
115{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100116 struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
Max46fbfce2017-11-01 19:22:25 +0100117 struct gprs_rlcmac_trx *trx;
118
119 printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
120
Max46fbfce2017-11-01 19:22:25 +0100121 trx = &bts->trx[0];
122
123 trx->pdch[0].enable();
124 trx->pdch[7].enable();
125
126 test_all_classes(trx, seq);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100127 talloc_free(bts);
Max46fbfce2017-11-01 19:22:25 +0100128}
129
Max731e2bb2018-02-05 16:15:30 +0100130static inline void test_window_wrapper()
131{
132 uint16_t i;
133 for (i = 0; i < 256 * 2 + 1; i++)
134 printf("W[%03u] -> %3u %s\n",
135 i, mslot_wrap_window(i), mslot_wrap_window(i) < 256 ? "OK" : "FAIL");
136}
Max46fbfce2017-11-01 19:22:25 +0100137
138int main(int argc, char **argv)
139{
140 tall_pcu_ctx = talloc_named_const(NULL, 1, "MslotTest context");
141 if (!tall_pcu_ctx)
142 abort();
143
144 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
145
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200146 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Max46fbfce2017-11-01 19:22:25 +0100147 log_set_use_color(osmo_stderr_target, 0);
Pau Espin Pedrol00f52cc2021-02-19 14:01:52 +0100148 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
Max46fbfce2017-11-01 19:22:25 +0100149 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
150
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100151 the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
152
Max46fbfce2017-11-01 19:22:25 +0100153 test_multislot_total_ascending(true);
154 test_multislot_total_ascending(false);
155
156 test_multislot_total_descending(true);
157 test_multislot_total_descending(false);
158
159 test_multislot_middle(true);
160 test_multislot_middle(false);
161
162 test_multislot_ends(true);
163 test_multislot_ends(false);
164
Max731e2bb2018-02-05 16:15:30 +0100165 test_window_wrapper();
166
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100167 talloc_free(the_pcu);
168
Max46fbfce2017-11-01 19:22:25 +0100169 return EXIT_SUCCESS;
170}
171
172/*
173 * stubs that should not be reached
174 */
175extern "C" {
176void l1if_pdch_req() { abort(); }
177void l1if_connect_pdch() { abort(); }
178void l1if_close_pdch() { abort(); }
179void l1if_open_pdch() { abort(); }
180}