Index: client/site_tests/network_LockedSIM/network_LockedSIM.py |
diff --git a/client/site_tests/network_LockedSIM/network_LockedSIM.py b/client/site_tests/network_LockedSIM/network_LockedSIM.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7c61d108291a392d29cf4025d15de6d3d3282b6 |
--- /dev/null |
+++ b/client/site_tests/network_LockedSIM/network_LockedSIM.py |
@@ -0,0 +1,92 @@ |
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+from autotest_lib.client.bin import test |
+from autotest_lib.client.common_lib import error |
+ |
+import os, time |
+import dbus, dbus.mainloop.glib, gobject |
+import random |
+ |
+class TestFailure(Exception): |
+ pass |
+ |
+class network_LockedSIM(test.test): |
+ version = 1 |
+ |
+ def modem(self, path): |
+ return self.bus.get_object('org.freedesktop.ModemManager', path) |
+ |
+ def ChangePin(self, path, old, new): |
+ iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' |
+ self.modem(path).ChangePin(old, new, dbus_interface=iface) |
+ |
+ def EnablePin(self, path, pin): |
+ iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' |
+ self.modem(path).EnablePin(pin, True, dbus_interface=iface) |
+ |
+ def DisablePin(self, path, pin): |
+ 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.
|
+ self.modem(path).EnablePin(pin, False, dbus_interface=iface) |
+ |
+ def Powercycle(self, path): |
+ iface = 'org.freedesktop.ModemManager.Modem' |
+ self.modem(path).PowerCycle(dbus_interface=iface) |
+ |
+ def Unlock(self, path, pin): |
+ iface = 'org.freedesktop.ModemManager.Modem.Gsm.Card' |
+ self.modem(path).SendPin(pin, dbus_interface=iface) |
+ |
+ def retries(self, path): |
+ iface = 'org.freedesktop.DBus.Properties' |
+ return self.modem(path).Get(self.imodem, 'UnlockRetries', |
+ dbus_interface=iface) |
+ |
+ def run_once(self): |
+ self.imm = 'org.freedesktop.ModemManager' |
+ self.imodem = 'org.freedesktop.ModemManager.Modem' |
+ self.icard = 'org.freedesktop.ModemManager.Modem.Gsm.Card' |
+ passed = True |
+ self.bus = dbus.SystemBus() |
+ self.mm = self.bus.get_object('org.freedesktop.ModemManager', |
+ '/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.
|
+ |
+ self.devs = self.mm.EnumerateDevices(dbus_interface=self.imm) |
+ print 'devs: %d' % len(self.devs) |
+ for d in self.devs: |
+ print 'device: %s' % d |
+ # Make sure we can change the pin - this guarantees that the pin is |
+ # properly set to start with. |
+ self.ChangePin(d, '1111', '1112') |
+ self.ChangePin(d, '1112', '1111') |
+ self.EnablePin(d, '1111') |
+ self.Powercycle(d) |
+ |
+ # Give the modem a little while to come back... |
+ time.sleep(20) |
+ |
+ # Re-enumerate devices, since we're hoping they all disappeared and |
+ # reappeared. |
+ self.devs = self.mm.EnumerateDevices(dbus_interface=self.imm) |
+ print 'newdevs: %d' % len(self.devs) |
+ for d in self.devs: |
+ print 'newdevice: %s' % d |
+ retries = self.retries(d) |
+ try: |
+ self.Unlock(d, '1112') |
+ except dbus.exceptions.DBusException: |
+ pass |
+ # We expect a failure here, so swallow the DBus exception. |
+ nretries = self.retries(d) |
+ 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.
|
+ self.DisablePin(d, '1111') |
+ print '%s retries %d nretries %d' % (d, retries, nretries) |
+ if nretries != (retries - 1): |
+ # We can't just raise the exception here - if there are multiple |
+ # modems in the system, we might raise on the first one and |
+ # leave the others locked. |
+ passed = False |
+ |
+ if not passed: |
+ raise TestFailure() |
Jason Glasgow
2011/01/10 20:54:18
If this test works for multiple devices, can we ra
|