Home | History | Annotate | Download | only in system_tests
      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 """
     17 Basic Bluetooth Classic stress tests.
     18 """
     19 
     20 import time
     21 from acts.base_test import BaseTestClass
     22 from acts.test_decorators import test_tracker_info
     23 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
     24 from acts.test_utils.bt.bt_test_utils import clear_bonded_devices
     25 from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
     26 from acts.test_utils.bt.bt_test_utils import reset_bluetooth
     27 from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
     28 
     29 
     30 class BtStressTest(BluetoothBaseTest):
     31     default_timeout = 20
     32     iterations = 100
     33 
     34     def __init__(self, controllers):
     35         BluetoothBaseTest.__init__(self, controllers)
     36 
     37     def teardown_test(self):
     38         super(BluetoothBaseTest, self).teardown_test()
     39         self.log_stats()
     40         return True
     41 
     42     @test_tracker_info(uuid='bbe050f8-7970-42b3-9104-a2cd8f09579c')
     43     def test_toggle_bluetooth(self):
     44         """Stress test toggling bluetooth on and off.
     45 
     46         Test the integrity of toggling bluetooth on and off.
     47 
     48         Steps:
     49         1. Toggle bluetooth off.
     50         2. Toggle bluetooth on.
     51         3. Repeat steps 1 and 2 one-hundred times.
     52 
     53         Expected Result:
     54         Each iteration of toggling bluetooth on and off should not cause an
     55         exception.
     56 
     57         Returns:
     58           Pass if True
     59           Fail if False
     60 
     61         TAGS: Classic, Stress
     62         Priority: 1
     63         """
     64         for n in range(self.iterations):
     65             self.log.info("Toggling bluetooth iteration {}.".format(n + 1))
     66             if not reset_bluetooth([self.android_devices[0]]):
     67                 self.log.error("Failure to reset Bluetooth")
     68                 return False
     69         return True
     70 
     71     @test_tracker_info(uuid='a6fac426-d068-4a86-9d55-00dbe51b2ff0')
     72     def test_pair_bluetooth_stress(self):
     73         """Stress test for pairing BT devices.
     74 
     75         Test the integrity of Bluetooth pairing.
     76 
     77         1. Primary device discover the secondary device
     78         2. Primary device tries to pair to secondary device
     79         3. Pair two devices after verifying pin number on both devices are equal
     80         4. Verify both devices are paired
     81         5. Unpair devices.
     82         6. Verify devices unpaired.
     83         7. Repeat steps 1-6 100 times.
     84 
     85 
     86         Expected Result:
     87         Each iteration of toggling Bluetooth pairing and unpairing
     88         should succeed.
     89 
     90         Returns:
     91           Pass if True
     92           Fail if False
     93 
     94         TAGS: Classic, Stress
     95         Priority: 1
     96         """
     97         for n in range(self.iterations):
     98             self.log.info("Pair bluetooth iteration {}.".format(n + 1))
     99             self.start_timer()
    100             if (not pair_pri_to_sec(
    101                     self.android_devices[0],
    102                     self.android_devices[1],
    103                     attempts=1,
    104                     auto_confirm=False)):
    105                 self.log.error("Failed to bond devices.")
    106                 return False
    107             self.log.info("Total time (ms): {}".format(self.end_timer()))
    108             # A device bond will trigger a number of system routines that need
    109             # to settle before unbond
    110             time.sleep(2)
    111             for ad in self.android_devices:
    112                 if not clear_bonded_devices(ad):
    113                     return False
    114                 # Necessary sleep time for entries to update unbonded state
    115                 time.sleep(2)
    116                 bonded_devices = ad.droid.bluetoothGetBondedDevices()
    117                 if len(bonded_devices) > 0:
    118                     self.log.error("Failed to unbond devices: {}".format(
    119                         bonded_devices))
    120                     return False
    121         return True
    122