OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 from autotest_lib.client.bin import test | |
6 from autotest_lib.client.common_lib import error | |
7 | |
8 import os, time | |
9 import dbus, dbus.mainloop.glib, gobject | |
10 import random | |
11 | |
12 class TestFailure(Exception): | |
13 pass | |
14 | |
15 class network_LockedSIM(test.test): | |
16 version = 1 | |
17 | |
18 def modem(self, path): | |
19 return self.bus.get_object('org.freedesktop.ModemManager', path) | |
20 | |
21 def ChangePin(self, path, old, new): | |
22 iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' | |
23 self.modem(path).ChangePin(old, new, dbus_interface=iface) | |
24 | |
25 def EnablePin(self, path, pin): | |
26 iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' | |
27 self.modem(path).EnablePin(pin, True, dbus_interface=iface) | |
28 | |
29 def DisablePin(self, path, pin): | |
30 iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' | |
Jason Glasgow
2011/01/10 20:54:18
Why not self.icard? (For many of the methods in t
Elly Fong-Jones
2011/04/06 20:08:12
Done.
| |
31 self.modem(path).EnablePin(pin, False, dbus_interface=iface) | |
32 | |
33 def Powercycle(self, path): | |
34 iface = 'org.freedesktop.ModemManager.Modem' | |
35 self.modem(path).PowerCycle(dbus_interface=iface) | |
36 | |
37 def Unlock(self, path, pin): | |
38 iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' | |
39 self.modem(path).SendPin(pin, dbus_interface=iface) | |
40 | |
41 def retries(self, path): | |
42 iface = 'org.freedesktop.DBus.Properties' | |
43 return self.modem(path).Get(self.imodem, 'UnlockRetries', | |
44 dbus_interface=iface) | |
45 | |
46 def run_once(self): | |
47 self.imm = 'org.freedesktop.ModemManager' | |
48 self.imodem = 'org.freedesktop.ModemManager.Modem' | |
49 self.icard = 'org.freedesktop.ModemManager.Modem.Gsm.Card' | |
50 passed = True | |
51 self.bus = dbus.SystemBus() | |
52 self.mm = self.bus.get_object('org.freedesktop.ModemManager', | |
53 '/org/freedesktop/ModemManager') | |
Jason Glasgow
2011/01/10 20:54:18
Can we parameterize /org/freedesktop/ModemManager?
Elly Fong-Jones
2011/04/06 20:08:12
Done.
| |
54 | |
55 self.devs = self.mm.EnumerateDevices(dbus_interface=self.imm) | |
56 print 'devs: %d' % len(self.devs) | |
57 for d in self.devs: | |
58 print 'device: %s' % d | |
59 # Make sure we can change the pin - this guarantees that the pin is | |
60 # properly set to start with. | |
61 self.ChangePin(d, '1111', '1112') | |
62 self.ChangePin(d, '1112', '1111') | |
63 self.EnablePin(d, '1111') | |
64 self.Powercycle(d) | |
65 | |
66 # Give the modem a little while to come back... | |
67 time.sleep(20) | |
68 | |
69 # Re-enumerate devices, since we're hoping they all disappeared and | |
70 # reappeared. | |
71 self.devs = self.mm.EnumerateDevices(dbus_interface=self.imm) | |
72 print 'newdevs: %d' % len(self.devs) | |
73 for d in self.devs: | |
74 print 'newdevice: %s' % d | |
75 retries = self.retries(d) | |
76 try: | |
77 self.Unlock(d, '1112') | |
78 except dbus.exceptions.DBusException: | |
79 pass | |
80 # We expect a failure here, so swallow the DBus exception. | |
81 nretries = self.retries(d) | |
82 self.Unlock(d, '1111') | |
Jason Glasgow
2011/01/10 20:54:18
Can we make sure not to do this if retries < 2? W
Elly Fong-Jones
2011/04/06 20:08:12
Done.
| |
83 self.DisablePin(d, '1111') | |
84 print '%s retries %d nretries %d' % (d, retries, nretries) | |
85 if nretries != (retries - 1): | |
86 # We can't just raise the exception here - if there are multiple | |
87 # modems in the system, we might raise on the first one and | |
88 # leave the others locked. | |
89 passed = False | |
90 | |
91 if not passed: | |
92 raise TestFailure() | |
Jason Glasgow
2011/01/10 20:54:18
If this test works for multiple devices, can we ra
| |
OLD | NEW |