Home | History | Annotate | Download | only in stress_tests
      1 # /usr/bin/env python3.4
      2 #
      3 # Copyright (C) 2018 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 import time
     18 
     19 from acts.test_utils.bt import BtEnum
     20 from acts.test_utils.bt.bt_test_utils import clear_bonded_devices
     21 from acts.test_utils.coex.CoexBaseTest import CoexBaseTest
     22 from acts.test_utils.coex.coex_test_utils import disconnect_headset_from_dev
     23 from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset
     24 
     25 
     26 class CoexBtMultiProfileStressTest(CoexBaseTest):
     27 
     28     def __init__(self, controllers):
     29         CoexBaseTest.__init__(self, controllers)
     30 
     31     def setup_class(self):
     32         CoexBaseTest.setup_class(self)
     33         self.receiver = self.relay_devices[1]
     34         req_params = ["iterations"]
     35         self.unpack_userparams(req_params)
     36 
     37     def setup_test(self):
     38         CoexBaseTest.setup_test(self)
     39         self.audio_receiver.pairing_mode()
     40         self.receiver.setup()
     41         self.receiver.power_on()
     42         self.receiver.pairing_mode()
     43 
     44     def teardown_test(self):
     45         clear_bonded_devices(self.pri_ad)
     46         CoexBaseTest.teardown_test(self)
     47         self.audio_receiver.clean_up()
     48         self.receiver.clean_up()
     49 
     50     def initiate_classic_connection_to_multiple_devices(self):
     51         """Initiates multiple BR/EDR connections.
     52 
     53         Steps:
     54         1. Initiate A2DP Connection.
     55         2. Initiate HFP Connection.
     56         3. Disconnect A2DP Connection.
     57         4. Disconnect HFP Connection.
     58         5. Repeat step 1 to 4.
     59 
     60         Returns:
     61             True if successful, False otherwise.
     62         """
     63         for i in range(self.iterations):
     64             if not pair_and_connect_headset(
     65                     self.pri_ad, self.receiver.mac_address,
     66                     {BtEnum.BluetoothProfile.A2DP.value}):
     67                 self.log.error("Failed to connect A2DP Profile.")
     68                 return False
     69             time.sleep(2)
     70 
     71             if not pair_and_connect_headset(
     72                     self.pri_ad, self.audio_receiver.mac_address,
     73                     {BtEnum.BluetoothProfile.HEADSET.value}):
     74                 self.log.error("Failed to connect HEADSET profile.")
     75                 return False
     76             time.sleep(2)
     77 
     78             if not disconnect_headset_from_dev(
     79                     self.pri_ad, self.receiver.mac_address,
     80                     [BtEnum.BluetoothProfile.A2DP.value]):
     81                 self.log.error("Could not disconnect {}".format(
     82                     self.receiver.mac_address))
     83                 return False
     84 
     85             if not disconnect_headset_from_dev(
     86                     self.pri_ad, self.audio_receiver.mac_address,
     87                     [BtEnum.BluetoothProfile.HEADSET.value]):
     88                 self.log.error("Could not disconnect {}".format(
     89                     self.audio_receiver.mac_address))
     90                 return False
     91         return True
     92 
     93     def initiate_classic_connection_with_iperf(self):
     94         """Wrapper function to initiate bluetooth classic connection to
     95         multiple devices.
     96         """
     97         self.run_iperf_and_get_result()
     98         if not self.initiate_classic_connection_to_multiple_devices():
     99             return False
    100         return self.teardown_result()
    101 
    102     def test_stress_multiple_connection_with_tcp_ul(self):
    103         """ Connects multiple headsets with wlan traffic over TCP-uplink.
    104 
    105         This test is to perform connect and disconnect with A2DP and HFP
    106         profiles on two different bluetooth devices.
    107 
    108         Steps:
    109         1. Run wlan traffic over TCP-uplink.
    110         2. Initiate connect and disconnect to multiple profiles from primary
    111         device.
    112 
    113         Returns:
    114             True if successful, False otherwise.
    115 
    116         Test Id: Bt_CoEx_Stress_037
    117         """
    118         if not self.initiate_classic_connection_with_iperf():
    119             return False
    120         return True
    121 
    122     def test_stress_multiple_connection_with_tcp_dl(self):
    123         """ Connects multiple headsets with wlan traffic over TCP-downlink.
    124 
    125         This test is to perform connect and disconnect with A2DP and HFP
    126         profiles on two different bluetooth devices.
    127 
    128         Steps:
    129         1. Run wlan traffic over TCP-downlink.
    130         2. Initiate connect and disconnect to multiple profiles from primary
    131         device.
    132 
    133         Returns:
    134             True if successful, False otherwise.
    135 
    136         Test Id: Bt_CoEx_Stress_038
    137         """
    138         if not self.initiate_classic_connection_with_iperf():
    139             return False
    140         return True
    141 
    142     def test_stress_multiple_connection_with_udp_ul(self):
    143         """ Connects multiple headsets with wlan traffic over UDP-uplink.
    144 
    145         This test is to perform connect and disconnect with A2DP and HFP
    146         profiles on two different bluetooth devices.
    147 
    148         Steps:
    149         1. Run wlan traffic over UDP-uplink.
    150         2. Initiate connect and disconnect to multiple profiles from primary
    151         device.
    152 
    153         Returns:
    154             True if successful, False otherwise.
    155 
    156         Test Id: Bt_CoEx_Stress_039
    157         """
    158         if not self.initiate_classic_connection_with_iperf():
    159             return False
    160         return True
    161 
    162     def test_stress_multiple_connection_with_udp_dl(self):
    163         """ Connects multiple headsets with wlan traffic over UDP-downlink.
    164 
    165         This test is to perform connect and disconnect with A2DP and HFP
    166         profiles.
    167 
    168         Steps:
    169         1. Run wlan traffic over UDP-downlink.
    170         2. Initiate connect and disconnect to multiple profiles from primary
    171         device.
    172 
    173         Returns:
    174             True if successful, False otherwise.
    175 
    176         Test Id: Bt_CoEx_Stress_040
    177         """
    178         if not self.initiate_classic_connection_with_iperf():
    179             return False
    180         return True
    181