[go: up one dir, main page]

File: testping.vala

package info (click to toggle)
libgisi 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 2,428 kB
  • ctags: 3,624
  • sloc: ansic: 16,866; sh: 11,295; makefile: 247
file content (412 lines) | stat: -rw-r--r-- 12,628 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

using GLib;

const string MODEM_IFACE = "usbpn0";
//const string MODEM_IFACE = "phonet0";

static ModemTester mt = null;
static MainLoop loop = null;

//===========================================================================
public static void sighandler( int signum )
{
    Posix.signal( signum, null ); // restore original sighandler
    loop.quit();
}

//===========================================================================
public static void schedule( int seconds = 3 )
{
    var starttime = time_t();

    while ( time_t() < starttime + seconds )
    {
         MainContext.default().iteration( false );
    }
}

//===========================================================================
class ModemTester
{
    public GIsi.Modem modem;
    public GIsi.PhonetLinkState linkstate;
    public GIsiClient.MTC mtc;
    public GIsiClient.PhoneInfo phoneinfo;
    public GIsiClient.SIMAuth simauth;
    public GIsiClient.SIM sim;
    public GIsiClient.Network network;
    public GIsiClient.Call call;

    public GIsiComm.MTC gcmtc;
    public GIsiComm.PhoneInfo gcphoneinfo;
    public GIsiComm.SIMAuth gcsimauth;
    public GIsiComm.SIM gcsim;
    public GIsiComm.Network gcnetwork;
    public GIsiComm.Call gccall;

    public ModemTester( string iface )
    {
        modem = new GIsi.Modem( iface );
        linkstate = (GIsi.PhonetLinkState) 999;
    }

    //
    // callbacks
    //
    public void onNetlinkStateChanged( GIsi.Modem modem, GIsi.PhonetLinkState st, string iface )
    {
        linkstate = st;
        debug( "netlink status for modem %p (%s) now %s", modem, iface, st.to_string() );
    }

    public void onClientReachabilityVerification( GIsi.Message msg )
    {
        debug( @"client reachability verification got a response: $msg" );
    }
}

//===========================================================================
void test_modem_create()
//===========================================================================
{
    var modem = new GIsi.Modem();
    modem = new GIsi.Modem( MODEM_IFACE );
    modem = new GIsi.Modem.index_new( 0 );
}

//===========================================================================
void test_netlink_bringup()
//===========================================================================
{
    mt.modem = new GIsi.Modem( MODEM_IFACE );
    assert( mt.modem != null );

    unowned GIsi.PhonetNetlink netlink = mt.modem.netlink_start( mt.onNetlinkStateChanged );
    assert( netlink != null );

    mt.modem.netlink_set_address( GIsi.PhonetDevice.SOS );

    while ( mt.linkstate != GIsi.PhonetLinkState.UP && mt.linkstate != GIsi.PhonetLinkState.DOWN )
    {
        MainContext.default().iteration( false );
    }

    assert( mt.linkstate == GIsi.PhonetLinkState.UP );
}

//===========================================================================
void test_comm_mtc_query()
//===========================================================================
{
    var ok = false;

    mt.gcmtc = new GIsiComm.MTC( mt.modem );

    mt.gcmtc.setPower( true, (error, cause) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( cause == GIsiClient.MTC.IsiCause.OK );
        debug( "power on OK" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;

    mt.gcmtc.readState( ( error, current, target ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        debug( @"current state = $current, target state = $target" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;
}

//===========================================================================
void test_client_phoneinfo_bringup()
//===========================================================================
{
    mt.phoneinfo = mt.modem.phone_info_client_create();
    assert( mt.phoneinfo != null );

    mt.phoneinfo.verify( mt.onClientReachabilityVerification );
}

//===========================================================================
void test_comm_phoneinfo_query()
//===========================================================================
{
    var ok = false;

    mt.gcphoneinfo = new GIsiComm.PhoneInfo( mt.modem );
    mt.gcphoneinfo.readManufacturer( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result == "Nokia" );
        debug( @"Vendor = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );

    ok = false;

    mt.gcphoneinfo.readModel( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result == "Nokia N900" );
        debug( @"Model = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );

    ok = false;

    mt.gcphoneinfo.readSerial( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result.has_prefix( "35" ) && result.length == 15 );
        debug( @"IMEI = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );

    ok = false;

    mt.gcphoneinfo.readVersion( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result.length == 2 );
        debug( @"Version = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );

    ok = false;
}

//===========================================================================
void test_client_simauth_bringup()
//===========================================================================
{
    mt.simauth = mt.modem.sim_auth_client_create();
    assert( mt.simauth != null );

    mt.simauth.verify( mt.onClientReachabilityVerification );
}

//===========================================================================
void test_comm_simauth_query()
//===========================================================================
{
    var ok = false;

    mt.gcsimauth = new GIsiComm.SIMAuth( mt.modem );

    schedule();

    mt.gcsimauth.queryStatus( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        debug( "SIM Status = 0x%0X", result );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
}

//===========================================================================
void test_client_sim_bringup()
//===========================================================================
{
    mt.sim = mt.modem.sim_client_create();
    assert( mt.sim != null );

    mt.sim.verify( mt.onClientReachabilityVerification );
}

//===========================================================================
void test_comm_sim_query()
//===========================================================================
{
    var ok = false;

    mt.gcsim = new GIsiComm.SIM( mt.modem );
    mt.gcsim.readSPN( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        //assert( result == "Nokia" );
        debug( @"SPN = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;

    mt.gcsim.readHPLMN( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result.has_prefix( "262" ) );
        debug( @"HPLMN = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;

    mt.gcsim.readIMSI( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        assert( result.has_prefix( "262" ) );
        debug( @"IMSI = $result" );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;
}

//===========================================================================
void test_client_network_bringup()
//===========================================================================
{
    mt.network = mt.modem.network_client_create();
    assert( mt.network != null );

    mt.network.verify( mt.onClientReachabilityVerification );
}

//===========================================================================
void test_comm_network_query()
//===========================================================================
{
    var ok = false;

    mt.gcnetwork = new GIsiComm.Network( mt.modem );

    mt.gcnetwork.queryStatus( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        debug( "Provider = %s (%s%s) in %s.%s", result.name, result.mcc, result.mnc, result.lac, result.cid );
        ok = true;
    } );
    while ( !ok ) MainContext.default().iteration( false );
    ok = false;

    mt.gcnetwork.queryStrength( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        debug( "RSSI = %d", result );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
    ok = false;

//#if 0
    mt.gcnetwork.listProviders( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        //debug( "RSSI = %d", result );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
//#endif
}

//===========================================================================
void test_comm_network_register()
//===========================================================================
{
    var ok = false;

    mt.gcnetwork.registerAutomatic( false, ( error ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        ok = true;
    } );

    while ( !ok ) MainContext.default().iteration( false );
}

//===========================================================================
void test_client_call_bringup()
//===========================================================================
{
    mt.call = mt.modem.call_client_create();
    assert( mt.call != null );

    mt.call.verify( mt.onClientReachabilityVerification );
}

//===========================================================================
void test_comm_call_query()
//===========================================================================
{
    var ok = false;

    mt.gccall = new GIsiComm.Call( mt.modem );

    /*

    mt.gccall.queryStatus( ( error, result ) => {
        assert( error == GIsiComm.ErrorCode.OK );
        //ok = true;
    } );
    *
    */
    while ( !ok ) MainContext.default().iteration( false );
    ok = false;
}

//===========================================================================
void main( string[] args )
//===========================================================================
{
    Test.init( ref args );

    Test.add_func( "/GISI/Modem/Create", test_modem_create );
    Test.add_func( "/GISI/Netlink/Bringup", test_netlink_bringup );

//    Test.add_func( "/GISI/COMM/MTC/Query", test_comm_mtc_query );

    Test.add_func( "/GISI/Client/PhoneInfo/Bringup", test_client_phoneinfo_bringup );
    Test.add_func( "/GISI/COMM/PhoneInfo/Query", test_comm_phoneinfo_query );

//    Test.add_func( "/GISI/Client/SIMAuth/Bringup", test_client_simauth_bringup );
//    Test.add_func( "/GISI/COMM/SIMAuth/Query", test_comm_simauth_query);

//    Test.add_func( "/GISI/Client/SIM/Bringup", test_client_sim_bringup );
//    Test.add_func( "/GISI/COMM/SIM/Query", test_comm_sim_query );

    Test.add_func( "/GISI/Client/Network/Bringup", test_client_network_bringup );
    Test.add_func( "/GISI/COMM/Network/Query", test_comm_network_query );
    Test.add_func( "/GISI/COMM/Network/Register", test_comm_network_register );

//    Test.add_func( "/GISI/Client/Call/Bringup", test_client_call_bringup );
//    Test.add_func( "/GISI/COMM/Call/Query", test_comm_call_query );

    mt = new ModemTester( MODEM_IFACE );

    loop = new MainLoop();
    Idle.add( () => {
        Test.run();
        return false;
    } );

    Posix.signal( Posix.SIGINT, sighandler );
    Posix.signal( Posix.SIGTERM, sighandler );

    debug( "=> mainloop" );
    loop.run();
    debug( "<= mainloop" );
}

// vim:ts=4:sw=4:expandtab