~ubuntu-branches/ubuntu/wily/ofono/wily-proposed

« back to all changes in this revision

Viewing changes to test/rilmodem/sim/test-sim-pin-unlock

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Tony Espy, Vicamo Yang, Alfonso Sanchez-Beato
  • Date: 2015-02-04 09:18:00 UTC
  • mfrom: (1.3.30)
  • Revision ID: package-import@ubuntu.com-20150204091800-ptp0cyfidrf69ar1
Tags: 1.12.bzr6886+15.04.20150204-0ubuntu1
[ Tony Espy ]
* test/rilmodem/sim: add new SIM test scripts
* test: fix test-call-forwarding script (LP: #1396323)

[ Vicamo Yang ]
* mtkmodem, rilmodem: re-factor naming
  This change makes the naming of GRil, mtk_data,
  ofono_modem, and ril_data instances consistent.
* rilmodem: fix duplicate APPSTATE* constants
* gril: get rid of duplicate ringbuffer.h (LP: #1408250)
* mtk.c: use RIL_RADIO_POWER request for single slot modems

[ Alfonso Sanchez-Beato ]
* gril, unit, mtk.c: SIM mode and session ID fixes for arale
  For MTK modems, DUAL_SIM_MODE requests aren't necessary.  Also
  add session-id to SIM IO requests for newer MTK modems.
* rilmodem, mtk.c, ril.c: add auto-answer support
  This change adds auto-answer support which is triggered
  by usage of a special test SIM (MCC/MNC 001/01 or 001/001).
* mtkmodem, unit, mtk.c: support arale firmware switch
  This change will cause the correct modem firmware to
  be loaded based upon the SIM MCC and MNC.  If new
  firmware is loaded, a modem reset is triggered.
* mtkmodem, unit, mtk.c: handle suspend events
  RIL_RESUME_REGISTRATION requests are not sent to
  MTK modems if suspend events are received.
* gril, include, mbpi, rilmodem, mtkmodem, rilmodem,
  gprs, unit, modem, ril.c, mtk.c: LTE updates
  This changes detection logic for LTE modems to rilmodem
  ( via an environment var ) and mtkmodem ( via a modem
  query ).  If detected, a RIL_INITIAL_ATTACH_APN request
  is not sent to the modem during gprs initialization.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
#
 
3
#  oFono - Open Source Telephony - RIL Modem test
 
4
#
 
5
#  Copyright (C) 2014 Canonical Ltd.
 
6
#
 
7
#  This program is free software; you can redistribute it and/or modify
 
8
#  it under the terms of the GNU General Public License version 2 as
 
9
#  published by the Free Software Foundation.
 
10
#
 
11
#  This program is distributed in the hope that it will be useful,
 
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#  GNU General Public License for more details.
 
15
#
 
16
#  You should have received a copy of the GNU General Public License
 
17
#  along with this program; if not, write to the Free Software
 
18
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
#
 
20
# This test ensures that basic modem information is available
 
21
# when the modem is online and has a valid, unlocked SIM present.
 
22
 
 
23
"""Tests the abilty to unlock a locked SIM for use.
 
24
 
 
25
This module contains a functional test which checks an
 
26
ofono/rilmodem/mtkmodem instance to ensure that the a
 
27
SIM PIN can be entered and thus unlock the SIM for use.
 
28
 
 
29
NOTE - this test by default tries to unlock the PIN of a
 
30
single SIM.  If the device is multi-SIM, the first modem
 
31
will be used by default.  The -m argument can be used to
 
32
specify the second modem if needed.
 
33
 
 
34
Requirements:
 
35
 
 
36
 * a SIM with PIN-locking enabled
 
37
 
 
38
 * the current PIN code for the SIM
 
39
 
 
40
Setup:
 
41
 
 
42
 * Ensure that FlightMode is NOT enabled
 
43
 
 
44
 * Ensure that at least one SIM with PIN-locking
 
45
   enabled is inserted in the phone AND STILL LOCKED!
 
46
   ( ie. the PIN hasn't been entered yet )
 
47
 
 
48
 * Run this script
 
49
 
 
50
ToDo:
 
51
 * If run on the emulator, make this script use console
 
52
   commands to configure the modem(s) for the required
 
53
   conditions ( ie. no SIM(s), online )
 
54
"""
 
55
 
 
56
import dbus.mainloop.glib
 
57
import simtestutil
 
58
 
 
59
from gi.repository import GLib
 
60
from simtestutil import *
 
61
 
 
62
def parse_test_args():
 
63
 
 
64
        parser = argparse.ArgumentParser()
 
65
 
 
66
        parser.add_argument("--pin",
 
67
                                dest="pin",
 
68
                                help="""Specify the SIM PIN code""",
 
69
                                required="yes",
 
70
                                )
 
71
 
 
72
        parser.add_argument("-t",
 
73
                        "--timeout",
 
74
                        dest="timeout",
 
75
                        help="""Specify a timeout which causes
 
76
                        the script to exit""",
 
77
                        default=10,
 
78
                        )
 
79
 
 
80
        return parse_args(parser)
 
81
 
 
82
class TestSimPukUnlock(SimTestCase):
 
83
 
 
84
        def setUp(self):
 
85
                self.args = args
 
86
                self.product = get_product()
 
87
                self.timer = False
 
88
 
 
89
                self.mainloop = GLib.MainLoop()
 
90
 
 
91
                dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
92
 
 
93
                SimTestCase.setUp(self)
 
94
 
 
95
                interval_ms = 1000 * int(self.args.timeout)
 
96
                GLib.timeout_add(interval_ms, self.timeout_cb)
 
97
 
 
98
        def pin_unlock(self, path):
 
99
 
 
100
                if self.args.debug:
 
101
                        print("pin_unlock called,"
 
102
                                "pin: {}".format(self.args.pin))
 
103
 
 
104
                simmanager = self.get_simmanager(path)
 
105
                simmanager.connect_to_signal("PropertyChanged",
 
106
                                                 self.sim_listener)
 
107
 
 
108
                properties = simmanager.GetProperties()
 
109
 
 
110
                locked_pins = properties["LockedPins"]
 
111
                self.assertTrue(len(locked_pins) == 1)
 
112
                self.assertTrue(locked_pins[0] == "pin")
 
113
 
 
114
                self.assertTrue(properties["PinRequired"] == "pin")
 
115
 
 
116
                simmanager.EnterPin("pin", self.args.pin)
 
117
 
 
118
        def sim_listener(self, name, value):
 
119
                if self.args.debug:
 
120
                        print("SIM property: {} changed "
 
121
                                "to {}".format(name, str(value)))
 
122
 
 
123
                if name == "PinRequired":
 
124
                        self.assertTrue(value == "none")
 
125
                        self.mainloop.quit()
 
126
 
 
127
        def timeout_cb(self):
 
128
                if self.args.debug:
 
129
                        print("ALL DONE - timer fired!!!")
 
130
 
 
131
                self.timer = True
 
132
                self.mainloop.quit()
 
133
 
 
134
        def validate_modem(self, path):
 
135
 
 
136
                self.pin_unlock(path)
 
137
 
 
138
                self.mainloop.run()
 
139
 
 
140
                self.assertTrue(self.timer == False)
 
141
 
 
142
        def test_main(self):
 
143
                self.main(args)
 
144
 
 
145
if __name__ == "__main__":
 
146
        args = parse_test_args()
 
147
 
 
148
        sim_unittest_main(args)
 
149