blob: bbdea6df92036f1de059fddae4ada007709b99dd [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);
84 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
85 var ClientSlot cs := { clientId := 23, slotNr := 42 };
86 f_rspro_srv_create_slotmap(cs, bs);
87 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
88}
89
90/* attempt to create a mapping for a slot that already has a mapping */
91testcase TC_createMapping_busySlot() runs on bankd_test_CT {
92 f_init();
93 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
94 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
95 var ClientSlot cs := { clientId := 23, slotNr := 42 };
96 f_rspro_srv_create_slotmap(cs, bs);
97 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId);
98 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
99}
100
101/* attempt to create a mapping for an out-of-range slot number */
102testcase TC_createMapping_invalidSlot() runs on bankd_test_CT {
103 f_init();
104 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
105 var BankSlot bs := { bankId := mp_bank_id, slotNr := 200 };
106 var ClientSlot cs := { clientId := 23, slotNr := 42 };
107 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId);
108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
109}
110
111/* attempt to create a mapping for an invalid bankID */
112testcase TC_createMapping_invalidBank() runs on bankd_test_CT {
113 f_init();
114 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
115 var BankSlot bs := { bankId := 200, slotNr := 0 };
116 var ClientSlot cs := { clientId := 23, slotNr := 42 };
117 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalBankId);
118 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
119}
120
121/* attempt to remove a non-existant mapping */
122testcase TC_removeMapping_unknownMap() runs on bankd_test_CT {
123 f_init();
124 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
125 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
126 var ClientSlot cs := { clientId := 23, slotNr := 42 };
127 f_rspro_srv_remove_slotmap(cs, bs, exp_res := unknownSlotmap);
128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
129}
130
131/* add and then remove a mapping, expect both to be successful */
132testcase TC_removeMapping() runs on bankd_test_CT {
133 f_init();
134 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
135 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
136 var ClientSlot cs := { clientId := 23, slotNr := 42 };
137 f_rspro_srv_create_slotmap(cs, bs);
138 f_rspro_srv_remove_slotmap(cs, bs);
139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
140}
141
142/* connect from client to bankd without specifying a clientId */
143testcase TC_clientConnect_missingSlot() runs on bankd_test_CT {
144 f_init_client(0);
145 RSPRO[0].send(ts_RSPRO_ConnectClientReq(rspro[0].rspro_id, omit));
146 f_rspro_exp(tr_RSPRO_ConnectClientRes(?, ResultCode:illegalClientId), 0);
147 f_rspro_exp_disconnect(0);
148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
149}
150
151/* connect from client to bankd using a clientId for which bankd has no map */
152testcase TC_clientConnect_unknown() runs on bankd_test_CT {
153 f_init_client(0);
154 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
156}
157
158/* connect from client to bankd using a clientSlot for which bankd has no map */
159
160
161/* first connect client, then later add matching mapping from server */
162testcase TC_clientConnect_createMapping() runs on bankd_test_CT {
163 f_init_client(0);
164 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
165
166 f_init();
167 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
168
169 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
170 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
171 f_sleep(10.0);
172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
173}
174
175
176/* first add mapping, then connect matching client */
177testcase TC_createMapping_clientConnect() runs on bankd_test_CT {
178 /* FIXME: this would only be done in f_init_client(), but we need it before */
179 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
180
181 f_init();
182 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
183
184 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
185 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
186
187 f_sleep(1.0);
188
189 f_init_client(0);
190 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
191 /* FIXME: how to determine that bank correctly mapped us */
192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
193}
194
195
196
197/* add mapping, connect matching client, disconnect + reconnect */
198testcase TC_createMapping_clientReconnect() runs on bankd_test_CT {
199 /* FIXME: this would only be done in f_init_client(), but we need it before */
200 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
201
202 f_init();
203 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
204
205 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
206 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
207
208 f_sleep(1.0);
209
210 f_init_client(0);
211 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
212 /* TODO: works only with empty slot, as setAtrReq isn't handled */
213 /* FIXME: how to determine that bank correctly mapped us */
214 f_sleep(5.0);
215 f_rspro_fini(rspro[0], 0);
216
217 f_init_client(0);
218 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
219 /* FIXME: how to determine that bank correctly mapped us */
220 f_sleep(5.0);
221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
222}
223
224
225
226/* remove mapping while client is connected */
227testcase TC_removeMapping_connected() runs on bankd_test_CT {
228 f_init_client(0);
229 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
230 /* TODO: works only with empty slot, as setAtrReq isn't handled */
231
232 f_init();
233 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
234
235 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
236 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
237 /* FIXME: how to determine that bank correctly mapped us */
238 f_sleep(5.0);
239 f_rspro_srv_remove_slotmap(rspro[0].rspro_client_slot, bs);
240 f_rspro_exp_disconnect(0);
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
242}
243
244/* first add mapping, then connect matching client and exchange some TPDUs */
245testcase TC_createMapping_exchangeTPDU() runs on bankd_test_CT {
246 /* FIXME: this would only be done in f_init_client(), but we need it before */
247 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
248
249 f_init();
250 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
251
252 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
253 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
254
255 f_sleep(1.0);
256
257 f_init_client(0);
258 f_rspro_connect_client(0, ok);
259 /* FIXME: how to determine that bank correctly mapped us */
260 f_rspro_exp(tr_RSPRO_SetAtrReq(rspro[0].rspro_client_slot, ?));
261
262 var TpduFlags f := {tpduHeaderPresent:=true, finalPart:=true, procByteContinueTx:=false,
263 procByteContinueRx:=false};
264 for (var integer i := 0; i < 10; i:=i+1) {
265 f_rspro_xceive_mdm2card(0, bs, 'A0A40000023F00'O, f);
266 }
267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
268}
269
270
271
272control {
273 execute( TC_connectBankReq_timeout() );
274 execute( TC_connectBankReq() );
275
276 execute( TC_createMapping() );
277 execute( TC_createMapping_busySlot() );
278 execute( TC_createMapping_invalidSlot() );
279 execute( TC_createMapping_invalidBank() );
280
281 execute( TC_removeMapping_unknownMap() );
282 execute( TC_removeMapping() );
283
284 execute( TC_clientConnect_missingSlot() );
285 execute( TC_clientConnect_unknown() );
286 execute( TC_clientConnect_createMapping() );
287 execute( TC_createMapping_clientConnect() );
288 execute( TC_createMapping_clientReconnect() );
289 execute( TC_removeMapping_connected() );
290
291 execute( TC_createMapping_exchangeTPDU() );
292}
293
294
295
296
297
298}