Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 1 | module RemsimBankd_Tests { |
| 2 | |
| 3 | /* Integration Tests for osmo-remsim-bankd |
| 4 | * (C) 2019 by Harald Welte <laforge@gnumonks.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | * |
| 12 | * This test suite tests osmo-remsim-bankd by attaching to the external interfaces |
| 13 | * such as RSPRO for simulated clients + server. |
| 14 | */ |
| 15 | |
| 16 | import from Osmocom_Types all; |
| 17 | import from IPA_Emulation all; |
| 18 | import from Misc_Helpers all; |
| 19 | |
| 20 | import from RSPRO all; |
| 21 | import from RSRES all; |
| 22 | import from RSPRO_Types all; |
| 23 | import from RSPRO_Server all; |
| 24 | import from REMSIM_Tests all; |
| 25 | |
| 26 | modulepar { |
| 27 | integer mp_bank_id := 1; |
| 28 | integer mp_num_slots := 8; |
| 29 | } |
| 30 | |
| 31 | /* We implement a RSPRO server to simulate the remsim-server and a |
| 32 | RSPRO client to simulate a remsim-client connecting to bankd */ |
| 33 | type component bankd_test_CT extends rspro_server_CT, rspro_client_CT { |
| 34 | } |
| 35 | |
| 36 | private function f_init(boolean start_client := false) runs on bankd_test_CT { |
| 37 | var ComponentIdentity srv_comp_id := valueof(ts_CompId(remsimServer, "ttcn-server")); |
| 38 | |
| 39 | f_rspro_srv_init(0, mp_server_ip, mp_server_port, srv_comp_id); |
| 40 | |
| 41 | if (start_client) { |
| 42 | f_init_client(0); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | private function f_init_client(integer i := 0) runs on rspro_client_CT { |
| 47 | var ComponentIdentity clnt_comp_id := valueof(ts_CompId(remsimClient, "ttcn-client")); |
| 48 | f_rspro_init(rspro[0], mp_bankd_ip, mp_bankd_port, clnt_comp_id, 0); |
| 49 | rspro[0].rspro_client_slot := { clientId := 23+i, slotNr := 0 }; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | /* Test if the bankd disconnects the TCP/IPA session if we don't respond to connectBankReq */ |
| 55 | testcase TC_connectBankReq_timeout() runs on bankd_test_CT { |
| 56 | timer T := 20.0; |
| 57 | f_init(); |
| 58 | |
| 59 | f_rspro_srv_exp(tr_RSPRO_ConnectBankReq(?, ?, ?)); |
| 60 | T.start; |
| 61 | alt { |
| 62 | [] RSPRO_SRV[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) { |
| 63 | setverdict(pass); |
| 64 | } |
| 65 | [] RSPRO_SRV[0].receive { repeat; } |
| 66 | [] T.timeout { |
| 67 | setverdict(fail, "Timeout waiting for disconnect"); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /* accept an inbound connection from bankd to simulated server */ |
| 73 | testcase TC_connectBankReq() runs on bankd_test_CT { |
| 74 | f_init(); |
| 75 | |
| 76 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
| 77 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 78 | } |
| 79 | |
| 80 | /* attempt to create a mapping */ |
| 81 | testcase TC_createMapping() runs on bankd_test_CT { |
| 82 | f_init(); |
| 83 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 84 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 85 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 86 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 87 | f_rspro_srv_create_slotmap(cs, bs); |
| 88 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 89 | } |
| 90 | |
| 91 | /* attempt to create a mapping for a slot that already has a mapping */ |
| 92 | testcase TC_createMapping_busySlot() runs on bankd_test_CT { |
| 93 | f_init(); |
| 94 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 95 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 96 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 97 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 98 | f_rspro_srv_create_slotmap(cs, bs); |
| 99 | f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId); |
| 100 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 101 | } |
| 102 | |
| 103 | /* attempt to create a mapping for an out-of-range slot number */ |
| 104 | testcase TC_createMapping_invalidSlot() runs on bankd_test_CT { |
| 105 | f_init(); |
| 106 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 107 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 108 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 200 }; |
| 109 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 110 | f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId); |
| 111 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 112 | } |
| 113 | |
| 114 | /* attempt to create a mapping for an invalid bankID */ |
| 115 | testcase TC_createMapping_invalidBank() runs on bankd_test_CT { |
| 116 | f_init(); |
| 117 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 118 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 119 | var BankSlot bs := { bankId := 200, slotNr := 0 }; |
| 120 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 121 | f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalBankId); |
| 122 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 123 | } |
| 124 | |
| 125 | /* attempt to remove a non-existant mapping */ |
| 126 | testcase TC_removeMapping_unknownMap() runs on bankd_test_CT { |
| 127 | f_init(); |
| 128 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 129 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 130 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 131 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 132 | f_rspro_srv_remove_slotmap(cs, bs, exp_res := unknownSlotmap); |
| 133 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 134 | } |
| 135 | |
| 136 | /* add and then remove a mapping, expect both to be successful */ |
| 137 | testcase TC_removeMapping() runs on bankd_test_CT { |
| 138 | f_init(); |
| 139 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 140 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 141 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 142 | var ClientSlot cs := { clientId := 23, slotNr := 42 }; |
| 143 | f_rspro_srv_create_slotmap(cs, bs); |
| 144 | f_rspro_srv_remove_slotmap(cs, bs); |
| 145 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 146 | } |
| 147 | |
| 148 | /* connect from client to bankd without specifying a clientId */ |
| 149 | testcase TC_clientConnect_missingSlot() runs on bankd_test_CT { |
| 150 | f_init_client(0); |
| 151 | RSPRO[0].send(ts_RSPRO_ConnectClientReq(rspro[0].rspro_id, omit)); |
| 152 | f_rspro_exp(tr_RSPRO_ConnectClientRes(?, ResultCode:illegalClientId), 0); |
| 153 | f_rspro_exp_disconnect(0); |
| 154 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 155 | } |
| 156 | |
| 157 | /* connect from client to bankd using a clientId for which bankd has no map */ |
| 158 | testcase TC_clientConnect_unknown() runs on bankd_test_CT { |
| 159 | f_init_client(0); |
| 160 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 161 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 162 | } |
| 163 | |
| 164 | /* connect from client to bankd using a clientSlot for which bankd has no map */ |
| 165 | |
| 166 | |
| 167 | /* first connect client, then later add matching mapping from server */ |
| 168 | testcase TC_clientConnect_createMapping() runs on bankd_test_CT { |
| 169 | f_init_client(0); |
| 170 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 171 | |
| 172 | f_init(); |
| 173 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
| 174 | |
| 175 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 176 | f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs); |
| 177 | f_sleep(10.0); |
| 178 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /* first add mapping, then connect matching client */ |
| 183 | testcase TC_createMapping_clientConnect() runs on bankd_test_CT { |
| 184 | /* FIXME: this would only be done in f_init_client(), but we need it before */ |
| 185 | rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 }; |
| 186 | |
| 187 | f_init(); |
| 188 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 189 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 190 | |
| 191 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 192 | f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs); |
| 193 | |
| 194 | f_sleep(1.0); |
| 195 | |
| 196 | f_init_client(0); |
| 197 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 198 | /* FIXME: how to determine that bank correctly mapped us */ |
| 199 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | |
| 204 | /* add mapping, connect matching client, disconnect + reconnect */ |
| 205 | testcase TC_createMapping_clientReconnect() runs on bankd_test_CT { |
| 206 | /* FIXME: this would only be done in f_init_client(), but we need it before */ |
| 207 | rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 }; |
| 208 | |
| 209 | f_init(); |
| 210 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 211 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 212 | |
| 213 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 214 | f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs); |
| 215 | |
| 216 | f_sleep(1.0); |
| 217 | |
| 218 | f_init_client(0); |
| 219 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 220 | /* TODO: works only with empty slot, as setAtrReq isn't handled */ |
| 221 | /* FIXME: how to determine that bank correctly mapped us */ |
| 222 | f_sleep(5.0); |
| 223 | f_rspro_fini(rspro[0], 0); |
| 224 | |
| 225 | f_init_client(0); |
| 226 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 227 | /* FIXME: how to determine that bank correctly mapped us */ |
| 228 | f_sleep(5.0); |
| 229 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | |
| 234 | /* remove mapping while client is connected */ |
| 235 | testcase TC_removeMapping_connected() runs on bankd_test_CT { |
| 236 | f_init_client(0); |
| 237 | f_rspro_connect_client(0, tr_Status_ok_or_nocard); |
| 238 | /* TODO: works only with empty slot, as setAtrReq isn't handled */ |
| 239 | |
| 240 | f_init(); |
| 241 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
| 242 | |
| 243 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 244 | f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs); |
| 245 | /* FIXME: how to determine that bank correctly mapped us */ |
| 246 | f_sleep(5.0); |
| 247 | f_rspro_srv_remove_slotmap(rspro[0].rspro_client_slot, bs); |
| 248 | f_rspro_exp_disconnect(0); |
| 249 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 250 | } |
| 251 | |
| 252 | /* first add mapping, then connect matching client and exchange some TPDUs */ |
| 253 | testcase TC_createMapping_exchangeTPDU() runs on bankd_test_CT { |
| 254 | /* FIXME: this would only be done in f_init_client(), but we need it before */ |
| 255 | rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 }; |
| 256 | |
| 257 | f_init(); |
| 258 | as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots); |
Harald Welte | d14ad4c | 2019-12-04 21:30:29 +0100 | [diff] [blame^] | 259 | f_rspro_srv_reset_state(ok); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 260 | |
| 261 | var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 }; |
| 262 | f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs); |
| 263 | |
| 264 | f_sleep(1.0); |
| 265 | |
| 266 | f_init_client(0); |
| 267 | f_rspro_connect_client(0, ok); |
| 268 | /* FIXME: how to determine that bank correctly mapped us */ |
| 269 | f_rspro_exp(tr_RSPRO_SetAtrReq(rspro[0].rspro_client_slot, ?)); |
| 270 | |
| 271 | var TpduFlags f := {tpduHeaderPresent:=true, finalPart:=true, procByteContinueTx:=false, |
| 272 | procByteContinueRx:=false}; |
| 273 | for (var integer i := 0; i < 10; i:=i+1) { |
| 274 | f_rspro_xceive_mdm2card(0, bs, 'A0A40000023F00'O, f); |
| 275 | } |
| 276 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | control { |
| 282 | execute( TC_connectBankReq_timeout() ); |
| 283 | execute( TC_connectBankReq() ); |
| 284 | |
| 285 | execute( TC_createMapping() ); |
| 286 | execute( TC_createMapping_busySlot() ); |
| 287 | execute( TC_createMapping_invalidSlot() ); |
| 288 | execute( TC_createMapping_invalidBank() ); |
| 289 | |
| 290 | execute( TC_removeMapping_unknownMap() ); |
| 291 | execute( TC_removeMapping() ); |
| 292 | |
| 293 | execute( TC_clientConnect_missingSlot() ); |
| 294 | execute( TC_clientConnect_unknown() ); |
| 295 | execute( TC_clientConnect_createMapping() ); |
| 296 | execute( TC_createMapping_clientConnect() ); |
| 297 | execute( TC_createMapping_clientReconnect() ); |
| 298 | execute( TC_removeMapping_connected() ); |
| 299 | |
| 300 | execute( TC_createMapping_exchangeTPDU() ); |
| 301 | } |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | } |