blob: e86dc1660df9dc398d94a701650745e382555e22 [file] [log] [blame]
Harald Weltefaa42922019-03-04 18:31:11 +01001module 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
16import from Osmocom_Types all;
17import from IPA_Emulation all;
18import from Misc_Helpers all;
19
20import from RSPRO all;
21import from RSRES all;
22import from RSPRO_Types all;
23import from RSPRO_Server all;
24import from REMSIM_Tests all;
25
26modulepar {
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 */
33type component bankd_test_CT extends rspro_server_CT, rspro_client_CT {
34}
35
36private 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
46private 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 */
55testcase 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 */
73testcase 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 */
81testcase TC_createMapping() runs on bankd_test_CT {
82 f_init();
83 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +010084 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +010085 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 */
92testcase TC_createMapping_busySlot() runs on bankd_test_CT {
93 f_init();
94 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +010095 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +010096 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
97 var ClientSlot cs := { clientId := 23, slotNr := 42 };
Harald Weltebca0ecd2019-12-04 21:53:29 +010098 /* create the mapping the first time */
Harald Weltefaa42922019-03-04 18:31:11 +010099 f_rspro_srv_create_slotmap(cs, bs);
Harald Weltebca0ecd2019-12-04 21:53:29 +0100100 /* re-create the mapping a second time */
101 f_rspro_srv_create_slotmap(cs, bs);
Harald Weltefaa42922019-03-04 18:31:11 +0100102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
103}
104
105/* attempt to create a mapping for an out-of-range slot number */
106testcase TC_createMapping_invalidSlot() runs on bankd_test_CT {
107 f_init();
108 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100109 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100110 var BankSlot bs := { bankId := mp_bank_id, slotNr := 200 };
111 var ClientSlot cs := { clientId := 23, slotNr := 42 };
112 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId);
113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
114}
115
116/* attempt to create a mapping for an invalid bankID */
117testcase TC_createMapping_invalidBank() runs on bankd_test_CT {
118 f_init();
119 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100120 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100121 var BankSlot bs := { bankId := 200, slotNr := 0 };
122 var ClientSlot cs := { clientId := 23, slotNr := 42 };
123 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalBankId);
124 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
125}
126
127/* attempt to remove a non-existant mapping */
128testcase TC_removeMapping_unknownMap() runs on bankd_test_CT {
129 f_init();
130 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100131 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100132 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
133 var ClientSlot cs := { clientId := 23, slotNr := 42 };
134 f_rspro_srv_remove_slotmap(cs, bs, exp_res := unknownSlotmap);
135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
136}
137
138/* add and then remove a mapping, expect both to be successful */
139testcase TC_removeMapping() runs on bankd_test_CT {
140 f_init();
141 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100142 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100143 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
144 var ClientSlot cs := { clientId := 23, slotNr := 42 };
145 f_rspro_srv_create_slotmap(cs, bs);
146 f_rspro_srv_remove_slotmap(cs, bs);
147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
148}
149
150/* connect from client to bankd without specifying a clientId */
151testcase TC_clientConnect_missingSlot() runs on bankd_test_CT {
152 f_init_client(0);
153 RSPRO[0].send(ts_RSPRO_ConnectClientReq(rspro[0].rspro_id, omit));
154 f_rspro_exp(tr_RSPRO_ConnectClientRes(?, ResultCode:illegalClientId), 0);
155 f_rspro_exp_disconnect(0);
156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
157}
158
159/* connect from client to bankd using a clientId for which bankd has no map */
160testcase TC_clientConnect_unknown() runs on bankd_test_CT {
161 f_init_client(0);
162 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
164}
165
166/* connect from client to bankd using a clientSlot for which bankd has no map */
167
168
169/* first connect client, then later add matching mapping from server */
170testcase TC_clientConnect_createMapping() runs on bankd_test_CT {
171 f_init_client(0);
172 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
173
174 f_init();
175 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
176
177 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
178 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
179 f_sleep(10.0);
180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
181}
182
183
184/* first add mapping, then connect matching client */
185testcase TC_createMapping_clientConnect() runs on bankd_test_CT {
186 /* FIXME: this would only be done in f_init_client(), but we need it before */
187 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
188
189 f_init();
190 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100191 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100192
193 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
194 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
195
196 f_sleep(1.0);
197
198 f_init_client(0);
199 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
200 /* FIXME: how to determine that bank correctly mapped us */
201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
202}
203
204
205
206/* add mapping, connect matching client, disconnect + reconnect */
207testcase TC_createMapping_clientReconnect() runs on bankd_test_CT {
208 /* FIXME: this would only be done in f_init_client(), but we need it before */
209 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
210
211 f_init();
212 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100213 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100214
215 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
216 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
217
218 f_sleep(1.0);
219
220 f_init_client(0);
221 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
222 /* TODO: works only with empty slot, as setAtrReq isn't handled */
223 /* FIXME: how to determine that bank correctly mapped us */
224 f_sleep(5.0);
225 f_rspro_fini(rspro[0], 0);
226
227 f_init_client(0);
228 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
229 /* FIXME: how to determine that bank correctly mapped us */
230 f_sleep(5.0);
231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
232}
233
234
235
236/* remove mapping while client is connected */
237testcase TC_removeMapping_connected() runs on bankd_test_CT {
238 f_init_client(0);
239 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
240 /* TODO: works only with empty slot, as setAtrReq isn't handled */
241
242 f_init();
243 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
244
245 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
246 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
247 /* FIXME: how to determine that bank correctly mapped us */
248 f_sleep(5.0);
249 f_rspro_srv_remove_slotmap(rspro[0].rspro_client_slot, bs);
250 f_rspro_exp_disconnect(0);
251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
252}
253
254/* first add mapping, then connect matching client and exchange some TPDUs */
255testcase TC_createMapping_exchangeTPDU() runs on bankd_test_CT {
256 /* FIXME: this would only be done in f_init_client(), but we need it before */
257 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
258
259 f_init();
260 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100261 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100262
263 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
264 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
265
266 f_sleep(1.0);
267
268 f_init_client(0);
269 f_rspro_connect_client(0, ok);
270 /* FIXME: how to determine that bank correctly mapped us */
271 f_rspro_exp(tr_RSPRO_SetAtrReq(rspro[0].rspro_client_slot, ?));
272
273 var TpduFlags f := {tpduHeaderPresent:=true, finalPart:=true, procByteContinueTx:=false,
274 procByteContinueRx:=false};
275 for (var integer i := 0; i < 10; i:=i+1) {
276 f_rspro_xceive_mdm2card(0, bs, 'A0A40000023F00'O, f);
277 }
278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
279}
280
281
282
283control {
284 execute( TC_connectBankReq_timeout() );
285 execute( TC_connectBankReq() );
286
287 execute( TC_createMapping() );
288 execute( TC_createMapping_busySlot() );
289 execute( TC_createMapping_invalidSlot() );
290 execute( TC_createMapping_invalidBank() );
291
292 execute( TC_removeMapping_unknownMap() );
293 execute( TC_removeMapping() );
294
295 execute( TC_clientConnect_missingSlot() );
296 execute( TC_clientConnect_unknown() );
297 execute( TC_clientConnect_createMapping() );
298 execute( TC_createMapping_clientConnect() );
299 execute( TC_createMapping_clientReconnect() );
300 execute( TC_removeMapping_connected() );
301
302 execute( TC_createMapping_exchangeTPDU() );
303}
304
305
306
307
308
309}