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 18 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 l2cap_coc_header_size 31 from acts.test_utils.bt.bt_constants import l2cap_max_inactivity_delay_after_disconnect 32 from acts.test_utils.bt.bt_test_utils import clear_bonded_devices 33 from acts.test_utils.bt.bt_test_utils import kill_bluetooth_process 34 from acts.test_utils.bt.bt_test_utils import reset_bluetooth 35 from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 36 from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs 37 from acts.test_utils.bt.bt_test_utils import write_read_verify_data 38 from acts.test_utils.bt.bt_test_utils import verify_server_and_client_connected 39 40 41 class BleCocTest(BluetoothBaseTest): 42 message = ( 43 "Space: the final frontier. These are the voyages of " 44 "the starship Enterprise. Its continuing mission: to explore " 45 "strange new worlds, to seek out new life and new civilizations," 46 " to boldly go where no man has gone before.") 47 48 def __init__(self, controllers): 49 BluetoothBaseTest.__init__(self, controllers) 50 self.client_ad = self.android_devices[0] 51 self.server_ad = self.android_devices[1] 52 # Note that some tests required a third device. 53 if len(self.android_devices) > 2: 54 self.server2_ad = self.android_devices[2] 55 56 def setup_class(self): 57 return setup_multiple_devices_for_bt_test(self.android_devices) 58 59 def teardown_test(self): 60 self.client_ad.droid.bluetoothSocketConnStop() 61 self.server_ad.droid.bluetoothSocketConnStop() 62 # Give sufficient time for the physical LE link to be disconnected. 63 time.sleep(l2cap_max_inactivity_delay_after_disconnect) 64 65 def _run_coc_connection_throughput( 66 self, 67 is_secured, 68 buffer_size, 69 le_connection_interval=0, 70 le_tx_data_length=default_le_data_length): 71 72 # The num_iterations is that number of repetitions of each 73 # set of buffers r/w. 74 # number_buffers is the total number of data buffers to transmit per 75 # set of buffers r/w. 76 # buffer_size is the number of bytes per L2CAP data buffer. 77 number_buffers = 100 78 num_iterations = 10 79 80 self.log.info( 81 "_run_coc_connection_throughput: calling " 82 "orchestrate_coc_connection. is_secured={}, Connection Interval={}msec, " 83 "buffer_size={}bytes".format(is_secured, le_connection_interval, 84 buffer_size)) 85 status, client_conn_id, server_conn_id = orchestrate_coc_connection( 86 self.client_ad, self.server_ad, True, is_secured, 87 le_connection_interval, le_tx_data_length) 88 if not status: 89 return False 90 91 list_server_ad = [self.server_ad] 92 list_client_conn_id = [client_conn_id] 93 data_rate = do_multi_connection_throughput( 94 self.client_ad, list_server_ad, list_client_conn_id, 95 num_iterations, number_buffers, buffer_size) 96 if data_rate <= 0: 97 return False 98 self.log.info( 99 "_run_coc_connection_throughput: throughput=%d bytes per sec", 100 data_rate) 101 102 return True 103 104 @BluetoothBaseTest.bt_test_wrap 105 @test_tracker_info(uuid='b6989966-c504-4934-bcd7-57fb4f7fde9c') 106 def test_coc_secured_connection(self): 107 """Test Bluetooth LE CoC secured connection 108 109 Test LE CoC though establishing a basic connection with security. 110 111 Steps: 112 1. Get the mac address of the server device. 113 2. Establish an LE CoC Secured connection from the client to the server AD. 114 3. Verify that the LE CoC connection is active from both the client and 115 server. 116 Expected Result: 117 LE CoC connection is established then disconnected succcessfully. 118 119 Returns: 120 Pass if True 121 Fail if False 122 123 TAGS: BLE, CoC 124 Priority: 1 125 """ 126 is_secured = True 127 self.log.info( 128 "_test_coc_secured_connection: calling orchestrate_coc_connection but " 129 "isBle=1 and securedConn={}".format(is_secured)) 130 status, client_conn_id, server_conn_id = orchestrate_coc_connection( 131 self.client_ad, self.server_ad, True, is_secured) 132 if not status: 133 return False 134 135 return True 136 137 @BluetoothBaseTest.bt_test_wrap 138 @test_tracker_info(uuid='6587792c-78fb-469f-9084-772c249f97de') 139 def test_coc_insecured_connection(self): 140 """Test Bluetooth LE CoC insecured connection 141 142 Test LE CoC though establishing a basic connection with no security. 143 144 Steps: 145 1. Get the mac address of the server device. 146 2. Establish an LE CoC Secured connection from the client to the server AD. 147 3. Verify that the LE CoC connection is active from both the client and 148 server. 149 Expected Result: 150 LE CoC connection is established then disconnected succcessfully. 151 152 Returns: 153 Pass if True 154 Fail if False 155 156 TAGS: BLE, CoC 157 Priority: 1 158 """ 159 is_secured = False 160 self.log.info( 161 "test_coc_insecured_connection: calling orchestrate_coc_connection but " 162 "isBle=1 and securedConn={}".format(is_secured)) 163 status, client_conn_id, server_conn_id = orchestrate_coc_connection( 164 self.client_ad, self.server_ad, True, is_secured) 165 if not status: 166 return False 167 168 return True 169 170 @BluetoothBaseTest.bt_test_wrap 171 @test_tracker_info(uuid='32a7b02e-f2b5-4193-b414-36c8815ac407') 172 def test_coc_secured_connection_write_ascii(self): 173 """Test LE CoC secured connection writing and reading ascii data 174 175 Test LE CoC though establishing a secured connection and reading and writing ascii data. 176 177 Steps: 178 1. Get the mac address of the server device. 179 2. Establish an LE CoC connection from the client to the server AD. The security of 180 connection is TRUE. 181 3. Verify that the LE CoC connection is active from both the client and 182 server. 183 4. Write data from the client and read received data from the server. 184 5. Verify data matches from client and server 185 6. Disconnect the LE CoC connection. 186 187 Expected Result: 188 LE CoC connection is established then disconnected succcessfully. 189 190 Returns: 191 Pass if True 192 Fail if False 193 194 TAGS: BLE, CoC 195 Priority: 1 196 """ 197 is_secured = True 198 self.log.info( 199 "test_coc_secured_connection_write_ascii: calling " 200 "orchestrate_coc_connection. is_secured={}".format(is_secured)) 201 status, client_conn_id, server_conn_id = orchestrate_coc_connection( 202 self.client_ad, self.server_ad, True, is_secured) 203 if not status: 204 return False 205 if not write_read_verify_data(self.client_ad, self.server_ad, 206 self.message, False): 207 return False 208 if not verify_server_and_client_connected(self.client_ad, 209 self.server_ad): 210 return False 211 212 return True 213 214 @BluetoothBaseTest.bt_test_wrap 215 @test_tracker_info(uuid='12537d27-79c9-40a0-8bdb-d023b0e36b58') 216 def test_coc_insecured_connection_write_ascii(self): 217 """Test LE CoC insecured connection writing and reading ascii data 218 219 Test LE CoC though establishing a connection. 220 221 Steps: 222 1. Get the mac address of the server device. 223 2. Establish an LE CoC connection from the client to the server AD. The security of 224 connection is FALSE. 225 3. Verify that the LE CoC connection is active from both the client and 226 server. 227 4. Write data from the client and read received data from the server. 228 5. Verify data matches from client and server 229 6. Disconnect the LE CoC connection. 230 231 Expected Result: 232 LE CoC connection is established then disconnected succcessfully. 233 234 Returns: 235 Pass if True 236 Fail if False 237 238 TAGS: BLE, CoC 239 Priority: 1 240 """ 241 is_secured = False 242 self.log.info( 243 "test_coc_secured_connection_write_ascii: calling " 244 "orchestrate_coc_connection. is_secured={}".format(is_secured)) 245 status, client_conn_id, server_conn_id = orchestrate_coc_connection( 246 self.client_ad, self.server_ad, True, is_secured) 247 if not status: 248 return False 249 if not write_read_verify_data(self.client_ad, self.server_ad, 250 self.message, False): 251 return False 252 if not verify_server_and_client_connected(self.client_ad, 253 self.server_ad): 254 return False 255 256 return True 257 258 @BluetoothBaseTest.bt_test_wrap 259 @test_tracker_info(uuid='214037f4-f0d1-47db-86a7-5230c71bdcac') 260 def test_coc_secured_connection_throughput(self): 261 """Test LE CoC writing and measured data throughput with security 262 263 Test CoC thoughput by establishing a secured connection and sending data. 264 265 Steps: 266 1. Get the mac address of the server device. 267 2. Establish a L2CAP CoC connection from the client to the server AD. 268 3. Verify that the L2CAP CoC connection is active from both the client 269 and server. 270 4. Write data from the client to server. 271 5. Verify data matches from client and server 272 6. Disconnect the L2CAP CoC connections. 273 274 Expected Result: 275 CoC connection is established then disconnected succcessfully. 276 277 Returns: 278 Pass if True 279 Fail if False 280 281 TAGS: BLE, CoC 282 Priority: 1 283 """ 284 285 is_secured = True 286 # Note: A 117 octets buffer size would fix nicely to a 123 bytes Data Length 287 return self._run_coc_connection_throughput(is_secured, 117) 288 289 @BluetoothBaseTest.bt_test_wrap 290 @test_tracker_info(uuid='6dc019bb-c3bf-4c98-978e-e2c5755058d7') 291 def test_coc_insecured_connection_throughput(self): 292 """Test LE CoC writing and measured data throughput without security. 293 294 Test CoC thoughput by establishing an insecured connection and sending data. 295 296 Steps: 297 1. Get the mac address of the server device. 298 2. Establish a L2CAP CoC connection from the client to the server AD. 299 3. Verify that the L2CAP CoC connection is active from both the client 300 and server. 301 4. Write data from the client to server. 302 5. Verify data matches from client and server 303 6. Disconnect the L2CAP CoC connections. 304 305 Expected Result: 306 CoC connection is established then disconnected succcessfully. 307 308 Returns: 309 Pass if True 310 Fail if False 311 312 TAGS: BLE, CoC 313 Priority: 1 314 """ 315 316 is_secured = False 317 # Note: A 117 octets buffer size would fix nicely to a 123 bytes Data Length 318 return self._run_coc_connection_throughput(is_secured, 117) 319 320 @BluetoothBaseTest.bt_test_wrap 321 @test_tracker_info(uuid='0af94805-1550-426c-bfdd-191b8b3a4c12') 322 def test_coc_connection_throughput_NOSEC_10CI_60SIZE(self): 323 """Test LE CoC data throughput with 10msec CI and 60bytes buffer size. 324 325 Test CoC thoughput by establishing a connection and sending data with 10msec 326 Connection Interval and 60 bytes data buffer size. 327 328 Steps: 329 1. Get the mac address of the server device. 330 2. Change the Connection Interval to 10msec. 331 3. Change Payload Buffer Size to 60 bytes. 332 4. Establish a L2CAP CoC connection from the client to the server AD. 333 5. Verify that the L2CAP CoC connection is active from both the client 334 and server. 335 6. Write data from the client to server. 336 7. Verify data matches from client and server 337 8. Disconnect the L2CAP CoC connections. 338 339 Expected Result: 340 CoC connection is established, check transmitted data contents, then disconnected 341 succcessfully. 342 343 Returns: 344 Pass if True 345 Fail if False 346 347 TAGS: BLE, CoC 348 Priority: 2 349 """ 350 351 is_secured = False 352 le_connection_interval = 10 353 buffer_size = 60 354 le_tx_data_length = buffer_size + l2cap_coc_header_size 355 return self._run_coc_connection_throughput( 356 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 357 358 @BluetoothBaseTest.bt_test_wrap 359 @test_tracker_info(uuid='c32dac07-623a-4fdd-96c6-387a76afb2af') 360 def test_coc_connection_throughput_NOSEC_10CI_80SIZE(self): 361 """Test LE CoC data throughput with 10msec CI and 80bytes buffer size. 362 363 Test CoC thoughput by establishing a connection and sending data with 10msec 364 Connection Interval and 80 bytes data buffer size. 365 366 Steps: 367 1. Get the mac address of the server device. 368 2. Change the Connection Interval to 10msec. 369 3. Change Payload Buffer Size to 80 bytes. 370 4. Establish a L2CAP CoC connection from the client to the server AD. 371 5. Verify that the L2CAP CoC connection is active from both the client 372 and server. 373 6. Write data from the client to server. 374 7. Verify data matches from client and server 375 8. Disconnect the L2CAP CoC connections. 376 377 Expected Result: 378 CoC connection is established, check transmitted data contents, then disconnected 379 succcessfully. 380 381 Returns: 382 Pass if True 383 Fail if False 384 385 TAGS: BLE, CoC 386 Priority: 2 387 """ 388 389 is_secured = False 390 le_connection_interval = 10 391 buffer_size = 80 392 le_tx_data_length = buffer_size + l2cap_coc_header_size 393 return self._run_coc_connection_throughput( 394 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 395 396 @BluetoothBaseTest.bt_test_wrap 397 @test_tracker_info(uuid='45d1b0c1-73b6-483f-ac6b-c3cec805da32') 398 def test_coc_connection_throughput_NOSEC_10CI_120SIZE(self): 399 """Test LE CoC data throughput with 10msec CI and 120bytes buffer size. 400 401 Test CoC thoughput by establishing a connection and sending data with 10msec 402 Connection Interval and 120 bytes data buffer size. 403 404 Steps: 405 1. Get the mac address of the server device. 406 2. Change the Connection Interval to 10msec. 407 3. Change Payload Buffer Size to 120 bytes. 408 4. Establish a L2CAP CoC connection from the client to the server AD. 409 5. Verify that the L2CAP CoC connection is active from both the client 410 and server. 411 6. Write data from the client to server. 412 7. Verify data matches from client and server 413 8. Disconnect the L2CAP CoC connections. 414 415 Expected Result: 416 CoC connection is established, check transmitted data contents, then disconnected 417 succcessfully. 418 419 Returns: 420 Pass if True 421 Fail if False 422 423 TAGS: BLE, CoC 424 Priority: 2 425 """ 426 427 is_secured = False 428 le_connection_interval = 10 429 buffer_size = 120 430 le_tx_data_length = buffer_size + l2cap_coc_header_size 431 return self._run_coc_connection_throughput( 432 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 433 434 @BluetoothBaseTest.bt_test_wrap 435 @test_tracker_info(uuid='85f07f07-1017-42db-b38d-df0bf2fce804') 436 def test_coc_connection_throughput_NOSEC_15CI_120SIZE(self): 437 """Test LE CoC data throughput with 15msec CI and 120bytes buffer size. 438 439 Test CoC thoughput by establishing a connection and sending data with 15msec 440 Connection Interval and 120 bytes data buffer size. 441 442 Steps: 443 1. Get the mac address of the server device. 444 2. Change the Connection Interval to 15msec. 445 3. Change Payload Buffer Size to 120 bytes. 446 4. Establish a L2CAP CoC connection from the client to the server AD. 447 5. Verify that the L2CAP CoC connection is active from both the client 448 and server. 449 6. Write data from the client to server. 450 7. Verify data matches from client and server 451 8. Disconnect the L2CAP CoC connections. 452 453 Expected Result: 454 CoC connection is established, check transmitted data contents, then disconnected 455 succcessfully. 456 457 Returns: 458 Pass if True 459 Fail if False 460 461 TAGS: BLE, CoC 462 Priority: 2 463 """ 464 465 is_secured = False 466 le_connection_interval = 15 467 buffer_size = 120 468 le_tx_data_length = buffer_size + l2cap_coc_header_size 469 return self._run_coc_connection_throughput( 470 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 471 472 @BluetoothBaseTest.bt_test_wrap 473 @test_tracker_info(uuid='4d3d4a06-7bbb-4a8c-9016-f326560cebb0') 474 def test_coc_connection_throughput_NOSEC_15CI_180SIZE(self): 475 """Test LE CoC data throughput with 15msec CI and 180bytes buffer size. 476 477 Test CoC thoughput by establishing a connection and sending data with 15msec 478 Connection Interval and 180 bytes data buffer size. 479 480 Steps: 481 1. Get the mac address of the server device. 482 2. Change the Connection Interval to 15msec. 483 3. Change Payload Buffer Size to 180 bytes. 484 4. Establish a L2CAP CoC connection from the client to the server AD. 485 5. Verify that the L2CAP CoC connection is active from both the client 486 and server. 487 6. Write data from the client to server. 488 7. Verify data matches from client and server 489 8. Disconnect the L2CAP CoC connections. 490 491 Expected Result: 492 CoC connection is established, check transmitted data contents, then disconnected 493 succcessfully. 494 495 Returns: 496 Pass if True 497 Fail if False 498 499 TAGS: BLE, CoC 500 Priority: 2 501 """ 502 503 is_secured = False 504 le_connection_interval = 15 505 buffer_size = 180 506 le_tx_data_length = buffer_size + l2cap_coc_header_size 507 return self._run_coc_connection_throughput( 508 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 509 510 @BluetoothBaseTest.bt_test_wrap 511 @test_tracker_info(uuid='124d85ba-41e6-4ab7-a017-99a88db7524a') 512 def test_coc_connection_throughput_NOSEC_20CI_240SIZE(self): 513 """Test LE CoC data throughput with 20msec CI and 240bytes buffer size. 514 515 Test CoC thoughput by establishing a connection and sending data with 20msec 516 Connection Interval and 240 bytes data buffer size. 517 518 Steps: 519 1. Get the mac address of the server device. 520 2. Change the Connection Interval to 20msec. 521 3. Change Payload Buffer Size to 240 bytes. 522 4. Establish a L2CAP CoC connection from the client to the server AD. 523 5. Verify that the L2CAP CoC connection is active from both the client 524 and server. 525 6. Write data from the client to server. 526 7. Verify data matches from client and server 527 8. Disconnect the L2CAP CoC connections. 528 529 Expected Result: 530 CoC connection is established, check transmitted data contents, then disconnected 531 succcessfully. 532 533 Returns: 534 Pass if True 535 Fail if False 536 537 TAGS: BLE, CoC 538 Priority: 2 539 """ 540 541 is_secured = False 542 le_connection_interval = 20 543 buffer_size = 240 544 le_tx_data_length = buffer_size + l2cap_coc_header_size 545 return self._run_coc_connection_throughput( 546 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 547 548 @BluetoothBaseTest.bt_test_wrap 549 @test_tracker_info(uuid='218932bc-ebb0-4c2b-96ad-220c600b50b1') 550 def test_coc_connection_throughput_NOSEC_30CI_240SIZE(self): 551 """Test LE CoC data throughput with 30msec CI and 240bytes buffer size. 552 553 Test CoC thoughput by establishing a connection and sending data with 30msec 554 Connection Interval and 240 bytes data buffer size. 555 556 Steps: 557 1. Get the mac address of the server device. 558 2. Change the Connection Interval to 30msec. 559 3. Change Payload Buffer Size to 240 bytes. 560 4. Establish a L2CAP CoC connection from the client to the server AD. 561 5. Verify that the L2CAP CoC connection is active from both the client 562 and server. 563 6. Write data from the client to server. 564 7. Verify data matches from client and server 565 8. Disconnect the L2CAP CoC connections. 566 567 Expected Result: 568 CoC connection is established, check transmitted data contents, then disconnected 569 succcessfully. 570 571 Returns: 572 Pass if True 573 Fail if False 574 575 TAGS: BLE, CoC 576 Priority: 2 577 """ 578 579 is_secured = False 580 le_connection_interval = 30 581 buffer_size = 240 582 le_tx_data_length = buffer_size + l2cap_coc_header_size 583 return self._run_coc_connection_throughput( 584 is_secured, buffer_size, le_connection_interval, le_tx_data_length) 585