Home | History | Annotate | Download | only in conn_oriented_chan
      1 #/usr/bin/env python3.4
      2 #
      3 # Copyright 2017 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of 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,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 """
     17 Test script to execute Bluetooth Connection-orient Channel (CoC) functionality for
     18 2 connections test cases. This test was designed to be run in a shield box.
     19 """
     20 
     21 import threading
     22 import time
     23 
     24 from queue import Empty
     25 from acts.test_decorators import test_tracker_info
     26 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
     27 from acts.test_utils.bt.bt_coc_test_utils import orchestrate_coc_connection
     28 from acts.test_utils.bt.bt_coc_test_utils import do_multi_connection_throughput
     29 from acts.test_utils.bt.bt_constants import default_le_data_length
     30 from acts.test_utils.bt.bt_constants import default_bluetooth_socket_timeout_ms
     31 from acts.test_utils.bt.bt_constants import l2cap_coc_header_size
     32 from acts.test_utils.bt.bt_constants import l2cap_max_inactivity_delay_after_disconnect
     33 from acts.test_utils.bt.bt_constants import le_connection_event_time_step_ms
     34 from acts.test_utils.bt.bt_test_utils import clear_bonded_devices
     35 from acts.test_utils.bt.bt_test_utils import kill_bluetooth_process
     36 from acts.test_utils.bt.bt_test_utils import reset_bluetooth
     37 from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
     38 from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
     39 from acts.test_utils.bt.bt_test_utils import write_read_verify_data
     40 from acts.test_utils.bt.bt_test_utils import verify_server_and_client_connected
     41 
     42 
     43 class BleCoc2ConnTest(BluetoothBaseTest):
     44     def __init__(self, controllers):
     45         BluetoothBaseTest.__init__(self, controllers)
     46         self.client_ad = self.android_devices[0]
     47         self.server_ad = self.android_devices[1]
     48         # Note that some tests required a third device.
     49         if len(self.android_devices) > 2:
     50             self.server2_ad = self.android_devices[2]
     51 
     52     def setup_class(self):
     53         return setup_multiple_devices_for_bt_test(self.android_devices)
     54 
     55     def teardown_test(self):
     56         self.client_ad.droid.bluetoothSocketConnStop()
     57         self.server_ad.droid.bluetoothSocketConnStop()
     58         # Give sufficient time for the physical LE link to be disconnected.
     59         time.sleep(l2cap_max_inactivity_delay_after_disconnect)
     60 
     61     # This utility function calculates the max and min connection event (ce) time.
     62     # The formula is that the min/max ce time should be less than half the connection
     63     # interval and must be multiples of the le_connection_event_time_step.
     64     def _calc_min_max_ce_time(self, le_connection_interval):
     65         conn_event_time_steps = int((le_connection_interval/2)/le_connection_event_time_step_ms)
     66         conn_event_time_steps -= 1
     67         return (le_connection_event_time_step_ms * conn_event_time_steps)
     68 
     69     def _run_coc_connection_throughput_2_conn(
     70             self,
     71             is_secured,
     72             buffer_size,
     73             le_connection_interval=0,
     74             le_tx_data_length=default_le_data_length,
     75             min_ce_len=0,
     76             max_ce_len=0):
     77 
     78         # The num_iterations is that number of repetitions of each
     79         # set of buffers r/w.
     80         # number_buffers is the total number of data buffers to transmit per
     81         # set of buffers r/w.
     82         # buffer_size is the number of bytes per L2CAP data buffer.
     83         num_iterations = 10
     84         number_buffers = 100
     85 
     86         # Make sure at least 3 phones are setup
     87         if len(self.android_devices) <= 2:
     88             self.log.info("test_coc_connection_throughput_2_conn: "
     89                           "Error: 3rd phone not configured in file")
     90             return False
     91 
     92         self.log.info(
     93             "_run_coc_connection_throughput_2_conn: is_secured={}, Interval={}, buffer_size={}, "
     94             "le_tx_data_length={}, min_ce_len={}".format(is_secured, le_connection_interval,
     95                                           buffer_size, le_tx_data_length, min_ce_len))
     96         status, client_conn_id1, server_conn_id1 = orchestrate_coc_connection(
     97             self.client_ad, self.server_ad, True, is_secured,
     98             le_connection_interval, le_tx_data_length, default_bluetooth_socket_timeout_ms,
     99             min_ce_len, max_ce_len)
    100         if not status:
    101             return False
    102 
    103         status, client_conn_id2, server_conn_id2 = orchestrate_coc_connection(
    104             self.client_ad, self.server2_ad, True, is_secured,
    105             le_connection_interval, le_tx_data_length, default_bluetooth_socket_timeout_ms,
    106             min_ce_len, max_ce_len)
    107         if not status:
    108             return False
    109 
    110         list_server_ad = [self.server_ad, self.server2_ad]
    111         list_client_conn_id = [client_conn_id1, client_conn_id2]
    112         data_rate = do_multi_connection_throughput(
    113             self.client_ad, list_server_ad, list_client_conn_id,
    114             num_iterations, number_buffers, buffer_size)
    115         if data_rate <= 0:
    116             return False
    117 
    118         self.log.info(
    119             "test_coc_connection_throughput_2_conn: throughput=%d bytes per "
    120             "sec", data_rate)
    121 
    122         self.client_ad.droid.bluetoothSocketConnStop(client_conn_id1)
    123         self.client_ad.droid.bluetoothSocketConnStop(client_conn_id2)
    124         self.server_ad.droid.bluetoothSocketConnStop(server_conn_id1)
    125         self.server2_ad.droid.bluetoothSocketConnStop(server_conn_id2)
    126         return True
    127 
    128     @BluetoothBaseTest.bt_test_wrap
    129     @test_tracker_info(uuid='27226006-b725-4312-920e-6193cf0539d4')
    130     def test_coc_insecured_connection_throughput_2_conn(self):
    131         """Test LE CoC data throughput on two insecured connections
    132 
    133         Test Data Throughput of 2 L2CAP CoC insecured connections.
    134         3 phones are required.
    135 
    136         Steps:
    137         1. Get the mac address of the server device.
    138         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    139         The connection is insecured.
    140         3. Verify that the L2CAP CoC connection is active from both the client
    141         and server.
    142         4. Establish a L2CAP CoC connection from the client to the server#2 AD.
    143         The connection is insecured.
    144         5. Verify that the L2CAP CoC connection is active from both the client
    145         and server.
    146         6. Write data from the client to both server#1 and server#2.
    147         7. Verify data matches from client and server
    148 
    149         Expected Result:
    150         L2CAP CoC connections are established and data written correctly to both servers.
    151 
    152         Returns:
    153           Pass if True
    154           Fail if False
    155 
    156         TAGS: BLE, CoC
    157         Priority: 2
    158         """
    159 
    160         # Note: A 117 octets buffer size would fix nicely to a 123 bytes Data Length
    161         status = self._run_coc_connection_throughput_2_conn(False, 117)
    162         return status
    163 
    164     @BluetoothBaseTest.bt_test_wrap
    165     @test_tracker_info(uuid='1a5fb032-8a27-42f1-933f-3e39311c09a6')
    166     def test_coc_secured_connection_throughput_2_conn(self):
    167         """Test LE CoC data throughput on two secured connections
    168 
    169         Test Data Throughput of 2 L2CAP CoC secured connections.
    170         3 phones are required.
    171 
    172         Steps:
    173         1. Get the mac address of the server device.
    174         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    175         The connection is secured.
    176         3. Verify that the L2CAP CoC connection is active from both the client
    177         and server.
    178         4. Establish a L2CAP CoC connection from the client to the server#2 AD.
    179         The connection is secured.
    180         5. Verify that the L2CAP CoC connection is active from both the client
    181         and server.
    182         6. Write data from the client to both server#1 and server#2.
    183         7. Verify data matches from client and server
    184 
    185         Expected Result:
    186         L2CAP CoC connections are established and data written correctly to both servers.
    187 
    188         Returns:
    189           Pass if True
    190           Fail if False
    191 
    192         TAGS: BLE, CoC
    193         Priority: 2
    194         """
    195 
    196         # Note: A 117 octets buffer size would fix nicely to a 123 bytes Data Length
    197         status = self._run_coc_connection_throughput_2_conn(True, 117)
    198         return status
    199 
    200     @BluetoothBaseTest.bt_test_wrap
    201     @test_tracker_info(uuid='b198f8cc-26af-44bd-bb4d-7dc8f8645617')
    202     def test_coc_connection_throughput_2_conn_NOSEC_10CI_60SIZE(self):
    203         """Test LE CoC data throughput with 10msec CI and 60bytes buffer size.
    204 
    205         Test data throughput of 2 L2CAP CoC insecured connections with 20msec connection interval
    206         and 60 bytes buffer size. 3 phones are required.
    207 
    208         Steps:
    209         1. Get the mac address of the server device.
    210         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    211         The connection is insecured.
    212         3. Set the connection interval to 20 msec and buffer size to 60 bytes.
    213         4. Verify that the L2CAP CoC connection is active from both the client
    214         and server.
    215         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    216         The connection is insecured.
    217         6. Set the connection interval to 20 msec and buffer size to 60 bytes.
    218         7. Verify that the L2CAP CoC connection is active from both the client
    219         and server.
    220         8. Write data from the client to both server#1 and server#2.
    221         9. Verify data matches from client and server
    222 
    223         Expected Result:
    224         L2CAP CoC connections are established and data written correctly to both servers.
    225 
    226         Returns:
    227           Pass if True
    228           Fail if False
    229 
    230         TAGS: BLE, CoC
    231         Priority: 1
    232         """
    233 
    234         is_secured = False
    235         le_connection_interval = 10
    236         buffer_size = 60
    237         le_tx_data_length = buffer_size + l2cap_coc_header_size
    238 
    239         status = self._run_coc_connection_throughput_2_conn(
    240             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    241             self._calc_min_max_ce_time(le_connection_interval),
    242             self._calc_min_max_ce_time(le_connection_interval))
    243         return status
    244 
    245     @BluetoothBaseTest.bt_test_wrap
    246     @test_tracker_info(uuid='12dc2a6c-8283-4617-a911-42335dd693a8')
    247     def test_coc_connection_throughput_2_conn_NOSEC_10CI_80SIZE(self):
    248         """Test LE CoC data throughput with 10msec CI and 80bytes buffer size.
    249 
    250         Test data throughput of 2 L2CAP CoC insecured connections with 20msec connection interval
    251         and 80 bytes buffer size. 3 phones are required.
    252 
    253         Steps:
    254         1. Get the mac address of the server device.
    255         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    256         The connection is insecured.
    257         3. Set the connection interval to 20 msec and buffer size to 80 bytes.
    258         4. Verify that the L2CAP CoC connection is active from both the client
    259         and server.
    260         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    261         The connection is insecured.
    262         6. Set the connection interval to 20 msec and buffer size to 80 bytes.
    263         7. Verify that the L2CAP CoC connection is active from both the client
    264         and server.
    265         8. Write data from the client to both server#1 and server#2.
    266         9. Verify data matches from client and server
    267 
    268         Expected Result:
    269         L2CAP CoC connections are established and data written correctly to both servers.
    270 
    271         Returns:
    272           Pass if True
    273           Fail if False
    274 
    275         TAGS: BLE, CoC
    276         Priority: 1
    277         """
    278 
    279         is_secured = False
    280         le_connection_interval = 10
    281         buffer_size = 80
    282         le_tx_data_length = buffer_size + l2cap_coc_header_size
    283         status = self._run_coc_connection_throughput_2_conn(
    284             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    285             self._calc_min_max_ce_time(le_connection_interval),
    286             self._calc_min_max_ce_time(le_connection_interval))
    287         return status
    288 
    289     @BluetoothBaseTest.bt_test_wrap
    290     @test_tracker_info(uuid='4730df05-3909-4adf-a365-7f0c3258c402')
    291     def test_coc_connection_throughput_2_conn_NOSEC_10CI_120SIZE(self):
    292         """Test LE CoC data throughput with 10msec CI and 120bytes buffer size.
    293 
    294         Test data throughput of 2 L2CAP CoC insecured connections with 20msec connection interval
    295         and 120 bytes buffer size. 3 phones are required.
    296 
    297         Steps:
    298         1. Get the mac address of the server device.
    299         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    300         The connection is insecured.
    301         3. Set the connection interval to 20 msec and buffer size to 120 bytes.
    302         4. Verify that the L2CAP CoC connection is active from both the client
    303         and server.
    304         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    305         The connection is insecured.
    306         6. Set the connection interval to 20 msec and buffer size to 120 bytes.
    307         7. Verify that the L2CAP CoC connection is active from both the client
    308         and server.
    309         8. Write data from the client to both server#1 and server#2.
    310         9. Verify data matches from client and server
    311 
    312         Expected Result:
    313         L2CAP CoC connections are established and data written correctly to both servers.
    314 
    315         Returns:
    316           Pass if True
    317           Fail if False
    318 
    319         TAGS: BLE, CoC
    320         Priority: 1
    321         """
    322 
    323         is_secured = False
    324         le_connection_interval = 10
    325         buffer_size = 120
    326         le_tx_data_length = buffer_size + l2cap_coc_header_size
    327         status = self._run_coc_connection_throughput_2_conn(
    328             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    329             self._calc_min_max_ce_time(le_connection_interval),
    330             self._calc_min_max_ce_time(le_connection_interval))
    331         return status
    332 
    333     @BluetoothBaseTest.bt_test_wrap
    334     @test_tracker_info(uuid='471a8748-b0a5-4be5-9322-7c75e2b5d048')
    335     def test_coc_connection_throughput_2_conn_NOSEC_15CI_120SIZE(self):
    336         """Test LE CoC data throughput with 15msec CI and 120bytes buffer size.
    337 
    338         Test data throughput of 2 L2CAP CoC insecured connections with 15msec connection interval
    339         and 120 bytes buffer size. 3 phones are required.
    340 
    341         Steps:
    342         1. Get the mac address of the server device.
    343         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    344         The connection is insecured.
    345         3. Set the connection interval to 15 msec and buffer size to 120 bytes.
    346         4. Verify that the L2CAP CoC connection is active from both the client
    347         and server.
    348         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    349         The connection is insecured.
    350         6. Set the connection interval to 15 msec and buffer size to 120 bytes.
    351         7. Verify that the L2CAP CoC connection is active from both the client
    352         and server.
    353         8. Write data from the client to both server#1 and server#2.
    354         9. Verify data matches from client and server
    355 
    356         Expected Result:
    357         L2CAP CoC connections are established and data written correctly to both servers.
    358 
    359         Returns:
    360           Pass if True
    361           Fail if False
    362 
    363         TAGS: BLE, CoC
    364         Priority: 1
    365         """
    366 
    367         is_secured = False
    368         le_connection_interval = 15
    369         buffer_size = 120
    370         le_tx_data_length = buffer_size + l2cap_coc_header_size
    371         status = self._run_coc_connection_throughput_2_conn(
    372             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    373             self._calc_min_max_ce_time(le_connection_interval),
    374             self._calc_min_max_ce_time(le_connection_interval))
    375         return status
    376 
    377     @BluetoothBaseTest.bt_test_wrap
    378     @test_tracker_info(uuid='053e59c2-f312-4bec-beaf-9e4efdce063a')
    379     def test_coc_connection_throughput_2_conn_NOSEC_15CI_180SIZE(self):
    380         """Test LE CoC data throughput with 15msec CI and 180bytes buffer size.
    381 
    382         Test data throughput of 2 L2CAP CoC insecured connections with 15msec connection interval
    383         and 120 bytes buffer size. 3 phones are required.
    384 
    385         Steps:
    386         1. Get the mac address of the server device.
    387         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    388         The connection is insecured.
    389         3. Set the connection interval to 15 msec and buffer size to 180 bytes.
    390         4. Verify that the L2CAP CoC connection is active from both the client
    391         and server.
    392         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    393         The connection is insecured.
    394         6. Set the connection interval to 15 msec and buffer size to 180 bytes.
    395         7. Verify that the L2CAP CoC connection is active from both the client
    396         and server.
    397         8. Write data from the client to both server#1 and server#2.
    398         9. Verify data matches from client and server
    399 
    400         Expected Result:
    401         L2CAP CoC connections are established and data written correctly to both servers.
    402 
    403         Returns:
    404           Pass if True
    405           Fail if False
    406 
    407         TAGS: BLE, CoC
    408         Priority: 1
    409         """
    410 
    411         is_secured = False
    412         le_connection_interval = 15
    413         buffer_size = 180
    414         le_tx_data_length = buffer_size + l2cap_coc_header_size
    415         status = self._run_coc_connection_throughput_2_conn(
    416             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    417             self._calc_min_max_ce_time(le_connection_interval),
    418             self._calc_min_max_ce_time(le_connection_interval))
    419         return status
    420 
    421     @BluetoothBaseTest.bt_test_wrap
    422     @test_tracker_info(uuid='2b43caa6-76b3-48c5-b342-32ebb31ac52c')
    423     def test_coc_connection_throughput_2_conn_NOSEC_20CI_240SIZE(self):
    424         """Test LE CoC data throughput with 20msec CI and 240bytes buffer size.
    425 
    426         Test data throughput of 2 L2CAP CoC insecured connections with 20msec connection interval
    427         and 240 bytes buffer size. 3 phones are required.
    428 
    429         Steps:
    430         1. Get the mac address of the server device.
    431         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    432         The connection is insecured.
    433         3. Set the connection interval to 20 msec and buffer size to 240 bytes.
    434         4. Verify that the L2CAP CoC connection is active from both the client
    435         and server.
    436         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    437         The connection is insecured.
    438         6. Set the connection interval to 20 msec and buffer size to 240 bytes.
    439         7. Verify that the L2CAP CoC connection is active from both the client
    440         and server.
    441         8. Write data from the client to both server#1 and server#2.
    442         9. Verify data matches from client and server
    443 
    444         Expected Result:
    445         L2CAP CoC connections are established and data written correctly to both servers.
    446 
    447         Returns:
    448           Pass if True
    449           Fail if False
    450 
    451         TAGS: BLE, CoC
    452         Priority: 1
    453         """
    454 
    455         is_secured = False
    456         le_connection_interval = 20
    457         buffer_size = 240
    458         le_tx_data_length = buffer_size + l2cap_coc_header_size
    459         status = self._run_coc_connection_throughput_2_conn(
    460             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    461             self._calc_min_max_ce_time(le_connection_interval),
    462             self._calc_min_max_ce_time(le_connection_interval))
    463         return status
    464 
    465     @BluetoothBaseTest.bt_test_wrap
    466     @test_tracker_info(uuid='f630df02-3fd6-4aa0-bc15-06837b705e97')
    467     def test_coc_connection_throughput_2_conn_NOSEC_30CI_240SIZE(self):
    468         """Test LE CoC data throughput with 30msec CI and 240bytes buffer size.
    469 
    470         Test data throughput of 2 L2CAP CoC insecured connections with 20msec connection interval
    471         and 240 bytes buffer size. 3 phones are required.
    472 
    473         Steps:
    474         1. Get the mac address of the server device.
    475         2. Establish a L2CAP CoC connection from the client to the server#1 AD.
    476         The connection is insecured.
    477         3. Set the connection interval to 30 msec and buffer size to 240 bytes.
    478         4. Verify that the L2CAP CoC connection is active from both the client
    479         and server.
    480         5. Establish a L2CAP CoC connection from the client to the server#2 AD.
    481         The connection is insecured.
    482         6. Set the connection interval to 30 msec and buffer size to 240 bytes.
    483         7. Verify that the L2CAP CoC connection is active from both the client
    484         and server.
    485         8. Write data from the client to both server#1 and server#2.
    486         9. Verify data matches from client and server
    487 
    488         Expected Result:
    489         L2CAP CoC connections are established and data written correctly to both servers.
    490 
    491         Returns:
    492           Pass if True
    493           Fail if False
    494 
    495         TAGS: BLE, CoC
    496         Priority: 2
    497         """
    498 
    499         is_secured = False
    500         le_connection_interval = 30
    501         buffer_size = 240
    502         le_tx_data_length = buffer_size + l2cap_coc_header_size
    503         status = self._run_coc_connection_throughput_2_conn(
    504             is_secured, buffer_size, le_connection_interval, le_tx_data_length,
    505             self._calc_min_max_ce_time(le_connection_interval),
    506             self._calc_min_max_ce_time(le_connection_interval))
    507         return status
    508