blob: 17e02c283ef008210c187bc276401dd515bc25a3 [file] [log] [blame]
# Copyright (c) 2012 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, utils
from autotest_lib.client.common_lib import error
import logging, re, socket, string, time, urllib2
import dbus, dbus.mainloop.glib, gobject
from autotest_lib.client.cros import flimflam_test_path
import flimflam, mm
class network_3GStressEnable(test.test):
version = 1
okerrors = [
'org.chromium.flimflam.Error.InProgress'
]
def EnableDevice(self, enable):
try:
if enable:
self.device.Enable()
else:
self.device.Disable()
except dbus.exceptions.DBusException, err:
if err._dbus_error_name in network_3GStressEnable.okerrors:
return
else:
raise error.TestFail(err)
def test(self, settle):
self.EnableDevice(True)
time.sleep(settle)
self.EnableDevice(False)
time.sleep(settle)
def FindDevice(self, names):
for name in names:
self.device = self.flim.FindElementByNameSubstring('Device',
name)
if self.device:
return True
self.device = self.flim.FindElementByPropertySubstring('Device',
'Interface',
name)
if self.device:
return True
return False
def run_once(self, names=['usb', 'wwan'], cycles=3, min=15, max=25):
self.flim = flimflam.FlimFlam(dbus.SystemBus())
if not self.FindDevice(names):
raise error.TestFail('No device found.')
service = self.flim.FindElementByNameSubstring('Service', 'cellular')
if service:
# If cellular's already up, take it down to start.
try:
service.SetProperty('AutoConnect', False)
except dbus.exceptions.DBusException, err:
# If the device has never connected to the cellular service
# before, flimflam will raise InvalidService when attempting
# to change the AutoConnect property.
if err._dbus_error_name != 'org.chromium.flimflam.'\
'Error.InvalidService':
raise err
self.EnableDevice(False)
for t in xrange(max, min, -1):
for n in xrange(cycles):
# deciseconds are an awesome unit.
print 'Cycle %d: %f seconds delay.' % (n, t / 10.0)
self.test(t / 10.0)
print 'Done.'