• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#/usr/bin/env python3.4
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Basic Bluetooth Classic stress tests.
18"""
19
20import time
21from acts.base_test import BaseTestClass
22from acts.test_utils.bt.bt_test_utils import log_energy_info
23from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
24from acts.test_utils.bt.bt_test_utils import reset_bluetooth
25from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
26
27
28class BtStressTest(BaseTestClass):
29    default_timeout = 10
30
31    def __init__(self, controllers):
32        BaseTestClass.__init__(self, controllers)
33
34    def setup_class(self):
35        return setup_multiple_devices_for_bt_test(self.android_devices)
36
37    def setup_test(self):
38        return reset_bluetooth(self.android_devices)
39
40    def setup_test(self):
41        setup_result = reset_bluetooth(self.android_devices)
42        self.log.debug(log_energy_info(self.android_devices, "Start"))
43        for a in self.android_devices:
44            a.ed.clear_all_events()
45        return setup_result
46
47    def teardown_test(self):
48        self.log.debug(log_energy_info(self.android_devices, "End"))
49        return True
50
51    def test_toggle_bluetooth(self):
52        """Stress test toggling bluetooth on and off.
53
54        Test the integrity of toggling bluetooth on and off.
55
56        Steps:
57        1. Toggle bluetooth off.
58        2. Toggle bluetooth on.
59        3. Repeat steps 1 and 2 one-hundred times.
60
61        Expected Result:
62        Each iteration of toggling bluetooth on and off should not cause an
63        exception.
64
65        Returns:
66          Pass if True
67          Fail if False
68
69        TAGS: Classic, Stress
70        Priority: 1
71        """
72        test_result = True
73        test_result_list = []
74        for n in range(100):
75            self.log.info("Toggling bluetooth iteration {}.".format(n + 1))
76            test_result = reset_bluetooth([self.android_devices[0]])
77            test_result_list.append(test_result)
78            if not test_result:
79                self.log.debug("Failure to reset Bluetooth... continuing")
80        self.log.info("Toggling Bluetooth failed {}/100 times".format(len(
81            test_result_list)))
82        if False in test_result_list:
83            return False
84        return test_result
85
86    def test_pair_bluetooth_stress(self):
87        """Stress test for pairing BT devices.
88
89        Test the integrity of Bluetooth pairing.
90
91        Steps:
92        1. Pair two Android devices
93        2. Verify both devices are paired
94        3. Unpair devices.
95        4. Verify devices unpaired.
96        5. Repeat steps 1-4 100 times.
97
98        Expected Result:
99        Each iteration of toggling Bluetooth pairing and unpairing
100        should succeed.
101
102        Returns:
103          Pass if True
104          Fail if False
105
106        TAGS: Classic, Stress
107        Priority: 1
108        """
109        for n in range(100):
110            self.log.info("Pair bluetooth iteration {}.".format(n + 1))
111            if (pair_pri_to_sec(self.android_devices[0].droid,
112                                self.android_devices[1].droid) == False):
113                self.log.error("Failed to bond devices.")
114                return False
115            for ad in self.android_devices:
116                bonded_devices = ad.droid.bluetoothGetBondedDevices()
117                for b in bonded_devices:
118                    ad.droid.bluetoothUnbond(b['address'])
119                #Necessary sleep time for entries to update unbonded state
120                time.sleep(1)
121                bonded_devices = ad.droid.bluetoothGetBondedDevices()
122                if len(bonded_devices) > 0:
123                    self.log.error("Failed to unbond devices: {}".format(
124                        bonded_devices))
125                    return False
126        return True
127