xref: /aosp_15_r20/external/autotest/client/site_tests/cellular_StressEnable/cellular_StressEnable.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from __future__ import absolute_import
7from __future__ import division
8from __future__ import print_function
9
10import dbus
11import logging
12import time
13
14from six.moves import range
15
16from autotest_lib.client.bin import test
17from autotest_lib.client.common_lib import error
18from autotest_lib.client.cros.networking import shill_context
19from autotest_lib.client.cros.networking import shill_proxy
20
21
22class cellular_StressEnable(test.test):
23    """
24    Stress-tests enabling and disabling a technology at short intervals.
25
26    """
27    version = 1
28
29    okerrors = [
30        shill_proxy.ShillProxy.ERROR_IN_PROGRESS
31    ]
32
33    def _enable_device(self, enable):
34        try:
35            timeout = shill_proxy.ShillProxy.DEVICE_ENABLE_DISABLE_TIMEOUT
36            if enable:
37                self.device.Enable(timeout=timeout)
38            else:
39                self.device.Disable(timeout=timeout)
40        except dbus.exceptions.DBusException as err:
41            if err.get_dbus_name() in cellular_StressEnable.okerrors:
42                return
43            raise error.TestFail(err)
44
45
46    def _test(self, settle):
47        self._enable_device(False)
48        time.sleep(settle)
49        self._enable_device(True)
50        time.sleep(settle)
51
52
53    def run_once(self, test_env, cycles=3, min=15, max=25):
54        with test_env, shill_context.ServiceAutoConnectContext(
55                test_env.shill.wait_for_cellular_service_object, False):
56            self.device = test_env.shill.find_cellular_device_object()
57            for t in range(max, min, -1):
58                for n in range(cycles):
59                    # deciseconds are an awesome unit.
60                    logging.info('Cycle %d: %f seconds delay.', n, t / 10.0)
61                    self._test(t / 10.0)
62            logging.info('Done.')
63