• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 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
5import dbus
6import logging
7import time
8
9from autotest_lib.client.bin import test
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.cros.networking import shill_context
12from autotest_lib.client.cros.networking import shill_proxy
13
14
15class cellular_StressEnable(test.test):
16    """
17    Stress-tests enabling and disabling a technology at short intervals.
18
19    """
20    version = 1
21
22    okerrors = [
23        shill_proxy.ShillProxy.ERROR_IN_PROGRESS
24    ]
25
26    def _enable_device(self, enable):
27        try:
28            timeout = shill_proxy.ShillProxy.DEVICE_ENABLE_DISABLE_TIMEOUT
29            if enable:
30                self.device.Enable(timeout=timeout)
31            else:
32                self.device.Disable(timeout=timeout)
33        except dbus.exceptions.DBusException, err:
34            if err.get_dbus_name() in cellular_StressEnable.okerrors:
35                return
36            raise error.TestFail(err)
37
38
39    def _test(self, settle):
40        self._enable_device(False)
41        time.sleep(settle)
42        self._enable_device(True)
43        time.sleep(settle)
44
45
46    def run_once(self, test_env, cycles=3, min=15, max=25):
47        with test_env, shill_context.ServiceAutoConnectContext(
48                test_env.shill.wait_for_cellular_service_object, False):
49            self.device = test_env.shill.find_cellular_device_object()
50            for t in xrange(max, min, -1):
51                for n in xrange(cycles):
52                    # deciseconds are an awesome unit.
53                    logging.info('Cycle %d: %f seconds delay.', n, t / 10.0)
54                    self._test(t / 10.0)
55            logging.info('Done.')
56