Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 1 | /* 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 | |
| 29 | extern "C" { |
Max | 731e2bb | 2018-02-05 16:15:30 +0100 | [diff] [blame] | 30 | #include "mslot_class.h" |
Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 31 | #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 */ |
| 38 | void *tall_pcu_ctx; |
| 39 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 40 | bool spoof_mnc_3_digits = false; |
Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 41 | |
| 42 | static 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 | |
| 63 | static 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 | |
| 84 | static 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 | |
| 105 | static 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 | |
| 124 | static 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 | |
Max | 731e2bb | 2018-02-05 16:15:30 +0100 | [diff] [blame] | 142 | static 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 | } |
Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 149 | |
| 150 | int 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 Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 158 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 159 | 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 | |
Max | 731e2bb | 2018-02-05 16:15:30 +0100 | [diff] [blame] | 175 | test_window_wrapper(); |
| 176 | |
Max | 46fbfce | 2017-11-01 19:22:25 +0100 | [diff] [blame] | 177 | return EXIT_SUCCESS; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * stubs that should not be reached |
| 182 | */ |
| 183 | extern "C" { |
| 184 | void l1if_pdch_req() { abort(); } |
| 185 | void l1if_connect_pdch() { abort(); } |
| 186 | void l1if_close_pdch() { abort(); } |
| 187 | void l1if_open_pdch() { abort(); } |
| 188 | } |