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" { |
| 30 | #include <osmocom/core/application.h> |
| 31 | #include <osmocom/core/msgb.h> |
| 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/utils.h> |
| 34 | } |
| 35 | |
| 36 | /* globals used by the code */ |
| 37 | void *tall_pcu_ctx; |
| 38 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 39 | |
| 40 | static inline void test_all_classes(struct gprs_rlcmac_trx *trx, bool clear_masks) |
| 41 | { |
| 42 | int i, rc; |
| 43 | uint8_t dl_slots = 0, ul_slots = 0; |
| 44 | |
| 45 | for (i = 0; i < 64; i++) { |
| 46 | rc = find_multi_slots(trx, i, &ul_slots, &dl_slots); |
| 47 | |
| 48 | printf(" [%s] multislot class %3u - UL: " OSMO_BIT_SPEC " DL: " OSMO_BIT_SPEC " [%d]\n", |
| 49 | clear_masks ? "SEQ" : "ACC", i, OSMO_BIT_PRINT(ul_slots), OSMO_BIT_PRINT(dl_slots), rc); |
| 50 | |
| 51 | if (rc == -EINVAL) |
| 52 | return; |
| 53 | |
| 54 | if (clear_masks) { |
| 55 | dl_slots = 0; |
| 56 | ul_slots = 0; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | static inline void test_multislot_total_ascending(bool seq) |
| 62 | { |
| 63 | BTS the_bts; |
| 64 | struct gprs_rlcmac_bts *bts; |
| 65 | struct gprs_rlcmac_trx *trx; |
| 66 | int i; |
| 67 | |
| 68 | printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative"); |
| 69 | |
| 70 | bts = the_bts.bts_data(); |
| 71 | |
| 72 | trx = &bts->trx[0]; |
| 73 | |
| 74 | for (i = 0; i < 8; i++) { |
| 75 | printf(" Enabled PDCH %u for multislot tests...\n", i); |
| 76 | trx->pdch[i].enable(); |
| 77 | |
| 78 | test_all_classes(trx, seq); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static inline void test_multislot_total_descending(bool seq) |
| 83 | { |
| 84 | BTS the_bts; |
| 85 | struct gprs_rlcmac_bts *bts; |
| 86 | struct gprs_rlcmac_trx *trx; |
| 87 | int i; |
| 88 | |
| 89 | printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative"); |
| 90 | |
| 91 | bts = the_bts.bts_data(); |
| 92 | |
| 93 | trx = &bts->trx[0]; |
| 94 | |
| 95 | for (i = 7; i >= 0; i--) { |
| 96 | printf(" Enabled PDCH %u for multislot tests...\n", i); |
| 97 | trx->pdch[i].enable(); |
| 98 | |
| 99 | test_all_classes(trx, seq); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static inline void test_multislot_middle(bool seq) |
| 104 | { |
| 105 | BTS the_bts; |
| 106 | struct gprs_rlcmac_bts *bts; |
| 107 | struct gprs_rlcmac_trx *trx; |
| 108 | |
| 109 | printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative"); |
| 110 | |
| 111 | bts = the_bts.bts_data(); |
| 112 | |
| 113 | trx = &bts->trx[0]; |
| 114 | |
| 115 | trx->pdch[2].enable(); |
| 116 | trx->pdch[3].enable(); |
| 117 | trx->pdch[4].enable(); |
| 118 | |
| 119 | test_all_classes(trx, seq); |
| 120 | } |
| 121 | |
| 122 | static inline void test_multislot_ends(bool seq) |
| 123 | { |
| 124 | BTS the_bts; |
| 125 | struct gprs_rlcmac_bts *bts; |
| 126 | struct gprs_rlcmac_trx *trx; |
| 127 | |
| 128 | printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative"); |
| 129 | |
| 130 | bts = the_bts.bts_data(); |
| 131 | |
| 132 | trx = &bts->trx[0]; |
| 133 | |
| 134 | trx->pdch[0].enable(); |
| 135 | trx->pdch[7].enable(); |
| 136 | |
| 137 | test_all_classes(trx, seq); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | int main(int argc, char **argv) |
| 142 | { |
| 143 | tall_pcu_ctx = talloc_named_const(NULL, 1, "MslotTest context"); |
| 144 | if (!tall_pcu_ctx) |
| 145 | abort(); |
| 146 | |
| 147 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
| 148 | |
| 149 | osmo_init_logging(&gprs_log_info); |
| 150 | log_set_use_color(osmo_stderr_target, 0); |
| 151 | log_set_print_filename(osmo_stderr_target, 0); |
| 152 | log_set_log_level(osmo_stderr_target, LOGL_DEBUG); |
| 153 | |
| 154 | test_multislot_total_ascending(true); |
| 155 | test_multislot_total_ascending(false); |
| 156 | |
| 157 | test_multislot_total_descending(true); |
| 158 | test_multislot_total_descending(false); |
| 159 | |
| 160 | test_multislot_middle(true); |
| 161 | test_multislot_middle(false); |
| 162 | |
| 163 | test_multislot_ends(true); |
| 164 | test_multislot_ends(false); |
| 165 | |
| 166 | return EXIT_SUCCESS; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * stubs that should not be reached |
| 171 | */ |
| 172 | extern "C" { |
| 173 | void l1if_pdch_req() { abort(); } |
| 174 | void l1if_connect_pdch() { abort(); } |
| 175 | void l1if_close_pdch() { abort(); } |
| 176 | void l1if_open_pdch() { abort(); } |
| 177 | } |