merge in nyc-release history after reset to nyc-dev
diff --git a/acts/framework/acts/controllers/native_android_device.py b/acts/framework/acts/controllers/native_android_device.py
index eac7bcc..4730f68 100644
--- a/acts/framework/acts/controllers/native_android_device.py
+++ b/acts/framework/acts/controllers/native_android_device.py
@@ -24,7 +24,7 @@
#TODO(tturney): Merge this into android device
-ACTS_CONTROLLER_CONFIG_NAME = "NativeAndroid"
+ACTS_CONTROLLER_CONFIG_NAME = "NativeAndroidDevice"
ACTS_CONTROLLER_REFERENCE_NAME = "native_android_devices"
def create(configs, logger):
@@ -126,4 +126,4 @@
"new session. Abort."))
return droid
self._droid_sessions[droid.uid] = [droid]
- return droid
\ No newline at end of file
+ return droid
diff --git a/acts/framework/acts/test_utils/bt/BleEnum.py b/acts/framework/acts/test_utils/bt/BleEnum.py
index 8337e01..3982d09 100644
--- a/acts/framework/acts/test_utils/bt/BleEnum.py
+++ b/acts/framework/acts/test_utils/bt/BleEnum.py
@@ -18,146 +18,81 @@
class ScanSettingsCallbackType(Enum):
- CALLBACK_TYPE_ALL_MATCHES = 1
- CALLBACK_TYPE_FIRST_MATCH = 2
- CALLBACK_TYPE_MATCH_LOST = 4
- CALLBACK_TYPE_FOUND_AND_LOST = 6
+ CALLBACK_TYPE_ALL_MATCHES = 1
+ CALLBACK_TYPE_FIRST_MATCH = 2
+ CALLBACK_TYPE_MATCH_LOST = 4
+ CALLBACK_TYPE_FOUND_AND_LOST = 6
class ScanSettingsMatchMode(Enum):
- AGGRESIVE = 1
- STICKY = 2
+ AGGRESIVE = 1
+ STICKY = 2
class ScanSettingsMatchNum(Enum):
- MATCH_NUM_ONE_ADVERTISEMENT = 1
- MATCH_NUM_FEW_ADVERTISEMENT = 2
- MATCH_NUM_MAX_ADVERTISEMENT = 3
+ MATCH_NUM_ONE_ADVERTISEMENT = 1
+ MATCH_NUM_FEW_ADVERTISEMENT = 2
+ MATCH_NUM_MAX_ADVERTISEMENT = 3
class ScanSettingsScanResultType(Enum):
- SCAN_RESULT_TYPE_FULL = 0
- SCAN_RESULT_TYPE_ABBREVIATED = 1
+ SCAN_RESULT_TYPE_FULL = 0
+ SCAN_RESULT_TYPE_ABBREVIATED = 1
class ScanSettingsScanMode(Enum):
- SCAN_MODE_OPPORTUNISTIC = -1
- SCAN_MODE_LOW_POWER = 0
- SCAN_MODE_BALANCED = 1
- SCAN_MODE_LOW_LATENCY = 2
+ SCAN_MODE_OPPORTUNISTIC = -1
+ SCAN_MODE_LOW_POWER = 0
+ SCAN_MODE_BALANCED = 1
+ SCAN_MODE_LOW_LATENCY = 2
class ScanSettingsReportDelaySeconds(Enum):
- MIN = 0
- MAX = 9223372036854775807
+ MIN = 0
+ MAX = 9223372036854775807
class AdvertiseSettingsAdvertiseType(Enum):
- ADVERTISE_TYPE_NON_CONNECTABLE = 0
- ADVERTISE_TYPE_CONNECTABLE = 1
+ ADVERTISE_TYPE_NON_CONNECTABLE = 0
+ ADVERTISE_TYPE_CONNECTABLE = 1
class AdvertiseSettingsAdvertiseMode(Enum):
- ADVERTISE_MODE_LOW_POWER = 0
- ADVERTISE_MODE_BALANCED = 1
- ADVERTISE_MODE_LOW_LATENCY = 2
+ ADVERTISE_MODE_LOW_POWER = 0
+ ADVERTISE_MODE_BALANCED = 1
+ ADVERTISE_MODE_LOW_LATENCY = 2
class AdvertiseSettingsAdvertiseTxPower(Enum):
- ADVERTISE_TX_POWER_ULTRA_LOW = 0
- ADVERTISE_TX_POWER_LOW = 1
- ADVERTISE_TX_POWER_MEDIUM = 2
- ADVERTISE_TX_POWER_HIGH = 3
+ ADVERTISE_TX_POWER_ULTRA_LOW = 0
+ ADVERTISE_TX_POWER_LOW = 1
+ ADVERTISE_TX_POWER_MEDIUM = 2
+ ADVERTISE_TX_POWER_HIGH = 3
class JavaInteger(Enum):
- MIN = -2147483648
- MAX = 2147483647
+ MIN = -2147483648
+ MAX = 2147483647
class Uuids(Enum):
- P_Service = "0000feef-0000-1000-8000-00805f9b34fb"
- HR_SERVICE = "0000180d-0000-1000-8000-00805f9b34fb"
+ P_Service = "0000feef-0000-1000-8000-00805f9b34fb"
+ HR_SERVICE = "0000180d-0000-1000-8000-00805f9b34fb"
-class GattConnectionState(Enum):
- STATE_DISCONNECTED = 0
- STATE_CONNECTING = 1
- STATE_CONNECTED = 2
- STATE_DISCONNECTING = 3
-
-
-class BluetoothGattCharacteristic(Enum):
- PROPERTY_BROADCAST = 0x01
- PROPERTY_READ = 0x02
- PROPERTY_WRITE_NO_RESPONSE = 0x04
- PROPERTY_WRITE = 0x08
- PROPERTY_NOTIFY = 0x10
- PROPERTY_INDICATE = 0x20
- PROPERTY_SIGNED_WRITE = 0x40
- PROPERTY_EXTENDED_PROPS = 0x80
- PERMISSION_READ = 0x01
- PERMISSION_READ_ENCRYPTED = 0x02
- PERMISSION_READ_ENCRYPTED_MITM = 0x04
- PERMISSION_WRITE = 0x10
- PERMISSION_WRITE_ENCRYPTED = 0x20
- PERMISSION_WRITE_ENCRYPTED_MITM = 0x40
- PERMISSION_WRITE_SIGNED = 0x80
- PERMISSION_WRITE_SIGNED_MITM = 0x100
- WRITE_TYPE_DEFAULT = 0x02
- WRITE_TYPE_NO_RESPONSE = 0x01
- WRITE_TYPE_SIGNED = 0x04
- FORMAT_UINT8 = 0x11
- FORMAT_UINT16 = 0x12
- FORMAT_UINT32 = 0x14
- FORMAT_SINT8 = 0x21
- FORMAT_SINT16 = 0x22
- FORMAT_SINT32 = 0x24
- FORMAT_SFLOAT = 0x32
- FORMAT_FLOAT = 0x34
-
-class BluetoothGattDescriptor(Enum):
- ENABLE_NOTIFICATION_VALUE = [0x01, 0x00]
- ENABLE_INDICATION_VALUE = [0x02, 0x00]
- DISABLE_NOTIFICATION_VALUE = [0x00, 0x00]
- PERMISSION_READ = 0x01
- PERMISSION_READ_ENCRYPTED = 0x02
- PERMISSION_READ_ENCRYPTED_MITM = 0x04
- PERMISSION_WRITE = 0x10
- PERMISSION_WRITE_ENCRYPTED = 0x20
- PERMISSION_WRITE_ENCRYPTED_MITM = 0x40
- PERMISSION_WRITE_SIGNED = 0x80
- PERMISSION_WRITE_SIGNED_MITM = 0x100
-
-class BluetoothGattService(Enum):
- SERVICE_TYPE_PRIMARY = 0
- SERVICE_TYPE_SECONDARY = 1
-
-class BluetoothGattConnectionPriority(Enum):
- CONNECTION_PRIORITY_BALANCED = 0
- CONNECTION_PRIORITY_HIGH = 1
- CONNECTION_PRIORITY_LOW_POWER = 2
-
-class BluetoothGatt(Enum):
- GATT_SUCCESS = 0
- GATT_FAILURE = 0x101
-
class AdvertiseErrorCode(Enum):
- DATA_TOO_LARGE = 1
- TOO_MANY_ADVERTISERS = 2
- ADVERTISE_ALREADY_STARTED = 3
- BLUETOOTH_INTERNAL_FAILURE = 4
- FEATURE_NOT_SUPPORTED = 5
+ DATA_TOO_LARGE = 1
+ TOO_MANY_ADVERTISERS = 2
+ ADVERTISE_ALREADY_STARTED = 3
+ BLUETOOTH_INTERNAL_FAILURE = 4
+ FEATURE_NOT_SUPPORTED = 5
+
class BluetoothAdapterState(Enum):
- STATE_OFF = 10
- STATE_TURNING_ON = 11
- STATE_ON = 12
- STATE_TURNING_OFF = 13
- STATE_BLE_TURNING_ON = 14
- STATE_BLE_ON = 15
- STATE_BLE_TURNING_OFF = 16
-
-class BluetoothMtuSize(Enum):
- MIN = 23
- MAX = 217
\ No newline at end of file
+ STATE_OFF = 10
+ STATE_TURNING_ON = 11
+ STATE_ON = 12
+ STATE_TURNING_OFF = 13
+ STATE_BLE_TURNING_ON = 14
+ STATE_BLE_ON = 15
+ STATE_BLE_TURNING_OFF = 16
diff --git a/acts/framework/acts/test_utils/bt/BluetoothBaseTest.py b/acts/framework/acts/test_utils/bt/BluetoothBaseTest.py
index 92eb2b8..6036a40 100644
--- a/acts/framework/acts/test_utils/bt/BluetoothBaseTest.py
+++ b/acts/framework/acts/test_utils/bt/BluetoothBaseTest.py
@@ -17,16 +17,17 @@
Base Class for Defining Common Bluetooth Test Functionality
"""
+import os
import time
+from acts import utils
from acts.base_test import BaseTestClass
from acts.controllers import android_device
-from acts.test_utils.bt.bt_test_utils import (log_energy_info,
- reset_bluetooth,
- setup_multiple_devices_for_bt_test,
- take_btsnoop_logs)
+from acts.test_utils.bt.bt_test_utils import (
+ log_energy_info, reset_bluetooth, setup_multiple_devices_for_bt_test,
+ take_btsnoop_logs)
+
class BluetoothBaseTest(BaseTestClass):
-
def __init__(self, controllers):
BaseTestClass.__init__(self, controllers)
@@ -34,13 +35,12 @@
# faster log lookup and reduce ambiguity in logging.
def bt_test_wrap(fn):
def _safe_wrap_test_case(self, *args, **kwargs):
- test_id = "{}:{}:{}".format(
- self.__class__.__name__,
- fn.__name__,
- time.time())
+ test_id = "{}:{}:{}".format(self.__class__.__name__, fn.__name__,
+ time.time())
log_string = "[Test ID] {}".format(test_id)
self.log.info(log_string)
return fn(self, *args, **kwargs)
+
return _safe_wrap_test_case
def setup_class(self):
@@ -57,17 +57,32 @@
return True
def on_fail(self, test_name, begin_time):
- self.log.debug("Test {} failed. Gathering bugreport and btsnoop logs".
- format(test_name))
+ self.log.debug(
+ "Test {} failed. Gathering bugreport and btsnoop logs".format(
+ test_name))
take_btsnoop_logs(self.android_devices, self, test_name)
- reset_bluetooth(self.android_devices)
+ self._take_bug_report(test_name, begin_time)
+ for _ in range(5):
+ if reset_bluetooth(self.android_devices):
+ break
+ else:
+ self.log.error("Failed to reset Bluetooth... retrying.")
+ return
- if "no_bug_report_on_fail" not in self.user_params:
+ def _take_bug_report(self, test_name, begin_time):
+ if "no_bug_report_on_fail" in self.user_params:
+ return
+
+ # magical sleep to ensure the runtime restart or reboot begins
+ time.sleep(1)
+ for ad in self.android_devices:
try:
- android_device.take_bug_reports(test_name,
- begin_time,
- self.android_devices)
+ ad.adb.wait_for_device()
+ ad.take_bug_report(test_name, begin_time)
+ tombstone_path = os.path.join(ad.log_path, "BugReports",
+ "{},{}".format(begin_time, ad.serial).replace(' ','_'))
+ utils.create_dir(tombstone_path)
+ ad.adb.pull('/data/tombstones/', tombstone_path)
except:
- self.log.error("Failed to take a bug report for {}"
- .format(test_name))
-
+ ad.log.error("Failed to take a bug report for {}, {}"
+ .format(ad.serial, test_name))
diff --git a/acts/framework/acts/test_utils/bt/BtEnum.py b/acts/framework/acts/test_utils/bt/BtEnum.py
index 8e00f44..0f69037 100644
--- a/acts/framework/acts/test_utils/bt/BtEnum.py
+++ b/acts/framework/acts/test_utils/bt/BtEnum.py
@@ -16,8 +16,22 @@
from enum import Enum
+
class BluetoothScanModeType(Enum):
- STATE_OFF = -1
- SCAN_MODE_NONE = 0
- SCAN_MODE_CONNECTABLE = 1
- SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3
+ STATE_OFF = -1
+ SCAN_MODE_NONE = 0
+ SCAN_MODE_CONNECTABLE = 1
+ SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3
+
+
+class BluetoothAdapterState(Enum):
+ STATE_OFF = 10
+ STATE_TURNING_ON = 11
+ STATE_ON = 12
+ STATE_TURNING_OFF = 13
+ STATE_BLE_TURNING_ON = 14
+ STATE_BLE_ON = 15
+ STATE_BLE_TURNING_OFF = 16
+
+class RfcommUuid(Enum):
+ DEFAULT_UUID = "457807c0-4897-11df-9879-0800200c9a66"
diff --git a/acts/framework/acts/test_utils/bt/GattEnum.py b/acts/framework/acts/test_utils/bt/GattEnum.py
new file mode 100644
index 0000000..a9ee637
--- /dev/null
+++ b/acts/framework/acts/test_utils/bt/GattEnum.py
@@ -0,0 +1,113 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+from enum import Enum
+
+
+class GattCbErr(Enum):
+ CHAR_WRITE_REQ_ERR = "Characteristic Write Request event not found. Expected {}"
+ CHAR_WRITE_ERR = "Characteristic Write event not found. Expected {}"
+ DESC_WRITE_REQ_ERR = "Descriptor Write Request event not found. Expected {}"
+ DESC_WRITE_ERR = "Descriptor Write event not found. Expected {}"
+ RD_REMOTE_RSSI_ERR = "Read Remote RSSI event not found. Expected {}"
+ GATT_SERV_DISC_ERR = "GATT Services Discovered event not found. Expected {}"
+ SERV_ADDED_ERR = "Service Added event not found. Expected {}"
+ MTU_CHANGED_ERR = "MTU Changed event not found. Expected {}"
+ GATT_CONN_CHANGE_ERR = "GATT Connection Changed event not found. Expected {}"
+
+
+class GattCbStrings(Enum):
+ CHAR_WRITE_REQ = "GattServer{}onCharacteristicWriteRequest"
+ CHAR_WRITE = "GattConnect{}onCharacteristicWrite"
+ DESC_WRITE_REQ = "GattServer{}onDescriptorWriteRequest"
+ DESC_WRITE = "GattConnect{}onDescriptorWrite"
+ RD_REMOTE_RSSI = "GattConnect{}onReadRemoteRssi"
+ GATT_SERV_DISC = "GattConnect{}onServicesDiscovered"
+ SERV_ADDED = "GattServer{}onServiceAdded"
+ MTU_CHANGED = "GattConnect{}onMtuChanged"
+ GATT_CONN_CHANGE = "GattConnect{}onConnectionStateChange"
+
+
+class GattConnectionState(Enum):
+ STATE_DISCONNECTED = 0
+ STATE_CONNECTING = 1
+ STATE_CONNECTED = 2
+ STATE_DISCONNECTING = 3
+
+
+class GattCharacteristic(Enum):
+ PROPERTY_BROADCAST = 0x01
+ PROPERTY_READ = 0x02
+ PROPERTY_WRITE_NO_RESPONSE = 0x04
+ PROPERTY_WRITE = 0x08
+ PROPERTY_NOTIFY = 0x10
+ PROPERTY_INDICATE = 0x20
+ PROPERTY_SIGNED_WRITE = 0x40
+ PROPERTY_EXTENDED_PROPS = 0x80
+ PERMISSION_READ = 0x01
+ PERMISSION_READ_ENCRYPTED = 0x02
+ PERMISSION_READ_ENCRYPTED_MITM = 0x04
+ PERMISSION_WRITE = 0x10
+ PERMISSION_WRITE_ENCRYPTED = 0x20
+ PERMISSION_WRITE_ENCRYPTED_MITM = 0x40
+ PERMISSION_WRITE_SIGNED = 0x80
+ PERMISSION_WRITE_SIGNED_MITM = 0x100
+ WRITE_TYPE_DEFAULT = 0x02
+ WRITE_TYPE_NO_RESPONSE = 0x01
+ WRITE_TYPE_SIGNED = 0x04
+ FORMAT_UINT8 = 0x11
+ FORMAT_UINT16 = 0x12
+ FORMAT_UINT32 = 0x14
+ FORMAT_SINT8 = 0x21
+ FORMAT_SINT16 = 0x22
+ FORMAT_SINT32 = 0x24
+ FORMAT_SFLOAT = 0x32
+ FORMAT_FLOAT = 0x34
+
+
+class GattDescriptor(Enum):
+ ENABLE_NOTIFICATION_VALUE = [0x01, 0x00]
+ ENABLE_INDICATION_VALUE = [0x02, 0x00]
+ DISABLE_NOTIFICATION_VALUE = [0x00, 0x00]
+ PERMISSION_READ = 0x01
+ PERMISSION_READ_ENCRYPTED = 0x02
+ PERMISSION_READ_ENCRYPTED_MITM = 0x04
+ PERMISSION_WRITE = 0x10
+ PERMISSION_WRITE_ENCRYPTED = 0x20
+ PERMISSION_WRITE_ENCRYPTED_MITM = 0x40
+ PERMISSION_WRITE_SIGNED = 0x80
+ PERMISSION_WRITE_SIGNED_MITM = 0x100
+
+
+class GattService(Enum):
+ SERVICE_TYPE_PRIMARY = 0
+ SERVICE_TYPE_SECONDARY = 1
+
+
+class GattConnectionPriority(Enum):
+ CONNECTION_PRIORITY_BALANCED = 0
+ CONNECTION_PRIORITY_HIGH = 1
+ CONNECTION_PRIORITY_LOW_POWER = 2
+
+
+class MtuSize(Enum):
+ MIN = 23
+ MAX = 217
+
+
+class BluetoothGatt(Enum):
+ GATT_SUCCESS = 0
+ GATT_FAILURE = 0x101
diff --git a/acts/framework/acts/test_utils/bt/bt_gatt_utils.py b/acts/framework/acts/test_utils/bt/bt_gatt_utils.py
new file mode 100644
index 0000000..e95833d
--- /dev/null
+++ b/acts/framework/acts/test_utils/bt/bt_gatt_utils.py
@@ -0,0 +1,292 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+from acts.logger import LoggerProxy
+from acts.test_utils.bt.bt_test_utils import get_mac_address_of_generic_advertisement
+from acts.test_utils.bt.GattEnum import GattCbErr
+from acts.test_utils.bt.GattEnum import GattCbStrings
+from acts.test_utils.bt.GattEnum import GattConnectionState
+from acts.test_utils.bt.GattEnum import GattCharacteristic
+from acts.test_utils.bt.GattEnum import GattDescriptor
+from acts.test_utils.bt.GattEnum import GattService
+from acts.test_utils.bt.GattEnum import GattConnectionPriority
+import pprint
+from queue import Empty
+from contextlib import suppress
+
+default_timeout = 10
+log = LoggerProxy()
+
+
+def setup_gatt_connection(cen_ad, mac_address, autoconnect):
+ test_result = True
+ gatt_callback = cen_ad.droid.gattCreateGattCallback()
+ log.info("Gatt Connect to mac address {}.".format(mac_address))
+ bluetooth_gatt = cen_ad.droid.gattClientConnectGatt(
+ gatt_callback, mac_address, autoconnect)
+ expected_event = GattCbStrings.GATT_CONN_CHANGE.value.format(gatt_callback)
+ try:
+ event = cen_ad.ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.GATT_CONN_CHANGE_ERR.value.format(expected_event))
+ test_result = False
+ return test_result, bluetooth_gatt, gatt_callback
+ if event['data']['State'] != GattConnectionState.STATE_CONNECTED.value:
+ log.info("Could not establish a connection to peripheral. Event "
+ "Details:".format(pprint.pformat(event)))
+ test_result = False
+ return test_result, bluetooth_gatt, gatt_callback
+
+
+def disconnect_gatt_connection(cen_ad, bluetooth_gatt, gatt_callback):
+ cen_ad.droid.gattClientDisconnect(bluetooth_gatt)
+ expected_event = GattCbStrings.GATT_CONN_CHANGE.value.format(gatt_callback)
+ try:
+ event = cen_ad.ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.GATT_CONN_CHANGE_ERR.value.format(expected_event))
+ return False
+ if event['data']['State'] != GattConnectionState.STATE_DISCONNECTED.value:
+ return False
+ return True
+
+
+def orchestrate_gatt_connection(cen_ad,
+ per_ad,
+ le=True,
+ mac_address=None,
+ autoconnect=False):
+ adv_callback = None
+ if mac_address is None:
+ if le:
+ mac_address, adv_callback = (
+ get_mac_address_of_generic_advertisement(cen_ad, per_ad))
+ else:
+ mac_address = per_ad.droid.bluetoothGetLocalAddress()
+ adv_callback = None
+ test_result, bluetooth_gatt, gatt_callback = setup_gatt_connection(
+ cen_ad, mac_address, autoconnect)
+ if not test_result:
+ log.error("Could not connect to peripheral.")
+ return False, None, None
+ return bluetooth_gatt, gatt_callback, adv_callback
+
+
+def run_continuous_write_descriptor(cen_droid, cen_ed, per_droid, per_ed,
+ gatt_server, gatt_server_callback,
+ bluetooth_gatt, services_count,
+ discovered_services_index):
+ log.info("Starting continuous write")
+ bt_device_id = 0
+ status = 1
+ offset = 1
+ test_value = "1,2,3,4,5,6,7"
+ test_value_return = "1,2,3"
+ with suppress(Exception):
+ for x in range(100000):
+ for i in range(services_count):
+ characteristic_uuids = (
+ cen_droid.gattClientGetDiscoveredCharacteristicUuids(
+ discovered_services_index, i))
+ log.info(characteristic_uuids)
+ for characteristic in characteristic_uuids:
+ descriptor_uuids = (
+ cen_droid.gattClientGetDiscoveredDescriptorUuids(
+ discovered_services_index, i, characteristic))
+ log.info(descriptor_uuids)
+ for descriptor in descriptor_uuids:
+ log.info("descriptor to be written {}".format(
+ descriptor))
+ cen_droid.gattClientDescriptorSetValue(
+ bluetooth_gatt, discovered_services_index, i,
+ characteristic, descriptor, test_value)
+ cen_droid.gattClientWriteDescriptor(
+ bluetooth_gatt, discovered_services_index, i,
+ characteristic, descriptor)
+ expected_event = GattCbStrings.DESC_WRITE_REQ.value.format(
+ gatt_server_callback)
+ try:
+ event = per_ed.pop_event(expected_event,
+ default_timeout)
+ except Empty:
+ log.error(
+ GattCbErr.DESC_WRITE_REQ_ERR.value.format(
+ expected_event))
+ return False
+ request_id = event['data']['requestId']
+ found_value = event['data']['value']
+ if found_value != test_value:
+ log.error(
+ "Values didn't match. Found: {}, Expected: "
+ "{}".format(found_value, test_value))
+ per_droid.gattServerSendResponse(
+ gatt_server, bt_device_id, request_id, status,
+ offset, test_value_return)
+ expected_event = GattCbStrings.DESC_WRITE.value.format(
+ bluetooth_gatt)
+ try:
+ cen_ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.DESC_WRITE_ERR.value.format(
+ expected_event))
+ return False
+
+
+def setup_characteristics_and_descriptors(droid):
+ characteristic_input = [
+ {
+ 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
+ 'property': GattCharacteristic.PROPERTY_WRITE.value
+ | GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
+ 'permission': GattCharacteristic.PROPERTY_WRITE.value
+ },
+ {
+ 'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
+ },
+ {
+ 'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
+ },
+ ]
+ descriptor_input = [
+ {
+ 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
+ }, {
+ 'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattCharacteristic.PERMISSION_WRITE.value,
+ }
+ ]
+ characteristic_list = setup_gatt_characteristics(droid,
+ characteristic_input)
+ descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
+ return characteristic_list, descriptor_list
+
+
+def setup_multiple_services(per_ad):
+ per_droid, per_ed = per_ad.droid, per_ad.ed
+ gatt_server_callback = per_droid.gattServerCreateGattServerCallback()
+ gatt_server = per_droid.gattServerOpenGattServer(gatt_server_callback)
+ characteristic_list, descriptor_list = (
+ setup_characteristics_and_descriptors(per_droid))
+ per_droid.gattServerCharacteristicAddDescriptor(characteristic_list[1],
+ descriptor_list[0])
+ per_droid.gattServerCharacteristicAddDescriptor(characteristic_list[2],
+ descriptor_list[1])
+ gattService = per_droid.gattServerCreateService(
+ "00000000-0000-1000-8000-00805f9b34fb",
+ GattService.SERVICE_TYPE_PRIMARY.value)
+ gattService2 = per_droid.gattServerCreateService(
+ "FFFFFFFF-0000-1000-8000-00805f9b34fb",
+ GattService.SERVICE_TYPE_PRIMARY.value)
+ gattService3 = per_droid.gattServerCreateService(
+ "3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
+ GattService.SERVICE_TYPE_PRIMARY.value)
+ for characteristic in characteristic_list:
+ per_droid.gattServerAddCharacteristicToService(gattService,
+ characteristic)
+ per_droid.gattServerAddService(gatt_server, gattService)
+ expected_event = GattCbStrings.SERV_ADDED.value.format(
+ gatt_server_callback)
+ try:
+ per_ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.SERV_ADDED_ERR.value.format(expected_event))
+ return False
+ for characteristic in characteristic_list:
+ per_droid.gattServerAddCharacteristicToService(gattService2,
+ characteristic)
+ per_droid.gattServerAddService(gatt_server, gattService2)
+ try:
+ per_ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.SERV_ADDED_ERR.value.format(expected_event))
+ return False
+ for characteristic in characteristic_list:
+ per_droid.gattServerAddCharacteristicToService(gattService3,
+ characteristic)
+ per_droid.gattServerAddService(gatt_server, gattService3)
+ try:
+ per_ed.pop_event(expected_event, default_timeout)
+ except Empty:
+ log.error(GattCbErr.SERV_ADDED_ERR.value.format(expected_event))
+ return False
+ return gatt_server_callback, gatt_server
+
+
+def setup_characteristics_and_descriptors(droid):
+ characteristic_input = [
+ {
+ 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
+ 'property': GattCharacteristic.PROPERTY_WRITE.value
+ | GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
+ 'permission': GattCharacteristic.PROPERTY_WRITE.value
+ },
+ {
+ 'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
+ },
+ {
+ 'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
+ },
+ ]
+ descriptor_input = [
+ {
+ 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
+ }, {
+ 'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattCharacteristic.PERMISSION_WRITE.value,
+ }
+ ]
+ characteristic_list = setup_gatt_characteristics(droid,
+ characteristic_input)
+ descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
+ return characteristic_list, descriptor_list
+
+
+def setup_gatt_characteristics(droid, input):
+ characteristic_list = []
+ for item in input:
+ index = droid.gattServerCreateBluetoothGattCharacteristic(
+ item['uuid'], item['property'], item['permission'])
+ characteristic_list.append(index)
+ return characteristic_list
+
+
+def setup_gatt_descriptors(droid, input):
+ descriptor_list = []
+ for item in input:
+ index = droid.gattServerCreateBluetoothGattDescriptor(
+ item['uuid'],
+ item['property'], )
+ descriptor_list.append(index)
+ log.info("setup descriptor list: {}".format(descriptor_list))
+ return descriptor_list
diff --git a/acts/framework/acts/test_utils/bt/bt_test_utils.py b/acts/framework/acts/test_utils/bt/bt_test_utils.py
index 8c2501b..adf55a0 100644
--- a/acts/framework/acts/test_utils/bt/bt_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_test_utils.py
@@ -20,35 +20,41 @@
import queue
import threading
import time
+from acts import utils
from contextlib2 import suppress
+from subprocess import call
from acts.logger import LoggerProxy
-from acts.test_utils.bt.BleEnum import *
-from acts.test_utils.bt.BtEnum import *
+from acts.test_utils.bt.BleEnum import AdvertiseSettingsAdvertiseMode
+from acts.test_utils.bt.BleEnum import ScanSettingsCallbackType
+from acts.test_utils.bt.BleEnum import ScanSettingsMatchMode
+from acts.test_utils.bt.BleEnum import ScanSettingsMatchNum
+from acts.test_utils.bt.BleEnum import ScanSettingsScanResultType
+from acts.test_utils.bt.BleEnum import ScanSettingsScanMode
+from acts.test_utils.bt.BleEnum import ScanSettingsReportDelaySeconds
+from acts.test_utils.bt.BleEnum import AdvertiseSettingsAdvertiseType
+from acts.test_utils.bt.BleEnum import AdvertiseSettingsAdvertiseTxPower
+from acts.test_utils.bt.BleEnum import ScanSettingsMatchNum
+from acts.test_utils.bt.BleEnum import ScanSettingsScanResultType
+from acts.test_utils.bt.BleEnum import ScanSettingsScanMode
+from acts.test_utils.bt.BtEnum import BluetoothScanModeType
+from acts.test_utils.bt.BtEnum import RfcommUuid
from acts.utils import exe_cmd
-default_timeout = 10
+default_timeout = 15
# bt discovery timeout
default_discovery_timeout = 3
log = LoggerProxy()
# Callback strings
-characteristic_write_request = "GattServer{}onCharacteristicWriteRequest"
-characteristic_write = "GattConnect{}onCharacteristicWrite"
-descriptor_write_request = "GattServer{}onDescriptorWriteRequest"
-descriptor_write = "GattConnect{}onDescriptorWrite"
-read_remote_rssi = "GattConnect{}onReadRemoteRssi"
-gatt_services_discovered = "GattConnect{}onServicesDiscovered"
scan_result = "BleScan{}onScanResults"
scan_failed = "BleScan{}onScanFailed"
-service_added = "GattServer{}onServiceAdded"
batch_scan_result = "BleScan{}onBatchScanResult"
adv_fail = "BleAdvertise{}onFailure"
adv_succ = "BleAdvertise{}onSuccess"
bluetooth_off = "BluetoothStateChangedOff"
bluetooth_on = "BluetoothStateChangedOn"
-mtu_changed = "GattConnect{}onMtuChanged"
# rfcomm test uuids
rfcomm_secure_uuid = "fa87c0d0-afac-11de-8a39-0800200c9a66"
@@ -57,7 +63,7 @@
advertisements_to_devices = {
"Nexus 4": 0,
"Nexus 5": 0,
- "Nexus 5X":15,
+ "Nexus 5X": 15,
"Nexus 7": 0,
"Nexus Player": 1,
"Nexus 6": 4,
@@ -74,7 +80,7 @@
"AOSP on Shamu": 4,
"MSM8992 for arm64": 9,
"LG Watch Urbane": 1,
- "Pixel C":4,
+ "Pixel C": 4,
"angler": 4,
"bullhead": 15,
}
@@ -92,7 +98,7 @@
"Sprout": True,
"Micromax AQ4501": True,
"4560MMX": True,
- "Pixel C":True,
+ "Pixel C": True,
"G Watch R": True,
"Gear Live": True,
"SmartWatch 3": True,
@@ -151,8 +157,12 @@
settings = droid.bleBuildAdvertiseSettings()
return settings
+
def setup_multiple_devices_for_bt_test(android_devices):
log.info("Setting up Android Devices")
+ # TODO: Temp fix for an selinux error.
+ for ad in android_devices:
+ ad.adb.shell("setenforce 0")
threads = []
try:
for a in android_devices:
@@ -166,6 +176,7 @@
d = a.droid
setup_result = d.bluetoothSetLocalName(generate_id_by_size(4))
if not setup_result:
+ log.error("Failed to set device name.")
return setup_result
d.bluetoothDisableBLE()
bonded_devices = d.bluetoothGetBondedDevices()
@@ -174,8 +185,10 @@
for a in android_devices:
setup_result = a.droid.bluetoothConfigHciSnoopLog(True)
if not setup_result:
+ log.error("Failed to enable Bluetooth Hci Snoop Logging.")
return setup_result
- except Exception:
+ except Exception as err:
+ log.error("Something went wrong in multi device setup: {}".format(err))
return False
return setup_result
@@ -187,17 +200,16 @@
"""
for a in android_devices:
droid, ed = a.droid, a.ed
- log.info(
- "Reset state of bluetooth on device: {}".format(
- droid.getBuildSerial()))
+ log.info("Reset state of bluetooth on device: {}".format(
+ droid.getBuildSerial()))
if droid.bluetoothCheckState() is True:
droid.bluetoothToggleState(False)
expected_bluetooth_off_event_name = bluetooth_off
try:
- ed.pop_event(
- expected_bluetooth_off_event_name, default_timeout)
+ ed.pop_event(expected_bluetooth_off_event_name,
+ default_timeout)
except Exception:
- log.info("Failed to toggle Bluetooth off.")
+ log.error("Failed to toggle Bluetooth off.")
return False
# temp sleep for b/17723234
time.sleep(3)
@@ -206,7 +218,12 @@
try:
ed.pop_event(expected_bluetooth_on_event_name, default_timeout)
except Exception:
- log.info("Failed to toggle Bluetooth on.")
+ log.info("Failed to toggle Bluetooth on (no broadcast received).")
+ # Try one more time to poke at the actual state.
+ if droid.bluetoothCheckState() is True:
+ log.info(".. actual state is ON")
+ return True
+ log.info(".. actual state is OFF")
return False
return True
@@ -216,7 +233,7 @@
for a in android_devices:
d, e = a.droid, a.ed
model = d.getBuildModel()
- max_advertisements = 0
+ max_advertisements = 1
batch_scan_supported = True
if model in advertisements_to_devices.keys():
max_advertisements = advertisements_to_devices[model]
@@ -232,9 +249,10 @@
return droid_list
-def generate_id_by_size(size,
- chars=(string.ascii_lowercase +
- string.ascii_uppercase + string.digits)):
+def generate_id_by_size(
+ size,
+ chars=(
+ string.ascii_lowercase + string.ascii_uppercase + string.digits)):
return ''.join(random.choice(chars) for _ in range(size))
@@ -248,38 +266,21 @@
try:
for scan_callback in scan_callback_list:
scan_droid.bleStopBleScan(scan_callback)
- except Exception:
+ except Exception as err:
+ log.debug(
+ "Failed to stop LE scan... reseting Bluetooth. Error {}".format(
+ err))
reset_bluetooth([scn_android_device])
try:
for adv_callback in adv_callback_list:
adv_droid.bleStopBleAdvertising(adv_callback)
- except Exception:
+ except Exception as err:
+ log.debug(
+ "Failed to stop LE advertisement... reseting Bluetooth. Error {}".format(
+ err))
reset_bluetooth([adv_android_device])
-def setup_gatt_characteristics(droid, input):
- characteristic_list = []
- for item in input:
- index = droid.gattServerCreateBluetoothGattCharacteristic(
- item['uuid'],
- item['property'],
- item['permission'])
- characteristic_list.append(index)
- return characteristic_list
-
-
-def setup_gatt_descriptors(droid, input):
- descriptor_list = []
- for item in input:
- index = droid.gattServerCreateBluetoothGattDescriptor(
- item['uuid'],
- item['property'],
- )
- descriptor_list.append(index)
- log.info("setup descriptor list: {}".format(descriptor_list))
- return descriptor_list
-
-
def get_mac_address_of_generic_advertisement(scan_ad, adv_ad):
adv_ad.droid.bleSetAdvertiseDataIncludeDeviceName(True)
adv_ad.droid.bleSetAdvertiseSettingsAdvertiseMode(
@@ -289,15 +290,15 @@
AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_HIGH.value)
advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(adv_ad.droid))
- adv_ad.droid.bleStartBleAdvertising(
- advertise_callback, advertise_data, advertise_settings)
- adv_ad.ed.pop_event("BleAdvertise{}onSuccess".format(
- advertise_callback), default_timeout)
+ adv_ad.droid.bleStartBleAdvertising(advertise_callback, advertise_data,
+ advertise_settings)
+ adv_ad.ed.pop_event("BleAdvertise{}onSuccess".format(advertise_callback),
+ default_timeout)
filter_list = scan_ad.droid.bleGenFilterList()
scan_settings = scan_ad.droid.bleBuildScanSetting()
scan_callback = scan_ad.droid.bleGenScanCallback()
- scan_ad.droid.bleSetScanFilterDeviceName(adv_ad.droid
- .bluetoothGetLocalName())
+ scan_ad.droid.bleSetScanFilterDeviceName(
+ adv_ad.droid.bluetoothGetLocalName())
scan_ad.droid.bleBuildScanFilter(filter_list)
scan_ad.droid.bleStartBleScan(filter_list, scan_settings, scan_callback)
event = scan_ad.ed.pop_event(
@@ -307,222 +308,6 @@
return mac_address, advertise_callback
-def setup_gatt_connection(cen_ad, mac_address, autoconnect):
- test_result = True
- gatt_callback = cen_ad.droid.gattCreateGattCallback()
- log.info("Gatt Connect to mac address {}.".format(mac_address))
- bluetooth_gatt = cen_ad.droid.gattClientConnectGatt(
- gatt_callback, mac_address,
- autoconnect)
- event = cen_ad.ed.pop_event(
- "GattConnect{}onConnectionStateChange".format(gatt_callback),
- default_timeout)
- if event['data']['State'] != GattConnectionState.STATE_CONNECTED.value:
- log.info("Could not establish a connection to peripheral. Event "
- "Details:".format(pprint.pformat(event)))
- test_result = False
- # To avoid race condition of quick connect/disconnect
- time.sleep(1)
- return test_result, bluetooth_gatt, gatt_callback
-
-
-def disconnect_gatt_connection(cen_ad, bluetooth_gatt, gatt_callback):
- cen_ad.droid.gattClientDisconnect(bluetooth_gatt)
- event = cen_ad.ed.pop_event(
- "GattConnect{}onConnectionStateChange".format(gatt_callback),
- default_timeout)
- if event['data']['State'] != GattConnectionState.STATE_DISCONNECTED.value:
- return False
- return True
-
-
-def orchestrate_gatt_connection(cen_ad, per_ad, le=True, mac_address=None):
- adv_callback = None
- if mac_address is None:
- if le:
- mac_address, adv_callback = (
- get_mac_address_of_generic_advertisement(cen_ad, per_ad))
- else:
- mac_address = get_bt_mac_address(cen_ad.droid, per_ad.droid, le)
- adv_callback = None
- autoconnect = False
- test_result, bluetooth_gatt, gatt_callback = setup_gatt_connection(
- cen_ad, mac_address, autoconnect)
- if not test_result:
- log.info("Could not connect to peripheral.")
- return False
- return bluetooth_gatt, gatt_callback, adv_callback
-
-
-def run_continuous_write_descriptor(
- cen_droid, cen_ed, per_droid, per_ed, gatt_server, gatt_server_callback,
- bluetooth_gatt, services_count, discovered_services_index):
- log.info("starting continuous write")
- bt_device_id = 0
- status = 1
- offset = 1
- test_value = "1,2,3,4,5,6,7"
- test_value_return = "1,2,3"
- with suppress(Exception):
- for x in range(100000):
- for i in range(services_count):
- characteristic_uuids = (
- cen_droid.gattClientGetDiscoveredCharacteristicUuids(
- discovered_services_index, i))
- log.info(characteristic_uuids)
- for characteristic in characteristic_uuids:
- descriptor_uuids = (
- cen_droid.gattClientGetDiscoveredDescriptorUuids(
- discovered_services_index, i, characteristic))
- log.info(descriptor_uuids)
- for descriptor in descriptor_uuids:
- log.info(
- "descriptor to be written {}".format(descriptor))
- cen_droid.gattClientDescriptorSetValue(
- bluetooth_gatt, discovered_services_index,
- i, characteristic, descriptor, test_value)
- cen_droid.gattClientWriteDescriptor(
- bluetooth_gatt, discovered_services_index,
- i, characteristic, descriptor)
- event = per_ed.pop_event(
- descriptor_write_request.format(
- gatt_server_callback), default_timeout)
- log.info(
- "onDescriptorWriteRequest event found: {}".format(
- event))
- request_id = event['data']['requestId']
- found_value = event['data']['value']
- if found_value != test_value:
- log.info(
- "Values didn't match. Found: {}, Expected: "
- "{}".format(found_value, test_value))
- per_droid.gattServerSendResponse(
- gatt_server, bt_device_id, request_id, status,
- offset, test_value_return)
- log.info("onDescriptorWrite event found: {}".format(
- cen_ed.pop_event(
- descriptor_write.format(bluetooth_gatt),
- default_timeout)))
-
-
-def setup_characteristics_and_descriptors(droid):
- characteristic_input = [
- {
- 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattCharacteristic.PROPERTY_WRITE.value |
- BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
- 'permission': BluetoothGattCharacteristic.PROPERTY_WRITE.value
- },
- {
- 'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
- },
- {
- 'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
- },
- ]
- descriptor_input = [
- {
- 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattDescriptor.PERMISSION_WRITE.value,
- },
- {
- 'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattCharacteristic.PERMISSION_WRITE.value,
- }
- ]
- characteristic_list = setup_gatt_characteristics(
- droid, characteristic_input)
- descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
- return characteristic_list, descriptor_list
-
-
-def setup_multiple_services(per_ad):
- per_droid, per_ed = per_ad.droid, per_ad.ed
- gatt_server_callback = per_droid.gattServerCreateGattServerCallback()
- gatt_server = per_droid.gattServerOpenGattServer(gatt_server_callback)
- characteristic_list, descriptor_list = (
- setup_characteristics_and_descriptors(per_droid))
- per_droid.gattServerCharacteristicAddDescriptor(
- characteristic_list[1], descriptor_list[0])
- per_droid.gattServerCharacteristicAddDescriptor(
- characteristic_list[2], descriptor_list[1])
- gattService = per_droid.gattServerCreateService(
- "00000000-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
- gattService2 = per_droid.gattServerCreateService(
- "FFFFFFFF-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
- gattService3 = per_droid.gattServerCreateService(
- "3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
- for characteristic in characteristic_list:
- per_droid.gattServerAddCharacteristicToService(
- gattService, characteristic)
- per_droid.gattServerAddService(gatt_server, gattService)
- per_ed.pop_event(service_added.format(gatt_server_callback),
- default_timeout)
- for characteristic in characteristic_list:
- per_droid.gattServerAddCharacteristicToService(
- gattService2, characteristic)
- per_droid.gattServerAddService(gatt_server, gattService2)
- per_ed.pop_event(service_added.format(gatt_server_callback),
- default_timeout)
- for characteristic in characteristic_list:
- per_droid.gattServerAddCharacteristicToService(gattService3,
- characteristic)
- per_droid.gattServerAddService(gatt_server, gattService3)
- per_ed.pop_event(service_added.format(gatt_server_callback),
- default_timeout)
- return gatt_server_callback, gatt_server
-
-
-def setup_characteristics_and_descriptors(droid):
- characteristic_input = [
- {
- 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattCharacteristic.PROPERTY_WRITE.value |
- BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
- 'permission': BluetoothGattCharacteristic.PROPERTY_WRITE.value
- },
- {
- 'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
- },
- {
- 'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
- },
- ]
- descriptor_input = [
- {
- 'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattDescriptor.PERMISSION_WRITE.value,
- },
- {
- 'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattCharacteristic.PERMISSION_WRITE.value,
- }
- ]
- characteristic_list = setup_gatt_characteristics(
- droid, characteristic_input)
- descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
- return characteristic_list, descriptor_list
-
-
def get_device_local_info(droid):
local_info_dict = {}
local_info_dict['name'] = droid.bluetoothGetLocalName()
@@ -566,7 +351,7 @@
if scan_mode != scan_mode_value:
return False
elif (scan_mode_value ==
- BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value):
+ BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value):
droid.bluetoothMakeDiscoverable()
scan_mode = droid.bluetoothGetScanMode()
if scan_mode != scan_mode_value:
@@ -599,9 +384,8 @@
return_string = "{} Energy info collection:\n".format(state)
for d in droids:
with suppress(Exception):
- if (d.getBuildModel() == "Nexus 6" or d.getBuildModel() == "Nexus 9"
- or d.getBuildModel() == "Nexus 6P"
- or d.getBuildModel() == "Nexus5X"):
+ if (d.getBuildModel() != "Nexus 5" or
+ d.getBuildModel() != "Nexus 4"):
description = ("Device: {}\tEnergyStatus: {}\n".format(
d.getBuildSerial(),
@@ -614,54 +398,38 @@
# Enable discovery on sec_droid so that pri_droid can find it.
# The timeout here is based on how much time it would take for two devices
# to pair with each other once pri_droid starts seeing devices.
+ log.info(
+ "Bonding device {} to {}".format(pri_droid.bluetoothGetLocalAddress(),
+ sec_droid.bluetoothGetLocalAddress()))
sec_droid.bluetoothMakeDiscoverable(default_timeout)
- target_name = sec_droid.bluetoothGetLocalName()
+ target_address = sec_droid.bluetoothGetLocalAddress()
+ log.debug("Starting paring helper on each device")
pri_droid.bluetoothStartPairingHelper()
sec_droid.bluetoothStartPairingHelper()
- result = pri_droid.bluetoothDiscoverAndBond(target_name)
-
+ log.info("Primary device starting discovery and executing bond")
+ result = pri_droid.bluetoothDiscoverAndBond(target_address)
# Loop until we have bonded successfully or timeout.
end_time = time.time() + default_timeout
+ log.info("Verifying devices are bonded")
while time.time() < end_time:
bonded_devices = pri_droid.bluetoothGetBondedDevices()
- expected_address = sec_droid.bluetoothGetLocalAddress()
bonded = False
for d in bonded_devices:
- if d['address'] == expected_address:
- return True
+ if d['address'] == target_address:
+ log.info("Successfully bonded to device")
+ return True
time.sleep(1)
# Timed out trying to bond.
+ log.debug("Failed to bond devices.")
return False
-def get_bt_mac_address(droid, droid1, make_undisocverable=True):
- droid1.bluetoothMakeDiscoverable(default_timeout)
- droid.bluetoothStartDiscovery()
- mac = ""
- target_name = droid1.bluetoothGetLocalName()
- time.sleep(default_discovery_timeout)
- discovered_devices = droid.bluetoothGetDiscoveredDevices()
- for device in discovered_devices:
- if 'name' in device.keys() and target_name == device['name']:
- mac = device['address']
- continue
- if make_undisocverable:
- droid1.bluetoothMakeUndiscoverable()
- droid.bluetoothCancelDiscovery()
- if mac == "":
- return False
- return mac
-
-
-def get_client_server_bt_mac_address(droid, droid1):
- return get_bt_mac_address(droid, droid1), get_bt_mac_address(droid1, droid)
-
-
def take_btsnoop_logs(android_devices, testcase, testname):
for a in android_devices:
- take_btsnoop_log(a.droid, testcase, testname)
+ take_btsnoop_log(a, testcase, testname)
-def take_btsnoop_log(droid, testcase, test_name):
+
+def take_btsnoop_log(ad, testcase, test_name):
"""Grabs the btsnoop_hci log on a device and stores it in the log directory
of the test class.
@@ -675,21 +443,78 @@
"""
test_name = "".join(x for x in test_name if x.isalnum())
with suppress(Exception):
- serial = droid.getBuildSerial()
- device_model = droid.getBuildModel()
+ serial = ad.droid.getBuildSerial()
+ device_model = ad.droid.getBuildModel()
device_model = device_model.replace(" ", "")
out_name = ','.join((test_name, device_model, serial))
+ snoop_path = ad.log_path + "/BluetoothSnoopLogs"
+ utils.create_dir(snoop_path)
cmd = ''.join(("adb -s ", serial, " pull /sdcard/btsnoop_hci.log ",
- testcase.log_path + "/" + out_name,
- ".btsnoop_hci.log"))
+ snoop_path + '/' + out_name, ".btsnoop_hci.log"))
testcase.log.info("Test failed, grabbing the bt_snoop logs on {} {}."
.format(device_model, serial))
exe_cmd(cmd)
-def rfcomm_connect(droid, device_address):
- droid.bluetoothRfcommConnect(device_address)
+def kill_bluetooth_process(ad):
+ log.info("Killing Bluetooth process.")
+ pid = ad.adb.shell(
+ "ps | grep com.android.bluetooth | awk '{print $2}'").decode('ascii')
+ call(["adb -s " + ad.serial + " shell kill " + pid],
+ shell=True)
-def rfcomm_accept(droid):
- droid.bluetoothRfcommAccept()
+def rfcomm_connect(ad, device_address):
+ rf_client_ad = ad
+ log.debug("Performing RFCOMM connection to {}".format(device_address))
+ try:
+ ad.droid.bluetoothRfcommConnect(device_address)
+ except Exception as err:
+ log.error("Failed to connect: {}".format(err))
+ ad.droid.bluetoothRfcommCloseSocket()
+ return
+ finally:
+ return
+ return
+
+
+def rfcomm_accept(ad):
+ rf_server_ad = ad
+ log.debug("Performing RFCOMM accept")
+ try:
+ ad.droid.bluetoothRfcommAccept(RfcommUuid.DEFAULT_UUID.value,
+ default_timeout)
+ except Exception as err:
+ log.error("Failed to accept: {}".format(err))
+ ad.droid.bluetoothRfcommCloseSocket()
+ return
+ finally:
+ return
+ return
+
+
+def write_read_verify_data(client_ad, server_ad, msg, binary=False):
+ log.info("Write message.")
+ try:
+ if binary:
+ client_ad.droid.bluetoothRfcommWriteBinary(msg)
+ else:
+ client_ad.droid.bluetoothRfcommWrite(msg)
+ except Exception as err:
+ log.error("Failed to write data: {}".format(err))
+ return False
+ log.info("Read message.")
+ try:
+ if binary:
+ read_msg = server_ad.droid.bluetoothRfcommReadBinary().rstrip("\r\n")
+ else:
+ read_msg = server_ad.droid.bluetoothRfcommRead()
+ except Exception as err:
+ log.error("Failed to read data: {}".format(err))
+ return False
+ log.info("Verify message.")
+ if msg != read_msg:
+ log.error("Mismatch! Read: {}, Expected: {}".format(
+ read_msg, msg))
+ return False
+ return True
diff --git a/acts/framework/acts/test_utils/bt/native_bt_test_utils.py b/acts/framework/acts/test_utils/bt/native_bt_test_utils.py
index f4623c6..341862f 100644
--- a/acts/framework/acts/test_utils/bt/native_bt_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/native_bt_test_utils.py
@@ -15,12 +15,24 @@
# the License.
from acts.logger import LoggerProxy
+from subprocess import call
+import time
log = LoggerProxy()
def setup_native_bluetooth(native_devices):
- for n in native_devices:
- droid = n.droid
- droid.BluetoothBinderInitInterface()
- droid.BluetoothBinderEnable()
- droid.BluetoothBinderRegisterBLE()
+ for n in native_devices:
+ droid = n.droid
+ pid = n.adb.shell("ps | grep bluetoothtbd | awk '{print $2}'").decode(
+ 'ascii')
+ if not pid:
+ call(
+ ["adb -s " + n.serial + " shell sh -c \"bluetoothtbd\" &"],
+ shell=True)
+ droid.BluetoothBinderInitInterface()
+ time.sleep(5) #temporary sleep statement
+ droid.BluetoothBinderEnable()
+ time.sleep(5) #temporary sleep statement
+ droid.BluetoothBinderRegisterBLE()
+ time.sleep(5) #temporary sleep statement
+
diff --git a/acts/framework/tests/Sl4aSanityTest.py b/acts/framework/tests/Sl4aSanityTest.py
index 9214639..2f5add6 100644
--- a/acts/framework/tests/Sl4aSanityTest.py
+++ b/acts/framework/tests/Sl4aSanityTest.py
@@ -49,7 +49,8 @@
return True
def test_message_then_shutdown_stress(self):
+ ad = self.android_devices[0]
for i in range(10):
- assert wifi_toggle_state(self.droid, self.ed, False)
- assert wifi_toggle_state(self.droid, self.ed, True)
+ assert wifi_toggle_state(ad.droid, ad.ed, False)
+ assert wifi_toggle_state(ad.droid, ad.ed, True)
return True
diff --git a/acts/tests/google/ble/api/BleAdvertiseApiTest.py b/acts/tests/google/ble/api/BleAdvertiseApiTest.py
index fd4429a..207f877 100644
--- a/acts/tests/google/ble/api/BleAdvertiseApiTest.py
+++ b/acts/tests/google/ble/api/BleAdvertiseApiTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See thea
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to exercise Ble Advertisement Api's. This exercises all getters and
setters. This is important since there is a builder object that is immutable
@@ -32,51 +31,14 @@
class BleAdvertiseVerificationError(Exception):
-
"""Error in fetsching BleScanner Advertise result."""
class BleAdvertiseApiTest(BluetoothBaseTest):
- tests = None
-
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
self.droid_list = get_advanced_droid_list(self.android_devices)
self.droid = self.android_devices[0].droid
- self.tests = (
- "test_adv_settings_defaults",
- "test_adv_data_defaults",
- "test_adv_settings_set_adv_mode_balanced",
- "test_adv_settings_set_adv_mode_low_power",
- "test_adv_settings_set_adv_mode_low_latency",
- "test_adv_settings_set_invalid_adv_mode",
- "test_adv_settings_set_adv_tx_power_level_high",
- "test_adv_settings_set_adv_tx_power_level_medium",
- "test_adv_settings_set_adv_tx_power_level_low",
- "test_adv_settings_set_adv_tx_power_level_ultra_low",
- "test_adv_settings_set_invalid_adv_tx_power_level",
- "test_adv_settings_set_is_connectable_true",
- "test_adv_settings_set_is_connectable_false",
- "test_adv_data_set_service_uuids_empty",
- "test_adv_data_set_service_uuids_single",
- "test_adv_data_set_service_uuids_multiple",
- "test_adv_data_set_service_uuids_invalid_uuid",
- "test_adv_data_set_service_data",
- "test_adv_data_set_service_data_invalid_service_data",
- "test_adv_data_set_service_data_invalid_service_data_uuid",
- "test_adv_data_set_manu_id",
- "test_adv_data_set_manu_id_invalid_manu_id",
- "test_adv_data_set_manu_id_invalid_manu_specific_data",
- "test_adv_data_set_manu_id_max",
- "test_adv_data_set_include_tx_power_level_true",
- "test_adv_data_set_include_tx_power_level_false",
- "test_adv_data_set_include_device_name_true",
- "test_adv_data_set_include_device_name_false",
- )
-
- if self.droid_list[0]['max_advertisements'] > 0:
- self.tests = self.tests + (
- "test_advertisement_greater_than_31_bytes",)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_defaults(self):
@@ -115,18 +77,18 @@
if adv_mode != exp_adv_mode:
test_result = False
self.log.debug("exp filtering mode: {},"
- " found filtering mode: {}".
- format(exp_adv_mode, adv_mode))
+ " found filtering mode: {}".format(exp_adv_mode,
+ adv_mode))
if tx_power_level != exp_tx_power_level:
test_result = False
self.log.debug("exp tx power level: {},"
- " found filtering tx power level: {}".
- format(exp_tx_power_level, tx_power_level))
+ " found filtering tx power level: {}".format(
+ exp_tx_power_level, tx_power_level))
if exp_is_connectable != is_connectable:
test_result = False
self.log.debug("exp is connectable: {},"
- " found filtering is connectable: {}".
- format(exp_is_connectable, is_connectable))
+ " found filtering is connectable: {}".format(
+ exp_is_connectable, is_connectable))
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -167,20 +129,20 @@
if service_uuids != exp_service_uuids:
test_result = False
self.log.debug("exp filtering service uuids: {},"
- " found filtering service uuids: {}".
- format(exp_service_uuids, service_uuids))
+ " found filtering service uuids: {}".format(
+ exp_service_uuids, service_uuids))
if include_tx_power_level != exp_include_tx_power_level:
test_result = False
- self.log.debug("exp filtering include tx power level:: {},"
- " found filtering include tx power level: {}".
- format(exp_include_tx_power_level,
- include_tx_power_level))
+ self.log.debug(
+ "exp filtering include tx power level:: {},"
+ " found filtering include tx power level: {}".format(
+ exp_include_tx_power_level, include_tx_power_level))
if include_device_name != exp_include_device_name:
test_result = False
- self.log.debug("exp filtering include tx power level: {},"
- " found filtering include tx power level: {}".
- format(exp_include_device_name,
- include_device_name))
+ self.log.debug(
+ "exp filtering include tx power level: {},"
+ " found filtering include tx power level: {}".format(
+ exp_include_device_name, include_device_name))
if not test_result:
self.log.debug("Some values didn't match the defaults.")
else:
@@ -214,10 +176,9 @@
droid = self.droid
exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_BALANCED.value
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_adv_mode))
- return self.verify_adv_settings_adv_mode(droid,
- exp_adv_mode)
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_adv_mode))
+ return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_mode_low_power(self):
@@ -246,10 +207,9 @@
droid = self.droid
exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_POWER.value
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_adv_mode))
- return self.verify_adv_settings_adv_mode(droid,
- exp_adv_mode)
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_adv_mode))
+ return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_mode_low_latency(self):
@@ -278,10 +238,9 @@
droid = self.droid
exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_adv_mode))
- return self.verify_adv_settings_adv_mode(droid,
- exp_adv_mode)
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_adv_mode))
+ return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_invalid_adv_mode(self):
@@ -308,8 +267,7 @@
droid = self.droid
exp_adv_mode = -1
self.log.debug("Step 2: Set the filtering mode to -1")
- return self.verify_invalid_adv_settings_adv_mode(droid,
- exp_adv_mode)
+ return self.verify_invalid_adv_settings_adv_mode(droid, exp_adv_mode)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_tx_power_level_high(self):
@@ -336,13 +294,12 @@
"""
self.log.debug("Step 1: Setup environment.")
droid = self.droid
- exp_adv_tx_power = (AdvertiseSettingsAdvertiseTxPower
- .ADVERTISE_TX_POWER_HIGH.value)
+ exp_adv_tx_power = (
+ AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_HIGH.value)
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_adv_tx_power))
- return self.verify_adv_settings_tx_power_level(droid,
- exp_adv_tx_power)
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_adv_tx_power))
+ return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_tx_power_level_medium(self):
@@ -370,13 +327,12 @@
self.log.debug("Step 1: Setup environment.")
test_result = True
droid = self.droid
- exp_adv_tx_power = (AdvertiseSettingsAdvertiseTxPower
- .ADVERTISE_TX_POWER_MEDIUM.value)
+ exp_adv_tx_power = (
+ AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_MEDIUM.value)
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_adv_tx_power))
- return self.verify_adv_settings_tx_power_level(droid,
- exp_adv_tx_power)
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_adv_tx_power))
+ return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_tx_power_level_low(self):
@@ -403,13 +359,12 @@
"""
self.log.debug("Step 1: Setup environment.")
droid = self.droid
- exp_adv_tx_power = (AdvertiseSettingsAdvertiseTxPower
- .ADVERTISE_TX_POWER_LOW.value)
+ exp_adv_tx_power = (
+ AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_LOW.value)
self.log.debug(
- "Step 2: Set the filtering settings object's value to ".
- format(exp_adv_tx_power))
- return self.verify_adv_settings_tx_power_level(droid,
- exp_adv_tx_power)
+ "Step 2: Set the filtering settings object's value to ".format(
+ exp_adv_tx_power))
+ return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_adv_tx_power_level_ultra_low(self):
@@ -436,13 +391,13 @@
"""
self.log.debug("Step 1: Setup environment.")
droid = self.droid
- exp_adv_tx_power = (AdvertiseSettingsAdvertiseTxPower
- .ADVERTISE_TX_POWER_ULTRA_LOW.value)
+ exp_adv_tx_power = (
+ AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_ULTRA_LOW.
+ value)
self.log.debug(
- "Step 2: Set the filtering settings object's value to ".
- format(exp_adv_tx_power))
- return self.verify_adv_settings_tx_power_level(droid,
- exp_adv_tx_power)
+ "Step 2: Set the filtering settings object's value to ".format(
+ exp_adv_tx_power))
+ return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_invalid_adv_tx_power_level(self):
@@ -469,8 +424,8 @@
droid = self.droid
exp_adv_tx_power = -1
self.log.debug("Step 2: Set the filtering mode to -1")
- return self.verify_invalid_adv_settings_tx_power_level(droid,
- exp_adv_tx_power)
+ return self.verify_invalid_adv_settings_tx_power_level(
+ droid, exp_adv_tx_power)
@BluetoothBaseTest.bt_test_wrap
def test_adv_settings_set_is_connectable_true(self):
@@ -499,8 +454,8 @@
droid = self.droid
exp_is_connectable = True
self.log.debug(
- "Step 2: Set the filtering settings object's value to {}".
- format(exp_is_connectable))
+ "Step 2: Set the filtering settings object's value to {}".format(
+ exp_is_connectable))
return self.verify_adv_settings_is_connectable(droid,
exp_is_connectable)
@@ -530,9 +485,8 @@
self.log.debug("Step 1: Setup environment.")
droid = self.droid
exp_is_connectable = False
- self.log.debug(
- "Step 2: Set the filtering settings object's value to " + str(
- exp_is_connectable))
+ self.log.debug("Step 2: Set the filtering settings object's value to "
+ + str(exp_is_connectable))
return self.verify_adv_settings_is_connectable(droid,
exp_is_connectable)
@@ -562,11 +516,9 @@
self.log.debug("Step 1: Setup environment.")
droid = self.droid
exp_service_uuids = []
- self.log.debug(
- "Step 2: Set the filtering data object's value to " + str(
- exp_service_uuids))
- return self.verify_adv_data_service_uuids(droid,
- exp_service_uuids)
+ self.log.debug("Step 2: Set the filtering data object's value to " +
+ str(exp_service_uuids))
+ return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_service_uuids_single(self):
@@ -594,11 +546,9 @@
self.log.debug("Step 1: Setup environment.")
droid = self.droid
exp_service_uuids = ["00000000-0000-1000-8000-00805f9b34fb"]
- self.log.debug(
- "Step 2: Set the filtering data object's value to " + str(
- exp_service_uuids))
- return self.verify_adv_data_service_uuids(droid,
- exp_service_uuids)
+ self.log.debug("Step 2: Set the filtering data object's value to " +
+ str(exp_service_uuids))
+ return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_service_uuids_multiple(self):
@@ -627,11 +577,9 @@
droid = self.droid
exp_service_uuids = ["00000000-0000-1000-8000-00805f9b34fb",
"00000000-0000-1000-8000-00805f9b34fb"]
- self.log.debug(
- "Step 2: Set the filtering data object's value to " + str(
- exp_service_uuids))
- return self.verify_adv_data_service_uuids(droid,
- exp_service_uuids)
+ self.log.debug("Step 2: Set the filtering data object's value to " +
+ str(exp_service_uuids))
+ return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_service_uuids_invalid_uuid(self):
@@ -657,9 +605,8 @@
self.log.debug("Step 1: Setup environment.")
droid = self.droid
exp_service_uuids = ["0"]
- self.log.debug(
- "Step 2: Set the filtering data service uuids to " + str(
- exp_service_uuids))
+ self.log.debug("Step 2: Set the filtering data service uuids to " +
+ str(exp_service_uuids))
return self.verify_invalid_adv_data_service_uuids(droid,
exp_service_uuids)
@@ -693,8 +640,7 @@
self.log.debug(
"Step 2: Set the filtering data object's service data uuid to: {}, "
"service data: {}".format(exp_service_data_uuid, exp_service_data))
- return self.verify_adv_data_service_data(droid,
- exp_service_data_uuid,
+ return self.verify_adv_data_service_data(droid, exp_service_data_uuid,
exp_service_data)
@BluetoothBaseTest.bt_test_wrap
@@ -727,9 +673,8 @@
self.log.debug(
"Step 2: Set the filtering data object's service data uuid to: {}, "
"service data: {}".format(exp_service_data_uuid, exp_service_data))
- return self.verify_invalid_adv_data_service_data(droid,
- exp_service_data_uuid,
- exp_service_data)
+ return self.verify_invalid_adv_data_service_data(
+ droid, exp_service_data_uuid, exp_service_data)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_service_data_invalid_service_data_uuid(self):
@@ -761,9 +706,8 @@
self.log.debug(
"Step 2: Set the filtering data object's service data uuid to: {}, "
"service data: {}".format(exp_service_data_uuid, exp_service_data))
- return self.verify_invalid_adv_data_service_data(droid,
- exp_service_data_uuid,
- exp_service_data)
+ return self.verify_invalid_adv_data_service_data(
+ droid, exp_service_data_uuid, exp_service_data)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_manu_id(self):
@@ -796,8 +740,7 @@
"Step 2: Set the filtering data object's service data manu id: {}"
", manu specific data: {}".format(exp_manu_id,
exp_manu_specific_data))
- return self.verify_adv_data_manu_id(droid,
- exp_manu_id,
+ return self.verify_adv_data_manu_id(droid, exp_manu_id,
exp_manu_specific_data)
@BluetoothBaseTest.bt_test_wrap
@@ -830,8 +773,7 @@
"Step 2: Set the filtering data object's service data manu id: {}"
", manu specific data: {}".format(exp_manu_id,
exp_manu_specific_data))
- return self.verify_invalid_adv_data_manu_id(droid,
- exp_manu_id,
+ return self.verify_invalid_adv_data_manu_id(droid, exp_manu_id,
exp_manu_specific_data)
@BluetoothBaseTest.bt_test_wrap
@@ -864,8 +806,7 @@
"Step 2: Set the filtering data object's service data manu id: {}"
", manu specific data: {}".format(exp_manu_id,
exp_manu_specific_data))
- return self.verify_invalid_adv_data_manu_id(droid,
- exp_manu_id,
+ return self.verify_invalid_adv_data_manu_id(droid, exp_manu_id,
exp_manu_specific_data)
@BluetoothBaseTest.bt_test_wrap
@@ -897,10 +838,9 @@
exp_manu_specific_data = "1,2,3"
self.log.debug(
"Step 2: Set the filtering data object's service data manu id: {}"
- ", manu specific data: {}".
- format(exp_manu_id, exp_manu_specific_data))
- return self.verify_adv_data_manu_id(droid,
- exp_manu_id,
+ ", manu specific data: {}".format(exp_manu_id,
+ exp_manu_specific_data))
+ return self.verify_adv_data_manu_id(droid, exp_manu_id,
exp_manu_specific_data)
@BluetoothBaseTest.bt_test_wrap
@@ -965,7 +905,7 @@
"Step 2: Set the filtering data object's include tx power level: {}"
.format(exp_include_tx_power_level))
return self.verify_adv_data_include_tx_power_level(
- droid , exp_include_tx_power_level)
+ droid, exp_include_tx_power_level)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_include_device_name_true(self):
@@ -996,8 +936,8 @@
self.log.debug(
"Step 2: Set the filtering data object's include device name: {}"
.format(exp_include_device_name))
- return self.verify_adv_data_include_device_name(droid,
- exp_include_device_name)
+ return self.verify_adv_data_include_device_name(
+ droid, exp_include_device_name)
@BluetoothBaseTest.bt_test_wrap
def test_adv_data_set_include_device_name_false(self):
@@ -1027,10 +967,10 @@
droid = self.droid
exp_include_device_name = False
self.log.debug(
- "Step 2: Set the filtering data object's include device name: {}".
- format(exp_include_device_name))
- return self.verify_adv_data_include_device_name(droid,
- exp_include_device_name)
+ "Step 2: Set the filtering data object's include device name: {}".format(
+ exp_include_device_name))
+ return self.verify_adv_data_include_device_name(
+ droid, exp_include_device_name)
@BluetoothBaseTest.bt_test_wrap
def test_advertisement_greater_than_31_bytes(self):
@@ -1056,22 +996,21 @@
"""
test_result = True
droid = self.droid
- ed = self.ed
+ ed = self.android_devices[0].ed
service_data = []
for i in range(25):
service_data.append(i)
droid.bleAddAdvertiseDataServiceData(
- "0000110D-0000-1000-8000-00805F9B34FB", ','.join(
- map(str, service_data)))
+ "0000110D-0000-1000-8000-00805F9B34FB",
+ ','.join(map(str, service_data)))
advcallback, adv_data, adv_settings = generate_ble_advertise_objects(
droid)
- droid.bleStartBleAdvertising(advcallback, adv_data,
- adv_settings)
+ droid.bleStartBleAdvertising(advcallback, adv_data, adv_settings)
try:
ed.pop_event(adv_fail.format(advcallback))
except SL4AAPIError:
- self.log.info("{} event was not found.".format(
- adv_fail.format(advcallback)))
+ self.log.info("{} event was not found.".format(adv_fail.format(
+ advcallback)))
return False
return test_result
@@ -1086,8 +1025,8 @@
self.log.debug("Step 4: Get the filtering setting's filtering mode.")
adv_mode = droid.bleGetAdvertiseSettingsMode(settings_index)
if exp_adv_mode is not adv_mode:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_adv_mode, adv_mode))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_adv_mode, adv_mode))
return False
self.log.debug("Advertise Setting's filtering mode {} value "
"test Passed.".format(exp_adv_mode))
@@ -1095,8 +1034,7 @@
def verify_adv_settings_tx_power_level(self, droid, exp_adv_tx_power):
try:
- droid.bleSetAdvertiseSettingsTxPowerLevel(
- exp_adv_tx_power)
+ droid.bleSetAdvertiseSettingsTxPowerLevel(exp_adv_tx_power)
except BleAdvertiseVerificationError as error:
self.log.debug(str(error))
return False
@@ -1106,15 +1044,14 @@
adv_tx_power_level = droid.bleGetAdvertiseSettingsTxPowerLevel(
settings_index)
if exp_adv_tx_power is not adv_tx_power_level:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_adv_tx_power, adv_tx_power_level))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_adv_tx_power, adv_tx_power_level))
return False
self.log.debug("Advertise Setting's tx power level {}"
" value test Passed.".format(exp_adv_tx_power))
return True
- def verify_adv_settings_is_connectable(self, droid,
- exp_is_connectable):
+ def verify_adv_settings_is_connectable(self, droid, exp_is_connectable):
try:
droid.bleSetAdvertiseSettingsIsConnectable(exp_is_connectable)
except BleAdvertiseVerificationError as error:
@@ -1127,8 +1064,8 @@
is_connectable = droid.bleGetAdvertiseSettingsIsConnectable(
settings_index)
if exp_is_connectable is not is_connectable:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_is_connectable, is_connectable))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_is_connectable, is_connectable))
return False
self.log.debug("Advertise Setting's is connectable {}"
" value test Passed.".format(exp_is_connectable))
@@ -1145,19 +1082,19 @@
self.log.debug("Step 4: Get the filtering data's service uuids.")
service_uuids = droid.bleGetAdvertiseDataServiceUuids(data_index)
if exp_service_uuids != service_uuids:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_service_uuids, service_uuids))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_service_uuids, service_uuids))
return False
- self.log.debug("Advertise Data's service uuids {}, value test Passed.".
- format(exp_service_uuids))
+ self.log.debug(
+ "Advertise Data's service uuids {}, value test Passed.".format(
+ exp_service_uuids))
return True
- def verify_adv_data_service_data(
- self, droid, exp_service_data_uuid,
- exp_service_data):
+ def verify_adv_data_service_data(self, droid, exp_service_data_uuid,
+ exp_service_data):
try:
- droid.bleAddAdvertiseDataServiceData(
- exp_service_data_uuid, exp_service_data)
+ droid.bleAddAdvertiseDataServiceData(exp_service_data_uuid,
+ exp_service_data)
except BleAdvertiseVerificationError as error:
self.log.debug(str(error))
return False
@@ -1167,17 +1104,16 @@
service_data = droid.bleGetAdvertiseDataServiceData(
data_index, exp_service_data_uuid)
if exp_service_data != service_data:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_service_data, service_data))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_service_data, service_data))
return False
self.log.debug("Advertise Data's service data uuid: {}, service data: "
"{}, value test Passed.".format(exp_service_data_uuid,
exp_service_data))
return True
- def verify_adv_data_manu_id(
- self, droid, exp_manu_id,
- exp_manu_specific_data):
+ def verify_adv_data_manu_id(self, droid, exp_manu_id,
+ exp_manu_specific_data):
try:
droid.bleAddAdvertiseDataManufacturerId(exp_manu_id,
exp_manu_specific_data)
@@ -1186,18 +1122,16 @@
return False
self.log.debug("Step 3: Get a filtering data object's index.")
data_index = droid.bleBuildAdvertiseData()
- self.log.debug(
- "Step 5: Get the filtering data's manu specific data.")
+ self.log.debug("Step 5: Get the filtering data's manu specific data.")
manu_specific_data = droid.bleGetAdvertiseDataManufacturerSpecificData(
data_index, exp_manu_id)
if exp_manu_specific_data != manu_specific_data:
- self.log.debug("exp value: " + str(exp_manu_specific_data)
- + ", Actual value: " + str(manu_specific_data))
+ self.log.debug("exp value: " + str(exp_manu_specific_data) +
+ ", Actual value: " + str(manu_specific_data))
return False
- self.log.debug("Advertise Data's manu id: " + str(
- exp_manu_id) + ", manu's specific data: " + str(
- exp_manu_specific_data)
- + " value test Passed.")
+ self.log.debug("Advertise Data's manu id: " + str(exp_manu_id) +
+ ", manu's specific data: " + str(
+ exp_manu_specific_data) + " value test Passed.")
return True
def verify_adv_data_include_tx_power_level(self, droid,
@@ -1215,20 +1149,17 @@
include_tx_power_level = droid.bleGetAdvertiseDataIncludeTxPowerLevel(
data_index)
if exp_include_tx_power_level is not include_tx_power_level:
- self.log.debug("exp value: " + str(exp_include_tx_power_level)
- + ", Actual value: " + str(include_tx_power_level))
+ self.log.debug("exp value: " + str(exp_include_tx_power_level) +
+ ", Actual value: " + str(include_tx_power_level))
return False
- self.log.debug(
- "Advertise Setting's include tx power level " +
- str(exp_include_tx_power_level)
- + " value test Passed.")
+ self.log.debug("Advertise Setting's include tx power level " + str(
+ exp_include_tx_power_level) + " value test Passed.")
return True
def verify_adv_data_include_device_name(self, droid,
exp_include_device_name):
try:
- droid.bleSetAdvertiseDataIncludeDeviceName(
- exp_include_device_name)
+ droid.bleSetAdvertiseDataIncludeDeviceName(exp_include_device_name)
except BleAdvertiseVerificationError as error:
self.log.debug(str(error))
return False
@@ -1238,16 +1169,14 @@
include_device_name = droid.bleGetAdvertiseDataIncludeDeviceName(
data_index)
if exp_include_device_name is not include_device_name:
- self.log.debug("exp value: {}, Actual value: {}".
- format(exp_include_device_name, include_device_name))
+ self.log.debug("exp value: {}, Actual value: {}".format(
+ exp_include_device_name, include_device_name))
return False
- self.log.debug(
- "Advertise Setting's include device name {}"
- " value test Passed.".format(exp_include_device_name))
+ self.log.debug("Advertise Setting's include device name {}"
+ " value test Passed.".format(exp_include_device_name))
return True
- def verify_invalid_adv_settings_adv_mode(self, droid,
- exp_adv_mode):
+ def verify_invalid_adv_settings_adv_mode(self, droid, exp_adv_mode):
try:
droid.bleSetAdvertiseSettingsAdvertiseMode(exp_adv_mode)
droid.bleBuildAdvertiseSettings()
@@ -1256,68 +1185,65 @@
return False
except SL4AAPIError:
self.log.debug("Set Advertise settings invalid filtering mode "
- "failed successfully with input as {}".
- format(exp_adv_mode))
+ "failed successfully with input as {}".format(
+ exp_adv_mode))
return True
def verify_invalid_adv_settings_tx_power_level(self, droid,
exp_adv_tx_power):
try:
- droid.bleSetAdvertiseSettingsTxPowerLevel(
- exp_adv_tx_power)
+ droid.bleSetAdvertiseSettingsTxPowerLevel(exp_adv_tx_power)
droid.bleBuildAdvertiseSettings()
- self.log.debug("Set Advertise settings invalid tx power level "
- + " with input as {}".format(exp_adv_tx_power))
+ self.log.debug("Set Advertise settings invalid tx power level " +
+ " with input as {}".format(exp_adv_tx_power))
return False
except SL4AAPIError:
self.log.debug("Set Advertise settings invalid tx power level "
- "failed successfullywith input as {}".
- format(exp_adv_tx_power))
+ "failed successfullywith input as {}".format(
+ exp_adv_tx_power))
return True
- def verify_invalid_adv_data_service_uuids(self, droid,
- exp_service_uuids):
+ def verify_invalid_adv_data_service_uuids(self, droid, exp_service_uuids):
try:
droid.bleSetAdvertiseDataSetServiceUuids(exp_service_uuids)
droid.bleBuildAdvertiseData()
- self.log.debug("Set Advertise Data service uuids "
- + " with input as {}".format(exp_service_uuids))
+ self.log.debug("Set Advertise Data service uuids " +
+ " with input as {}".format(exp_service_uuids))
return False
except SL4AAPIError:
self.log.debug("Set Advertise Data invalid service uuids failed "
- "successfully with input as {}".
- format(exp_service_uuids))
+ "successfully with input as {}".format(
+ exp_service_uuids))
return True
- def verify_invalid_adv_data_service_data(self, droid,
- exp_service_data_uuid,
- exp_service_data):
+ def verify_invalid_adv_data_service_data(
+ self, droid, exp_service_data_uuid, exp_service_data):
try:
- droid.bleAddAdvertiseDataServiceData(
- exp_service_data_uuid, exp_service_data)
+ droid.bleAddAdvertiseDataServiceData(exp_service_data_uuid,
+ exp_service_data)
droid.bleBuildAdvertiseData()
self.log.debug("Set Advertise Data service data uuid: {},"
- ", service data: {}".
- format(exp_service_data_uuid, exp_service_data))
+ ", service data: {}".format(exp_service_data_uuid,
+ exp_service_data))
return False
except SL4AAPIError:
self.log.debug("Set Advertise Data service data uuid: " + str(
- exp_service_data_uuid) + ", service data: " + str(
- exp_service_data) + " failed successfully.")
+ exp_service_data_uuid) + ", service data: " + str(
+ exp_service_data) + " failed successfully.")
return True
def verify_invalid_adv_data_manu_id(self, droid, exp_manu_id,
exp_manu_specific_data):
try:
droid.bleAddAdvertiseDataManufacturerId(exp_manu_id,
- exp_manu_specific_data)
+ exp_manu_specific_data)
droid.bleBuildAdvertiseData()
- self.log.debug("Set Advertise Data manu id: " + str(
- exp_manu_id) + ", manu specific data: " + str(
- exp_manu_specific_data))
+ self.log.debug("Set Advertise Data manu id: " + str(exp_manu_id) +
+ ", manu specific data: " + str(
+ exp_manu_specific_data))
return False
except SL4AAPIError:
self.log.debug("Set Advertise Data manu id: {},"
- " manu specific data: {},".
- format(exp_manu_id, exp_manu_specific_data))
+ " manu specific data: {},".format(
+ exp_manu_id, exp_manu_specific_data))
return True
diff --git a/acts/tests/google/ble/api/BleScanApiTest.py b/acts/tests/google/ble/api/BleScanApiTest.py
index 5cbb5f8..bb93cd8 100644
--- a/acts/tests/google/ble/api/BleScanApiTest.py
+++ b/acts/tests/google/ble/api/BleScanApiTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to exercise Ble Scan Api's. This exercises all getters and
setters. This is important since there is a builder object that is immutable
@@ -31,71 +30,26 @@
class BleScanResultsError(Exception):
-
"""Error in getting scan results"""
class BleScanVerificationError(Exception):
-
"""Error in comparing BleScan results"""
class BleSetScanSettingsError(Exception):
-
"""Error in setting Ble Scan Settings"""
class BleSetScanFilterError(Exception):
-
"""Error in setting Ble Scan Settings"""
class BleScanApiTest(BluetoothBaseTest):
- tests = None
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
self.droid = self.android_devices[0].droid
- self.tests = (
- "test_start_ble_scan_with_default_settings",
- "test_stop_ble_scan_default_settings",
- "test_scan_settings_callback_type_all_matches",
- "test_scan_settings_set_callback_type_first_match",
- "test_scan_settings_set_callback_type_match_lost",
- "test_scan_settings_set_invalid_callback_type",
- "test_scan_settings_set_scan_mode_low_power",
- "test_scan_settings_set_scan_mode_balanced",
- "test_scan_settings_set_scan_mode_low_latency",
- "test_scan_settings_set_invalid_scan_mode",
- "test_scan_settings_set_report_delay_millis_min",
- "test_scan_settings_set_report_delay_millis_min_plus_one",
- "test_scan_settings_set_report_delay_millis_max",
- "test_scan_settings_set_report_delay_millis_max_minus_one",
- "test_scan_settings_set_invalid_report_delay_millis_min_minus_one",
- "test_scan_settings_set_scan_result_type_full",
- "test_scan_settings_set_scan_result_type_abbreviated",
- "test_scan_settings_set_invalid_scan_result_type",
- "test_scan_filter_set_device_name",
- "test_scan_filter_set_device_name_blank",
- "test_scan_filter_set_device_name_special_chars",
- "test_scan_filter_set_device_address",
- "test_scan_filter_set_invalid_device_address_lower_case",
- "test_scan_filter_set_invalid_device_address_blank",
- "test_scan_filter_set_invalid_device_address_bad_format",
- "test_scan_filter_set_invalid_device_address_bad_address",
- "test_scan_filter_set_manufacturer_id_data",
- "test_scan_filter_set_manufacturer_id_data_mask",
- "test_scan_filter_set_manufacturer_max_id",
- "test_scan_filter_set_manufacturer_data_empty",
- "test_scan_filter_set_manufacturer_data_mask_empty",
- "test_scan_filter_set_invalid_manufacturer_min_id_minus_one",
- "test_scan_filter_set_service_uuid",
- "test_scan_filter_service_uuid_p_service",
- "test_classic_ble_scan_with_service_uuids_p",
- "test_classic_ble_scan_with_service_uuids_hr",
- "test_classic_ble_scan_with_service_uuids_empty_uuid_list",
- "test_classic_ble_scan_with_service_uuids_hr_and_p",
- )
def _format_defaults(self, input):
"""
@@ -128,8 +82,8 @@
if 'ScanSettings' in input.keys():
try:
droid.bleSetScanSettingsCallbackType(input['ScanSettings'][0])
- droid.bleSetScanSettingsReportDelayMillis(
- input['ScanSettings'][1])
+ droid.bleSetScanSettingsReportDelayMillis(input[
+ 'ScanSettings'][1])
droid.bleSetScanSettingsScanMode(input['ScanSettings'][2])
droid.bleSetScanSettingsResultType(input['ScanSettings'][3])
except SL4AAPIError as error:
@@ -144,14 +98,14 @@
return False
if 'ScanFilterDeviceAddress' in input.keys():
try:
- droid.bleSetScanFilterDeviceAddress(
- input['ScanFilterDeviceAddress'])
+ droid.bleSetScanFilterDeviceAddress(input[
+ 'ScanFilterDeviceAddress'])
except SL4AAPIError as error:
self.log.debug("Set Scan Filter Device Address failed with: {}"
.format(error))
return False
- if ('ScanFilterManufacturerDataId' in input.keys()
- and 'ScanFilterManufacturerDataMask' in input.keys()):
+ if ('ScanFilterManufacturerDataId' in input.keys() and
+ 'ScanFilterManufacturerDataMask' in input.keys()):
try:
droid.bleSetScanFilterManufacturerData(
input['ScanFilterManufacturerDataId'],
@@ -161,19 +115,20 @@
self.log.debug("Set Scan Filter Manufacturer info with data "
"mask failed with: {}".format(error))
return False
- if ('ScanFilterManufacturerDataId' in input.keys()
- and 'ScanFilterManufacturerData' in input.keys()
- and 'ScanFilterManufacturerDataMask' not in input.keys()):
+ if ('ScanFilterManufacturerDataId' in input.keys() and
+ 'ScanFilterManufacturerData' in input.keys() and
+ 'ScanFilterManufacturerDataMask' not in input.keys()):
try:
droid.bleSetScanFilterManufacturerData(
input['ScanFilterManufacturerDataId'],
input['ScanFilterManufacturerData'])
except SL4AAPIError as error:
- self.log.debug("Set Scan Filter Manufacturer info failed with: "
- "{}".format(error))
+ self.log.debug(
+ "Set Scan Filter Manufacturer info failed with: "
+ "{}".format(error))
return False
- if ('ScanFilterServiceUuid' in input.keys() and 'ScanFilterServiceMask'
- in input.keys()):
+ if ('ScanFilterServiceUuid' in input.keys() and
+ 'ScanFilterServiceMask' in input.keys()):
droid.bleSetScanFilterServiceUuid(input['ScanFilterServiceUuid'],
input['ScanFilterServiceMask'])
@@ -182,11 +137,9 @@
scan_settings_index = droid.bleBuildScanSetting()
scan_settings = (
droid.bleGetScanSettingsCallbackType(scan_settings_index),
- droid.bleGetScanSettingsReportDelayMillis(
- scan_settings_index),
+ droid.bleGetScanSettingsReportDelayMillis(scan_settings_index),
droid.bleGetScanSettingsScanMode(scan_settings_index),
- droid.bleGetScanSettingsScanResultType(
- scan_settings_index))
+ droid.bleGetScanSettingsScanResultType(scan_settings_index))
scan_filter_index = droid.bleBuildScanFilter(filter_list)
device_name_filter = droid.bleGetScanFilterDeviceName(
@@ -209,43 +162,47 @@
return False
if device_address_filter != input['ScanFilterDeviceAddress']:
self.log.debug("Scan Filter address name did not match. expected: "
- "{}, found: {}".format(
- input['ScanFilterDeviceAddress'], device_address_filter))
+ "{}, found: {}".format(input[
+ 'ScanFilterDeviceAddress'],
+ device_address_filter))
return False
if manufacturer_id != input['ScanFilterManufacturerDataId']:
self.log.debug("Scan Filter manufacturer data id did not match. "
- "expected: {}, found: {}".format(
- input['ScanFilterManufacturerDataId'], manufacturer_id))
+ "expected: {}, found: {}".format(input[
+ 'ScanFilterManufacturerDataId'],
+ manufacturer_id))
return False
if manufacturer_data != input['ScanFilterManufacturerData']:
self.log.debug("Scan Filter manufacturer data did not match. "
- "expected: {}, found: {}".format(
- input['ScanFilterManufacturerData'], manufacturer_data))
+ "expected: {}, found: {}".format(input[
+ 'ScanFilterManufacturerData'],
+ manufacturer_data))
return False
if 'ScanFilterManufacturerDataMask' in input.keys():
manufacturer_data_mask = droid.bleGetScanFilterManufacturerDataMask(
- filter_list,
- scan_filter_index)
+ filter_list, scan_filter_index)
if manufacturer_data_mask != input[
'ScanFilterManufacturerDataMask']:
- self.log.debug("Manufacturer data mask did not match. expected:"
- " {}, found: {}".format(
- input['ScanFilterManufacturerDataMask'],
- manufacturer_data_mask))
+ self.log.debug(
+ "Manufacturer data mask did not match. expected:"
+ " {}, found: {}".format(input[
+ 'ScanFilterManufacturerDataMask'],
+ manufacturer_data_mask))
return False
- if ('ScanFilterServiceUuid' in input.keys() and 'ScanFilterServiceMask'
- in input.keys()):
+ if ('ScanFilterServiceUuid' in input.keys() and
+ 'ScanFilterServiceMask' in input.keys()):
expected_service_uuid = input['ScanFilterServiceUuid']
expected_service_mask = input['ScanFilterServiceMask']
service_uuid = droid.bleGetScanFilterServiceUuid(filter_list,
scan_filter_index)
- service_mask = droid.bleGetScanFilterServiceUuidMask(filter_list,
- scan_filter_index)
+ service_mask = droid.bleGetScanFilterServiceUuidMask(
+ filter_list, scan_filter_index)
if service_uuid != expected_service_uuid.lower():
self.log.debug("Service uuid did not match. expected: {}, "
- "found {}".format(expected_service_uuid,service_uuid))
+ "found {}".format(expected_service_uuid,
+ service_uuid))
return False
if service_mask != expected_service_mask.lower():
self.log.debug("Service mask did not match. expected: {}, "
@@ -1278,8 +1235,8 @@
return self.verify_classic_ble_scan_with_service_uuids(
droid, scan_callback, service_uuid_list)
- def verify_classic_ble_scan_with_service_uuids(
- self, droid, scan_callback, service_uuid_list):
+ def verify_classic_ble_scan_with_service_uuids(self, droid, scan_callback,
+ service_uuid_list):
test_result = True
try:
diff --git a/acts/tests/google/ble/api/GattApiTest.py b/acts/tests/google/ble/api/GattApiTest.py
index 7afd6ce..4edee1e 100644
--- a/acts/tests/google/ble/api/GattApiTest.py
+++ b/acts/tests/google/ble/api/GattApiTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to exercise Gatt Apis.
"""
@@ -25,23 +24,18 @@
class GattApiTest(BluetoothBaseTest):
- tests = None
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
- self.tests = (
- "test_open_gatt_server",
- "test_open_gatt_server_on_same_callback",
- "test_open_gatt_server_on_invalid_callback",
- )
+ self.ad = self.android_devices[0]
def setup_class(self):
return setup_multiple_devices_for_bt_test(self.android_devices)
def setup_test(self):
self.log.debug(log_energy_info(self.android_devices, "Start"))
- for e in self.eds:
- e.clear_all_events()
+ for a in self.android_devices:
+ a.ed.clear_all_events()
return True
def teardown_test(self):
@@ -68,9 +62,8 @@
TAGS: LE, GATT
Priority: 1
"""
- droid, ed = self.droid, self.ed
- gatt_server_callback = droid.gattServerCreateGattServerCallback()
- droid.gattServerOpenGattServer(gatt_server_callback)
+ gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback()
+ self.ad.droid.gattServerOpenGattServer(gatt_server_cb)
return True
@BluetoothBaseTest.bt_test_wrap
@@ -94,10 +87,9 @@
TAGS: LE, GATT
Priority: 2
"""
- droid, ed = self.droid, self.ed
- gatt_server_callback = droid.gattServerCreateGattServerCallback()
- droid.gattServerOpenGattServer(gatt_server_callback)
- droid.gattServerOpenGattServer(gatt_server_callback)
+ gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback()
+ self.ad.droid.gattServerOpenGattServer(gatt_server_cb)
+ self.ad.droid.gattServerOpenGattServer(gatt_server_cb)
return True
@BluetoothBaseTest.bt_test_wrap
@@ -119,10 +111,9 @@
TAGS: LE, GATT
Priority: 2
"""
- droid, ed = self.droid, self.ed
invalid_callback_index = -1
try:
- droid.gattServerOpenGattServer(invalid_callback_index)
+ self.ad.droid.gattServerOpenGattServer(invalid_callback_index)
except SL4AAPIError as e:
self.log.info("Failed successfully with exception: {}.".format(e))
return True
diff --git a/acts/tests/google/ble/beacon_tests/BeaconSwarmTest.py b/acts/tests/google/ble/beacon_tests/BeaconSwarmTest.py
index 9101168..fa51d82 100644
--- a/acts/tests/google/ble/beacon_tests/BeaconSwarmTest.py
+++ b/acts/tests/google/ble/beacon_tests/BeaconSwarmTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises different testcases with a lot of ble beacon traffic.
@@ -38,7 +37,6 @@
class BeaconSwarmTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
beacon_swarm_count = 0
advertising_device_name_list = []
@@ -47,12 +45,6 @@
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
self.scn_ad = self.android_devices[0]
- self.tests = (
- "test_swarm_1000_on_scan_result",
- "test_swarm_10000_on_batch_scan_result",
- "test_swarm_rotate_addresses",
- "test_swarm_scan_result_filter_each_device_name",
- )
def setup_test(self):
self.log.debug(log_energy_info(self.android_devices, "Start"))
@@ -90,11 +82,12 @@
for _ in range(beacon_count):
d.bleSetAdvertiseDataIncludeDeviceName(True)
d.bleSetAdvertiseSettingsAdvertiseMode(
- AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value)
+ AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.
+ value)
advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(d))
- d.bleStartBleAdvertising(
- advertise_callback, advertise_data, advertise_settings)
+ d.bleStartBleAdvertising(advertise_callback, advertise_data,
+ advertise_settings)
try:
e.pop_event(
adv_succ.format(advertise_callback),
@@ -106,8 +99,8 @@
d.bluetoothGetLocalName())
except Exception as e:
self.log.info("Advertising failed due to " + str(e))
- self.log.info(
- "Beacons active: {}".format(self.beacon_swarm_count))
+ self.log.info("Beacons active: {}".format(
+ self.beacon_swarm_count))
except Exception:
self.log.debug(
"Something went wrong in starting advertisements, continuing.")
@@ -137,9 +130,8 @@
for t in threads:
t.join()
if self.beacon_swarm_count < (beacon_count * len(beacon_serials)):
- self.log.error(
- "Not enough beacons advertising: {}".format(
- self.beacon_swarm_count))
+ self.log.error("Not enough beacons advertising: {}".format(
+ self.beacon_swarm_count))
return False
return True
@@ -160,9 +152,9 @@
serial_no = d.getBuildSerial()
if serial_no not in beacon_serials:
continue
- thread = threading.Thread(target=
- self._start_advertisements_thread,
- args=(d, e, beacon_count, True))
+ thread = threading.Thread(
+ target=self._start_advertisements_thread,
+ args=(d, e, beacon_count, True))
threads.append(thread)
thread.start()
for t in threads:
@@ -195,19 +187,18 @@
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
for _ in range(1000000):
event_info = self.scn_ad.ed.pop_event(
- scan_result.format(scan_callback),
- self.default_timeout)
+ scan_result.format(scan_callback), self.default_timeout)
mac_address = event_info['data']['Result']['deviceInfo']['address']
if mac_address not in self.discovered_mac_address_list:
self.discovered_mac_address_list.append(mac_address)
- self.log.info("Discovered {} different devices.".format(
- len(self.discovered_mac_address_list)))
- self.log.debug("Discovered {} different devices.".format(
- len(self.discovered_mac_address_list)))
+ self.log.info("Discovered {} different devices.".format(len(
+ self.discovered_mac_address_list)))
+ self.log.debug("Discovered {} different devices.".format(len(
+ self.discovered_mac_address_list)))
self.scn_ad.droid.bleStopBleScan(scan_callback)
return True
@@ -239,18 +230,17 @@
self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(1000)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
for _ in range(10000):
event_info = self.scn_ad.ed.pop_event(
- batch_scan_result.format(scan_callback),
- self.default_timeout)
+ batch_scan_result.format(scan_callback), self.default_timeout)
for result in event_info['data']['Results']:
mac_address = result['deviceInfo']['address']
if mac_address not in self.discovered_mac_address_list:
self.discovered_mac_address_list.append(mac_address)
- self.log.info("Discovered {} different devices.".format(
- len(self.discovered_mac_address_list)))
+ self.log.info("Discovered {} different devices.".format(len(
+ self.discovered_mac_address_list)))
self.scn_ad.droid.bleStopBleScan(scan_callback)
return True
@@ -289,13 +279,13 @@
try:
self.scn_ad.droid.bleSetScanFilterDeviceName(filter_name)
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.log.debug(self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout))
except Exception:
- self.log.info(
- "Couldn't find advertiser name {}.".format(filter_name))
+ self.log.info("Couldn't find advertiser name {}.".format(
+ filter_name))
return False
self.scn_ad.droid.bleStopBleScan(scan_callback)
return True
@@ -334,21 +324,24 @@
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(filter_list,scan_settings,scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
scan_callback_list.append(scan_callback)
thread = threading.Thread(
- target=self._restart_special_advertisements_thread, args=())
+ target=self._restart_special_advertisements_thread,
+ args=())
thread.start()
n = 0
while n < 10000:
for cb in scan_callback_list:
- event_info = self.scn_ad.ed.pop_event(scan_result.format(
- cb), self.default_timeout)
- mac_address = event_info['data']['Result']['deviceInfo']['address']
+ event_info = self.scn_ad.ed.pop_event(
+ scan_result.format(cb), self.default_timeout)
+ mac_address = event_info['data']['Result']['deviceInfo'][
+ 'address']
if mac_address not in self.discovered_mac_address_list:
self.discovered_mac_address_list.append(mac_address)
- self.log.info("Discovered {} different devices.".format(
- len(self.discovered_mac_address_list)))
+ self.log.info("Discovered {} different devices.".format(len(
+ self.discovered_mac_address_list)))
n += 1
self.scn_ad.droid.bleStopBleScan(scan_callback)
return True
diff --git a/acts/tests/google/ble/concurrency/ConcurrentBleAdvertisingTest.py b/acts/tests/google/ble/concurrency/ConcurrentBleAdvertisingTest.py
index 61f5141..57ef8a7 100644
--- a/acts/tests/google/ble/concurrency/ConcurrentBleAdvertisingTest.py
+++ b/acts/tests/google/ble/concurrency/ConcurrentBleAdvertisingTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to exercises different ways Ble Advertisements can run in
concurrency. This test was designed to be run in a shield box.
@@ -38,7 +37,6 @@
class ConcurrentBleAdvertisingTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
max_advertisements = 4
@@ -51,25 +49,11 @@
if self.max_advertisements == 0:
self.tests = ()
return
- self.tests = (
- "test_max_advertisements_defaults",
- "test_max_advertisements_include_device_name_and_filter_device_name",
- "test_max_advertisements_exclude_device_name_and_filter_device_name",
- "test_max_advertisements_with_manufacturer_data",
- "test_max_advertisements_with_manufacturer_data_mask",
- "test_max_advertisements_with_service_data",
- "test_max_advertisements_with_manufacturer_data_mask_and_include_device_name",
- "test_max_advertisements_with_service_uuids",
- "test_max_advertisements_with_service_uuid_and_service_mask",
- "test_max_advertisements_plus_one",
- "test_start_two_advertisements_on_same_callback",
- "test_toggle_advertiser_bt_state",
- "test_restart_advertise_callback_after_bt_toggle",
- )
def on_fail(self, test_name, begin_time):
- self.log.debug("Test {} failed. Gathering bugreport and btsnoop logs".
- format(test_name))
+ self.log.debug(
+ "Test {} failed. Gathering bugreport and btsnoop logs".format(
+ test_name))
take_btsnoop_logs(self.android_devices, self, test_name)
reset_bluetooth(self.android_devices)
@@ -92,16 +76,16 @@
advertise_callback = self.adv_ad.droid.bleGenBleAdvertiseCallback()
advertise_callback_list.append(advertise_callback)
self.adv_ad.droid.bleStartBleAdvertising(
- advertise_callback, advertise_data,
- advertise_settings)
+ advertise_callback, advertise_data, advertise_settings)
try:
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
- self.log.info("Advertisement {} started.".format(i+1))
+ self.log.info("Advertisement {} started.".format(i + 1))
except Empty as error:
- self.log.info("Advertisement {} failed to start.".format(i+1))
- self.log.debug(
- "Test failed with Empty error: {}".format(error))
+ self.log.info("Advertisement {} failed to start.".format(i +
+ 1))
+ self.log.debug("Test failed with Empty error: {}".format(
+ error))
return False
except concurrent.futures._base.TimeoutError as error:
self.log.debug(
@@ -110,8 +94,8 @@
return False
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
start_time = time.time()
while (start_time + self.default_timeout) > time.time():
event = None
@@ -161,12 +145,13 @@
test_result = True
filter_list = self.scn_ad.droid.bleGenFilterList()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
- def test_max_advertisements_include_device_name_and_filter_device_name(self):
+ def test_max_advertisements_include_device_name_and_filter_device_name(
+ self):
"""Testing max advertisement variant.
Test that a single device can have the max advertisements
@@ -197,12 +182,13 @@
self.scn_ad.droid.bleSetScanFilterDeviceName(
self.adv_ad.droid.bluetoothGetLocalName())
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
- def test_max_advertisements_exclude_device_name_and_filter_device_name(self):
+ def test_max_advertisements_exclude_device_name_and_filter_device_name(
+ self):
"""Test max advertisement variant.
Test that a single device can have the max advertisements concurrently
@@ -232,8 +218,8 @@
self.scn_ad.droid.bleSetScanFilterDeviceName(
self.adv_ad.droid.bluetoothGetLocalName())
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return not test_result
@BluetoothBaseTest.bt_test_wrap
@@ -267,8 +253,8 @@
self.scn_ad.droid.bleSetScanFilterManufacturerData(1, "1")
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(1, "1")
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -302,8 +288,8 @@
self.scn_ad.droid.bleSetScanFilterManufacturerData(1, "1", "1")
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(1, "1")
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -339,12 +325,13 @@
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleAddAdvertiseDataServiceData(
"0000110A-0000-1000-8000-00805F9B34FB", "11,17,80")
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
- def test_max_advertisements_with_manufacturer_data_mask_and_include_device_name(self):
+ def test_max_advertisements_with_manufacturer_data_mask_and_include_device_name(
+ self):
"""Test max advertisement variant.
Test that a single device can have the max advertisements concurrently
@@ -377,8 +364,8 @@
self.scn_ad.droid.bleSetScanFilterManufacturerData(1, "1", "1")
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(1, "1")
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -414,8 +401,8 @@
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids(
["00000000-0000-1000-8000-00805f9b34fb"])
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -452,8 +439,8 @@
self.scn_ad.droid.bleBuildScanFilter(filter_list)
self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids(
["00000000-0000-1000-8000-00805f9b34fb"])
- test_result = self._verify_n_advertisements(
- self.max_advertisements, filter_list)
+ test_result = self._verify_n_advertisements(self.max_advertisements,
+ filter_list)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -512,8 +499,7 @@
advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
- advertise_callback, advertise_data,
- advertise_settings)
+ advertise_callback, advertise_data, advertise_settings)
try:
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
@@ -526,8 +512,7 @@
.format(error))
try:
self.adv_ad.droid.bleStartBleAdvertising(
- advertise_callback, advertise_data,
- advertise_settings)
+ advertise_callback, advertise_data, advertise_settings)
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
test_result = False
@@ -569,8 +554,7 @@
advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
- advertise_callback, advertise_data,
- advertise_settings)
+ advertise_callback, advertise_data, advertise_settings)
try:
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
@@ -579,12 +563,12 @@
return False
except concurrent.futures._base.TimeoutError as error:
self.log.debug(
- "Test failed, filtering callback onSuccess never occurred: {}".
- format(error))
+ "Test failed, filtering callback onSuccess never occurred: {}".format(
+ error))
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
try:
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout)
@@ -596,8 +580,8 @@
return False
self.scn_ad.droid.bleStopBleScan(scan_callback)
test_result = reset_bluetooth([self.android_devices[1]])
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
if not test_result:
return test_result
try:
@@ -650,8 +634,8 @@
test_result = False
except concurrent.futures._base.TimeoutError as error:
self.log.debug(
- "Test failed, filtering callback onSuccess never occurred: {}".
- format(error))
+ "Test failed, filtering callback onSuccess never occurred: {}".format(
+ error))
test_result = reset_bluetooth([self.android_devices[1]])
if not test_result:
return test_result
@@ -665,6 +649,6 @@
test_result = False
except concurrent.futures._base.TimeoutError as error:
self.log.debug(
- "Test failed, filtering callback onSuccess never occurred: {}".
- format(error))
+ "Test failed, filtering callback onSuccess never occurred: {}".format(
+ error))
return test_result
diff --git a/acts/tests/google/ble/concurrency/ConcurrentBleScanningTest.py b/acts/tests/google/ble/concurrency/ConcurrentBleScanningTest.py
index 3b1a133..dc95269 100644
--- a/acts/tests/google/ble/concurrency/ConcurrentBleScanningTest.py
+++ b/acts/tests/google/ble/concurrency/ConcurrentBleScanningTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to exercises Ble Scans can run in concurrency.
This test was designed to be run in a shield box.
@@ -46,21 +45,12 @@
self.scn_ad = self.android_devices[0]
self.adv_ad = self.android_devices[1]
if self.droid_list[1]['max_advertisements'] == 0:
- self.tests = (
- "test_max_concurrent_ble_scans_plus_one",
- )
+ self.tests = ("test_max_concurrent_ble_scans_plus_one", )
return
- self.tests = (
- "test_max_concurrent_ble_scans",
- "test_max_concurrent_ble_scans_then_discover_advertisement",
- "test_max_concurrent_ble_scans_plus_one",
- "test_max_concurrent_ble_scans_verify_scans_stop_independently",
- )
def on_fail(self, test_name, begin_time):
- self.log.debug(
- "Test {} failed. Gathering bugreport and btsnoop logs."
- .format(test_name))
+ self.log.debug("Test {} failed. Gathering bugreport and btsnoop logs."
+ .format(test_name))
take_btsnoop_logs(self.android_devices, self, test_name)
reset_bluetooth(self.android_devices)
@@ -110,12 +100,13 @@
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
except Empty as error:
- self.log.exception(
- "Test failed with Empty error: {}".format(error))
+ self.log.exception("Test failed with Empty error: {}".format(
+ error))
test_result = False
except concurrent.futures._base.TimeoutError as error:
- self.log.exception("Test failed callback onSuccess never occurred: "
- "{}".format(error))
+ self.log.exception(
+ "Test failed callback onSuccess never occurred: "
+ "{}".format(error))
test_result = False
if not test_result:
return test_result
@@ -129,18 +120,16 @@
self.log.debug("Concurrent Ble Scan iteration {}".format(i + 1))
scan_callback = self.scn_ad.droid.bleGenScanCallback()
scan_callback_list.append(scan_callback)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
try:
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout)
- self.log.info(
- "Found scan event successfully. Iteration {} "
- "successful.".format(i))
+ self.log.info("Found scan event successfully. Iteration {} "
+ "successful.".format(i))
except Exception:
- self.log.info(
- "Failed to find a scan result for callback {}"
- .format(scan_callback))
+ self.log.info("Failed to find a scan result for callback {}"
+ .format(scan_callback))
test_result = False
break
for callback in scan_callback_list:
@@ -199,15 +188,16 @@
self.log.debug("Concurrent Ble Scan iteration {}".format(i + 1))
scan_callback = self.scn_ad.droid.bleGenScanCallback()
scan_callback_list.append(scan_callback)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
try:
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
except Empty as error:
- self.log.exception("Test failed with Empty error: {}".format(error))
+ self.log.exception("Test failed with Empty error: {}".format(
+ error))
return False
except concurrent.futures._base.TimeoutError as error:
self.log.exception("Test failed, filtering callback onSuccess "
@@ -216,15 +206,14 @@
i = 0
for callback in scan_callback_list:
try:
- self.scn_ad.ed.pop_event(scan_result.format(scan_callback),
- self.default_timeout)
+ self.scn_ad.ed.pop_event(
+ scan_result.format(scan_callback), self.default_timeout)
self.log.info(
"Found scan event successfully. Iteration {} successful."
.format(i))
except Exception:
- self.log.info(
- "Failed to find a scan result for callback {}"
- .format(scan_callback))
+ self.log.info("Failed to find a scan result for callback {}"
+ .format(scan_callback))
return False
i += 1
for callback in scan_callback_list:
@@ -267,12 +256,12 @@
for i in range(self.max_concurrent_scans):
self.log.debug("Concurrent Ble Scan iteration {}".format(i + 1))
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
scan_callback_list.append(scan_callback)
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
try:
self.scn_ad.ed.pop_event(
scan_failed.format(scan_callback), self.default_timeout)
@@ -333,35 +322,36 @@
self.log.debug("Concurrent Ble Scan iteration {}".format(i + 1))
scan_callback = self.scn_ad.droid.bleGenScanCallback()
scan_callback_list.append(scan_callback)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
try:
self.adv_ad.ed.pop_event(
adv_succ.format(advertise_callback), self.default_timeout)
except Empty as error:
- self.log.exception(
- "Test failed with Empty error: {}".format(error))
+ self.log.exception("Test failed with Empty error: {}".format(
+ error))
return False
except concurrent.futures._base.TimeoutError as error:
- self.log.exception("Test failed, filtering callback onSuccess never"
- " occurred: {}".format(error))
+ self.log.exception(
+ "Test failed, filtering callback onSuccess never"
+ " occurred: {}".format(error))
return False
i = 0
for callback in scan_callback_list:
expected_scan_event_name = scan_result.format(scan_callback)
try:
- self.scn_ad.ed.pop_event(
- expected_scan_event_name, self.default_timeout)
+ self.scn_ad.ed.pop_event(expected_scan_event_name,
+ self.default_timeout)
self.log.info(
- "Found scan event successfully. Iteration {} successful.".
- format(i))
+ "Found scan event successfully. Iteration {} successful.".format(
+ i))
i += 1
except Exception:
self.log.info(
- "Failed to find a scan result for callback {}".
- format(scan_callback))
+ "Failed to find a scan result for callback {}".format(
+ scan_callback))
return False
self.scn_ad.droid.bleStopBleScan(callback)
self.adv_ad.droid.bleStopBleAdvertising(advertise_callback)
diff --git a/acts/tests/google/ble/examples/BleExamplesTest.py b/acts/tests/google/ble/examples/BleExamplesTest.py
index 0fcef37..7691a00 100644
--- a/acts/tests/google/ble/examples/BleExamplesTest.py
+++ b/acts/tests/google/ble/examples/BleExamplesTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This script shows simple examples of how to get started with bluetooth low energy testing in acts.
"""
@@ -30,7 +29,6 @@
class BleExamplesTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
active_scan_callback_list = []
active_adv_callback_list = []
@@ -47,9 +45,6 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_bt_toggle",
- )
def teardown_test(self):
cleanup_scanners_and_advertisers(
@@ -63,10 +58,9 @@
# unexpected exception, you can customise it.
def on_exception(self, test_name, begin_time):
self.log.debug(
- "Test {} failed. Gathering bugreport and btsnoop logs".
- format(test_name))
- android_devices.take_bug_reports(self.android_devices,
- test_name,
+ "Test {} failed. Gathering bugreport and btsnoop logs".format(
+ test_name))
+ android_devices.take_bug_reports(self.android_devices, test_name,
begin_time)
@BluetoothBaseTest.bt_test_wrap
@@ -107,14 +101,14 @@
filter_list = self.scn_droid.bleGenFilterList()
scan_settings = self.scn_droid.bleBuildScanSetting()
scan_callback = self.scn_droid.bleGenScanCallback()
- self.scn_droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
event_name = scan_result.format(scan_callback)
try:
event = self.scn_ed.pop_event(event_name, self.default_timeout)
- self.log.info(
- "Found scan result: {}".format(pprint.pformat(event)))
+ self.log.info("Found scan result: {}".format(pprint.pformat(
+ event)))
except Exception:
self.log.info("Didn't find any scan results.")
return True
diff --git a/acts/tests/google/ble/filtering/FilteringTest.py b/acts/tests/google/ble/filtering/FilteringTest.py
index a28b93e..61324cd 100644
--- a/acts/tests/google/ble/filtering/FilteringTest.py
+++ b/acts/tests/google/ble/filtering/FilteringTest.py
@@ -34,7 +34,6 @@
class FilteringTest(BluetoothBaseTest):
- tests = None
default_timeout = 30
valid_filter_suite = [
@@ -137,15 +136,15 @@
"tx_power_level": [
AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_HIGH.value,
AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_LOW.value,
- AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_ULTRA_LOW.value,
+ AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_ULTRA_LOW.
+ value,
AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_MEDIUM.value,
],
"is_connectable": [True, False],
"scan_mode": [ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value,
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value,
ScanSettingsScanMode.SCAN_MODE_BALANCED.value,
- ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value,
- ]
+ ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, ]
}
default_callback = 1
@@ -155,9 +154,9 @@
def _get_combinations(self, t):
varNames = sorted(t)
- return (
- [dict(zip(varNames, prod)) for prod
- in it.product(*(t[varName] for varName in varNames))])
+ return ([dict(zip(varNames, prod))
+ for prod in it.product(*(t[varName]
+ for varName in varNames))])
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
@@ -167,21 +166,10 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.log.info(
- "Scanner device model: {}".format(
- self.scn_ad.droid.getBuildModel()))
- self.log.info(
- "Advertiser device model: {}".format(
- self.adv_ad.droid.getBuildModel()))
- self.tests = (
- "test_valid_filters",
- "test_valid_filters_opportunistic_scan",
- "test_default_advertisement",
- "test_settings_in_effect_suite",
- "test_filters_suite",
- "test_filters_suite_opportunistic_scan",
- "test_non_connectable_advertise_data",
- )
+ self.log.info("Scanner device model: {}".format(
+ self.scn_ad.droid.getBuildModel()))
+ self.log.info("Advertiser device model: {}".format(
+ self.adv_ad.droid.getBuildModel()))
def blescan_verify_onfailure_event_handler(self, event):
self.log.debug("Verifying {} event".format(adv_fail))
@@ -206,9 +194,10 @@
'include_device_name'] is not False:
if event['data']['Result']['deviceName'] != filters[
'include_device_name']:
- self.log.error("Expected device name: {}, Found device name: {}"
- .format(filters['include_device_name'],
- event['data']['Result']['deviceName']))
+ self.log.error(
+ "Expected device name: {}, Found device name: {}"
+ .format(filters['include_device_name'], event['data'][
+ 'Result']['deviceName']))
test_result = False
elif 'deviceName' in event['data']['Result'].keys():
@@ -234,42 +223,41 @@
test_result = True
if 'is_connectable' in settings_in_effect.keys():
if (event['data']['SettingsInEffect']['isConnectable'] !=
- settings_in_effect['is_connectable']):
- self.log.error(
- "Expected is connectable value: {}, Actual is "
- "connectable value:".format(
- settings_in_effect['is_connectable'],
- event['data']['SettingsInEffect']['isConnectable']))
+ settings_in_effect['is_connectable']):
+ self.log.error("Expected is connectable value: {}, Actual is "
+ "connectable value:".format(settings_in_effect[
+ 'is_connectable'], event['data'][
+ 'SettingsInEffect']['isConnectable']))
test_result = False
elif (event['data']['SettingsInEffect']['isConnectable'] !=
- self.default_is_connectable):
+ self.default_is_connectable):
self.log.error(
"Default value for isConnectable did not match what was found.")
test_result = False
if 'mode' in settings_in_effect.keys():
if (event['data']['SettingsInEffect']['mode'] !=
- settings_in_effect['mode']):
- self.log.error(
- "Expected mode value: {}, Actual mode value: {}"
- .format(settings_in_effect['mode'],
- event['data']['SettingsInEffect']['mode']))
+ settings_in_effect['mode']):
+ self.log.error("Expected mode value: {}, Actual mode value: {}"
+ .format(settings_in_effect['mode'], event[
+ 'data']['SettingsInEffect']['mode']))
test_result = False
elif (event['data']['SettingsInEffect']['mode'] !=
- self.default_advertise_mode):
+ self.default_advertise_mode):
self.log.error(
"Default value for filtering mode did not match what was "
"found.")
test_result = False
if 'tx_power_level' in settings_in_effect.keys():
if (event['data']['SettingsInEffect']['txPowerLevel'] ==
- JavaInteger.MIN.value):
+ JavaInteger.MIN.value):
self.log.error("Expected tx power level was not meant to be: "
"{}".format(JavaInteger.MIN.value))
test_result = False
elif (event['data']['SettingsInEffect']['txPowerLevel'] !=
- self.default_tx_power_level):
- self.log.error("Default value for tx power level did not match what"
- " was found.")
+ self.default_tx_power_level):
+ self.log.error(
+ "Default value for tx power level did not match what"
+ " was found.")
test_result = False
return test_result
@@ -277,28 +265,27 @@
(filters, settings_in_effect) = params
test_result = True
- self.log.debug("Settings in effect: {}".format(
- pprint.pformat(settings_in_effect)))
+ self.log.debug("Settings in effect: {}".format(pprint.pformat(
+ settings_in_effect)))
self.log.debug("Filters:".format(pprint.pformat(filters)))
if 'is_connectable' in settings_in_effect.keys():
self.log.debug("Setting advertisement is_connectable to {}".format(
- settings_in_effect['is_connectable']))
+ settings_in_effect['is_connectable']))
self.adv_ad.droid.bleSetAdvertiseSettingsIsConnectable(
settings_in_effect['is_connectable'])
if 'mode' in settings_in_effect.keys():
- self.log.debug(
- "Setting advertisement mode to {}"
- .format(settings_in_effect['mode']))
+ self.log.debug("Setting advertisement mode to {}"
+ .format(settings_in_effect['mode']))
self.adv_ad.droid.bleSetAdvertiseSettingsAdvertiseMode(
settings_in_effect['mode'])
if 'tx_power_level' in settings_in_effect.keys():
self.log.debug("Setting advertisement tx_power_level to {}".format(
- settings_in_effect['tx_power_level']))
+ settings_in_effect['tx_power_level']))
self.adv_ad.droid.bleSetAdvertiseSettingsTxPowerLevel(
settings_in_effect['tx_power_level'])
filter_list = self.scn_ad.droid.bleGenFilterList()
- if ('include_device_name' in filters.keys()
- and filters['include_device_name'] is not False):
+ if ('include_device_name' in filters.keys() and
+ filters['include_device_name'] is not False):
self.log.debug("Setting advertisement include_device_name to {}"
.format(filters['include_device_name']))
@@ -306,9 +293,9 @@
filters['include_device_name'] = (
self.adv_ad.droid.bluetoothGetLocalName())
self.log.debug("Setting scanner include_device_name to {}".format(
- filters['include_device_name']))
- self.scn_ad.droid.bleSetScanFilterDeviceName(
- filters['include_device_name'])
+ filters['include_device_name']))
+ self.scn_ad.droid.bleSetScanFilterDeviceName(filters[
+ 'include_device_name'])
else:
self.log.debug(
"Setting advertisement include_device_name to False")
@@ -336,52 +323,49 @@
filters['manufacturer_specific_data'])
if 'service_data' in filters.keys():
self.adv_ad.droid.bleAddAdvertiseDataServiceData(
- filters['service_data_uuid'],
- filters['service_data'])
+ filters['service_data_uuid'], filters['service_data'])
self.scn_ad.droid.bleSetScanFilterServiceData(
- filters['service_data_uuid'],
- filters['service_data'])
+ filters['service_data_uuid'], filters['service_data'])
if 'manufacturer_specific_data_list' in filters.keys():
for pair in filters['manufacturer_specific_data_list']:
(manu_id, manu_data) = pair
- self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(
- manu_id, manu_data)
+ self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(manu_id,
+ manu_data)
if 'service_mask' in filters.keys():
self.scn_ad.droid.bleSetScanFilterServiceUuid(
- filters['service_uuid'].upper(),
- filters['service_mask'])
- self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids(
- [filters['service_uuid'].upper()])
+ filters['service_uuid'].upper(), filters['service_mask'])
+ self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids([filters[
+ 'service_uuid'].upper()])
elif 'service_uuid' in filters.keys():
- self.scn_ad.droid.bleSetScanFilterServiceUuid(
- filters['service_uuid'])
- self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids(
- [filters['service_uuid']])
+ self.scn_ad.droid.bleSetScanFilterServiceUuid(filters[
+ 'service_uuid'])
+ self.adv_ad.droid.bleSetAdvertiseDataSetServiceUuids([filters[
+ 'service_uuid']])
self.scn_ad.droid.bleBuildScanFilter(filter_list)
advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(self.adv_ad.droid))
- if ('scan_mode' in settings_in_effect
- and settings_in_effect['scan_mode']
- != ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value):
- self.scn_ad.droid.bleSetScanSettingsScanMode(
- settings_in_effect['scan_mode'])
+ if ('scan_mode' in settings_in_effect and
+ settings_in_effect['scan_mode'] !=
+ ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value):
+ self.scn_ad.droid.bleSetScanSettingsScanMode(settings_in_effect[
+ 'scan_mode'])
else:
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
opportunistic = False
scan_settings2, scan_callback2 = None, None
if ('scan_mode' in settings_in_effect and
settings_in_effect['scan_mode'] ==
- ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value):
+ ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value):
opportunistic = True
scan_settings2 = self.scn_ad.droid.bleBuildScanSetting()
scan_callback2 = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings2,
+ scan_callback2)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value)
self.adv_ad.droid.bleStartBleAdvertising(
@@ -404,8 +388,8 @@
try:
finished = False
start_time = time.time()
- while (time.time() < start_time + self.default_timeout and not
- finished):
+ while (time.time() < start_time + self.default_timeout and
+ not finished):
test_result = worker.result(self.default_timeout)
if test_result:
@@ -478,12 +462,12 @@
TAGS: LE, Advertising, Filtering, Scanning
Priority: 1
"""
- settings = self._get_combinations(
- self.settings_in_effect_variants)
+ settings = self._get_combinations(self.settings_in_effect_variants)
filters = [{"include_device_name": True}]
params = list(it.product(filters, settings))
- failed = self.run_generated_testcases(
- self._magic, params, tag="settings_in_effect_suite")
+ failed = self.run_generated_testcases(self._magic,
+ params,
+ tag="settings_in_effect_suite")
if failed:
return False
return True
@@ -511,10 +495,13 @@
"""
valid_filter_suit = self._get_combinations(self.valid_filter_variants)
settings = [
- {'mode':AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value}]
+ {'mode':
+ AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value}
+ ]
params = list(it.product(valid_filter_suit, settings))
- failed = self.run_generated_testcases(
- self._magic, params, tag="filters_suite")
+ failed = self.run_generated_testcases(self._magic,
+ params,
+ tag="filters_suite")
if failed:
return False
return True
@@ -544,11 +531,14 @@
reset_bluetooth(self.android_devices)
valid_filter_suit = self._get_combinations(self.valid_filter_variants)
settings = [
- {'mode': AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value,
- 'scan_mode': ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value}]
+ {'mode':
+ AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value,
+ 'scan_mode': ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value}
+ ]
params = list(it.product(valid_filter_suit, settings))
- failed = self.run_generated_testcases(
- self._magic, params, tag="filters_suite")
+ failed = self.run_generated_testcases(self._magic,
+ params,
+ tag="filters_suite")
if failed:
return False
return True
@@ -576,10 +566,13 @@
"""
reset_bluetooth(self.android_devices)
settings = [
- {'mode': AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value}]
+ {'mode':
+ AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value}
+ ]
params = list(it.product(self.valid_filter_suite, settings))
- failed = self.run_generated_testcases(
- self._magic, params, tag="valid_filters")
+ failed = self.run_generated_testcases(self._magic,
+ params,
+ tag="valid_filters")
if failed:
return False
return True
@@ -607,11 +600,14 @@
Priority: 1
"""
settings = [
- {'mode': AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value,
- 'scan_mode': ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value}]
+ {'mode':
+ AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value,
+ 'scan_mode': ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value}
+ ]
params = list(it.product(self.valid_filter_suite, settings))
- failed = self.run_generated_testcases(
- self._magic, params, tag="valid_filters")
+ failed = self.run_generated_testcases(self._magic,
+ params,
+ tag="valid_filters")
if failed:
return False
return True
diff --git a/acts/tests/google/ble/filtering/UniqueFilteringTest.py b/acts/tests/google/ble/filtering/UniqueFilteringTest.py
index 9ae6c33..6a3600b 100644
--- a/acts/tests/google/ble/filtering/UniqueFilteringTest.py
+++ b/acts/tests/google/ble/filtering/UniqueFilteringTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises different filters and outcomes not exercised in
FilteringTest.
@@ -35,7 +34,6 @@
class UniqueFilteringTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
def __init__(self, controllers):
@@ -46,27 +44,14 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_scan_flush_pending_scan_results",
- "test_scan_non_existent_name_filter",
- "test_scan_advertisement_with_device_service_uuid_filter_expect_no_events",
- "test_scan_filter_device_address",
- )
- if self.droid_list[1]['max_advertisements'] > 1:
- self.tests = self.tests + \
- ("test_scan_filtering_multiple_advertisements_manufacturer_data",
- )
- if self.droid_list[0]['batch_scan_supported']:
- self.tests = self.tests + (
- "test_scan_flush_results_without_on_batch_scan_results_triggered",
- "test_scan_trigger_on_batch_scan_results",)
def blescan_verify_onfailure_event_handler(self, event):
self.log.debug("Verifying onFailure event")
self.log.debug(pprint.pformat(event))
return event
- def blescan_verify_onscanresult_event_handler(self, event,
+ def blescan_verify_onscanresult_event_handler(self,
+ event,
expected_callbacktype=None,
system_time_nanos=None):
test_result = True
@@ -74,7 +59,8 @@
self.log.debug(pprint.pformat(event))
callbacktype = event['data']['CallbackType']
if callbacktype != expected_callbacktype:
- self.log.debug("Expected callback type: {}, Found callback type: {}"
+ self.log.debug(
+ "Expected callback type: {}, Found callback type: {}"
.format(expected_callbacktype, callbacktype))
test_result = False
return test_result
@@ -82,9 +68,11 @@
def blescan_get_mac_address_event_handler(self, event):
return event['data']['Result']['deviceInfo']['address']
- def blescan_verify_onbatchscanresult_event_handler(self, event,
- system_time_nanos=None,
- report_delay_nanos=None):
+ def blescan_verify_onbatchscanresult_event_handler(
+ self,
+ event,
+ system_time_nanos=None,
+ report_delay_nanos=None):
test_result = True
self.log.debug("Verifying onBatchScanResult event")
self.log.debug(pprint.pformat(event))
@@ -134,8 +122,8 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.scn_ad.droid.bleFlushPendingScanResults(scan_callback)
worker = self.scn_ad.ed.handle_event(
self.blescan_verify_onscanresult_event_handler,
@@ -188,8 +176,8 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
system_time_nanos = self.scn_ad.droid.getSystemElapsedRealtimeNanos()
self.log.debug("Current system time: {}".format(system_time_nanos))
worker = self.scn_ad.ed.handle_event(
@@ -234,21 +222,20 @@
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
expected_event_name = batch_scan_result.format(scan_callback)
- advertise_callback, advertise_data, advertise_settings =(
+ advertise_callback, advertise_data, advertise_settings = (
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
worker = self.scn_ad.ed.handle_event(
self.blescan_verify_onbatchscanresult_event_handler,
expected_event_name, ([]), self.default_timeout)
self.scn_ad.droid.bleFlushPendingScanResults(scan_callback)
try:
- event_info = self.scn_ad.ed.pop_event(expected_event_name,
- 10)
- self.log.debug(
- "Unexpectedly found an advertiser: {}".format(event_info))
+ event_info = self.scn_ad.ed.pop_event(expected_event_name, 10)
+ self.log.debug("Unexpectedly found an advertiser: {}".format(
+ event_info))
test_result = False
except Empty:
self.log.debug("No {} events were found as expected.".format(
@@ -294,13 +281,13 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
try:
- event_info = self.scn_ad.ed.pop_event(
- expected_event_name, self.default_timeout)
- self.log.error(
- "Unexpectedly found an advertiser: {}".format(event_info))
+ event_info = self.scn_ad.ed.pop_event(expected_event_name,
+ self.default_timeout)
+ self.log.error("Unexpectedly found an advertiser: {}".format(
+ event_info))
test_result = False
except Empty:
self.log.debug("No events were found as expected.")
@@ -337,7 +324,7 @@
service_mask = "00000000-0000-1000-8000-00805F9B34FA"
self.adv_ad.droid.bleSetAdvertiseDataIncludeDeviceName(True)
self.scn_ad.droid.bleSetScanFilterServiceUuid(service_uuid,
- service_mask)
+ service_mask)
self.adv_ad.droid.bleSetAdvertiseSettingsAdvertiseMode(
AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
@@ -350,16 +337,16 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
worker = self.scn_ad.ed.handle_event(
self.blescan_verify_onscanresult_event_handler,
expected_event_name, ([1]), self.default_timeout)
try:
event_info = self.scn_ad.ed.pop_event(expected_event_name,
- self.default_timeout)
- self.log.error(
- "Unexpectedly found an advertiser:".format(event_info))
+ self.default_timeout)
+ self.log.error("Unexpectedly found an advertiser:".format(
+ event_info))
test_result = False
except Empty as error:
self.log.debug("No events were found as expected.")
@@ -401,26 +388,25 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleSetAdvertiseSettingsAdvertiseMode(
AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value)
- self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(
- 117, "1,2,3,4,5,6,7,8")
+ self.adv_ad.droid.bleAddAdvertiseDataManufacturerId(117,
+ "1,2,3,4,5,6,7,8")
advertise_callback1, advertise_data1, advertise_settings1 = (
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
self.adv_ad.droid.bleStartBleAdvertising(
- advertise_callback1, advertise_data1,
- advertise_settings1)
+ advertise_callback1, advertise_data1, advertise_settings1)
filter_list = self.scn_ad.droid.bleGenFilterList()
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleSetScanFilterManufacturerData(
- 117, "1,2,3", "127,127,127")
+ self.scn_ad.droid.bleSetScanFilterManufacturerData(117, "1,2,3",
+ "127,127,127")
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -462,13 +448,13 @@
generate_ble_advertise_objects(self.adv_ad.droid))
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
- event_info = self.scn_ad.ed.pop_event(
- expected_event_name, self.default_timeout)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
+ event_info = self.scn_ad.ed.pop_event(expected_event_name,
+ self.default_timeout)
mac_address = event_info['data']['Result']['deviceInfo']['address']
- self.log.info(
- "Filter advertisement with address {}".format(mac_address))
+ self.log.info("Filter advertisement with address {}".format(
+ mac_address))
self.scn_ad.droid.bleStopBleScan(scan_callback)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
@@ -477,11 +463,11 @@
generate_ble_scan_objects(self.scn_ad.droid))
self.scn_ad.droid.bleBuildScanFilter(filter_list2)
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
expected_event_name = scan_result.format(scan_callback2)
- found_event = self.scn_ad.ed.pop_event(
- expected_event_name, self.default_timeout)
+ found_event = self.scn_ad.ed.pop_event(expected_event_name,
+ self.default_timeout)
if (found_event['data']['Result']['deviceInfo']['address'] !=
mac_address):
test_result = False
diff --git a/acts/tests/google/ble/gatt/GattConnectTest.py b/acts/tests/google/ble/gatt/GattConnectTest.py
index fa2dda3..d23113c 100644
--- a/acts/tests/google/ble/gatt/GattConnectTest.py
+++ b/acts/tests/google/ble/gatt/GattConnectTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises different GATT connection tests.
"""
@@ -24,30 +23,24 @@
from contextlib import suppress
from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
-from acts.test_utils.bt.BleEnum import BluetoothGattCharacteristic
-from acts.test_utils.bt.BleEnum import BluetoothGattDescriptor
-from acts.test_utils.bt.BleEnum import BluetoothGattService
-from acts.test_utils.bt.BleEnum import BluetoothMtuSize
-from acts.test_utils.bt.bt_test_utils import characteristic_write_request
-from acts.test_utils.bt.bt_test_utils import characteristic_write
-from acts.test_utils.bt.bt_test_utils import descriptor_write
-from acts.test_utils.bt.bt_test_utils import descriptor_write_request
-from acts.test_utils.bt.bt_test_utils import disconnect_gatt_connection
-from acts.test_utils.bt.bt_test_utils import gatt_services_discovered
+from acts.test_utils.bt.GattEnum import GattCharacteristic
+from acts.test_utils.bt.GattEnum import GattDescriptor
+from acts.test_utils.bt.GattEnum import GattService
+from acts.test_utils.bt.GattEnum import MtuSize
+from acts.test_utils.bt.GattEnum import GattCbErr
+from acts.test_utils.bt.GattEnum import GattCbStrings
+from acts.test_utils.bt.GattEnum import GattConnectionPriority
+from acts.test_utils.bt.bt_gatt_utils import disconnect_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import orchestrate_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_characteristics
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_descriptors
from acts.test_utils.bt.bt_test_utils import get_advanced_droid_list
from acts.test_utils.bt.bt_test_utils import get_mac_address_of_generic_advertisement
-from acts.test_utils.bt.bt_test_utils import mtu_changed
-from acts.test_utils.bt.bt_test_utils import orchestrate_gatt_connection
-from acts.test_utils.bt.bt_test_utils import read_remote_rssi
-from acts.test_utils.bt.bt_test_utils import service_added
-from acts.test_utils.bt.bt_test_utils import setup_gatt_characteristics
-from acts.test_utils.bt.bt_test_utils import setup_gatt_connection
-from acts.test_utils.bt.bt_test_utils import setup_gatt_descriptors
from acts.test_utils.bt.bt_test_utils import log_energy_info
class GattConnectTest(BluetoothBaseTest):
- tests = None
adv_instances = []
default_timeout = 10
default_discovery_timeout = 3
@@ -61,19 +54,6 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_gatt_connect",
- "test_gatt_request_min_mtu",
- "test_gatt_request_max_mtu",
- "test_gatt_request_out_of_bounds_mtu",
- "test_gatt_connect_trigger_on_read_rssi",
- "test_gatt_connect_trigger_on_services_discovered",
- "test_gatt_connect_trigger_on_services_discovered_iterate_attributes",
- "test_gatt_connect_with_service_uuid_variations",
- "test_gatt_connect_in_quick_succession",
- "test_write_descriptor_stress",
- "test_gatt_connect_mitm_attack",
- )
def teardown_test(self):
for adv in self.adv_instances:
@@ -85,44 +65,44 @@
characteristic_input = [
{
'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattCharacteristic.PROPERTY_WRITE.value |
- BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
- 'permission': BluetoothGattCharacteristic.PROPERTY_WRITE.value
+ 'property': GattCharacteristic.PROPERTY_WRITE.value
+ | GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
+ 'permission': GattCharacteristic.PERMISSION_WRITE.value
},
{
'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
},
{
'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
},
]
descriptor_input = [
{
'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattDescriptor.PERMISSION_WRITE.value,
- },
- {
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
+ }, {
'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattCharacteristic.PERMISSION_WRITE.value,
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattCharacteristic.PERMISSION_WRITE.value,
}
]
- characteristic_list = setup_gatt_characteristics(
- droid, characteristic_input)
+ characteristic_list = setup_gatt_characteristics(droid,
+ characteristic_input)
descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
return characteristic_list, descriptor_list
def _orchestrate_gatt_disconnection(self, bluetooth_gatt, gatt_callback):
self.log.info("Disconnecting from peripheral device.")
- test_result = disconnect_gatt_connection(
- self.cen_ad, bluetooth_gatt, gatt_callback)
+ test_result = disconnect_gatt_connection(self.cen_ad, bluetooth_gatt,
+ gatt_callback)
+ self.cen_ad.droid.gattClientClose(bluetooth_gatt)
if not test_result:
self.log.info("Failed to disconnect from peripheral device.")
return False
@@ -139,24 +119,28 @@
self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
discovered_services_index, i))
for characteristic in characteristic_uuids:
- self.log.info(
- "Discovered characteristic uuid {}".format(characteristic))
+ self.log.info("Discovered characteristic uuid {}".format(
+ characteristic))
descriptor_uuids = (
self.cen_ad.droid.gattClientGetDiscoveredDescriptorUuids(
discovered_services_index, i, characteristic))
for descriptor in descriptor_uuids:
- self.log.info(
- "Discovered descriptor uuid {}".format(descriptor))
+ self.log.info("Discovered descriptor uuid {}".format(
+ descriptor))
def _find_service_added_event(self, gatt_server_callback, uuid):
- event = self.per_ad.ed.pop_event(
- service_added.format(gatt_server_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.SERV_ADDED.value.format(
+ gatt_server_callback)
+ try:
+ event = self.per_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.SERV_ADDED_ERR.value.format(
+ expected_event))
+ return False
if event['data']['serviceUuid'].lower() != uuid.lower():
- self.log.info(
- "Uuid mismatch. Found: {}, Expected {}.".format(
- event['data']['serviceUuid'],
- uuid))
+ self.log.error("Uuid mismatch. Found: {}, Expected {}.".format(
+ event['data']['serviceUuid'], uuid))
return False
return True
@@ -173,32 +157,32 @@
characteristic_list[2], descriptor_list[1])
gatt_service = self.per_ad.droid.gattServerCreateService(
"00000000-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
gatt_service2 = self.per_ad.droid.gattServerCreateService(
"FFFFFFFF-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
gatt_service3 = self.per_ad.droid.gattServerCreateService(
"3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
result = self._find_service_added_event(
gatt_server_callback, "00000000-0000-1000-8000-00805f9b34fb")
if not result:
return False
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service2,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service2, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service2)
result = self._find_service_added_event(
gatt_server_callback, "FFFFFFFF-0000-1000-8000-00805f9b34fb")
if not result:
return False
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service3,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service3, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service3)
result = self._find_service_added_event(
gatt_server_callback, "3846D7A0-69C8-11E4-BA00-0002A5D5C51B")
@@ -206,6 +190,9 @@
return False, False
return gatt_server_callback, gatt_server
+ def _cleanup_services(self, gatt_server):
+ self.per_ad.droid.gattServerClearServices(gatt_server)
+
@BluetoothBaseTest.bt_test_wrap
def test_gatt_connect(self):
"""Test GATT connection over LE.
@@ -239,6 +226,56 @@
gatt_callback)
@BluetoothBaseTest.bt_test_wrap
+ def test_gatt_connect_autoconnect(self):
+ """Test GATT connection over LE.
+
+ Test re-establishing a gat connection using autoconnect
+ set to True in order to test connection whitelist.
+
+ Steps:
+ 1. Start a generic advertisement.
+ 2. Start a generic scanner.
+ 3. Find the advertisement and extract the mac address.
+ 4. Stop the first scanner.
+ 5. Create a GATT connection between the scanner and advertiser.
+ 6. Disconnect the GATT connection.
+ 7. Create a GATT connection with autoconnect set to True
+ 8. Disconnect the GATT connection.
+
+ Expected Result:
+ Verify that a connection was re-established and then disconnected
+ successfully.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: LE, Advertising, Filtering, Scanning, GATT
+ Priority: 0
+ """
+ autoconnect = False
+ mac_address, adv_callback = (
+ get_mac_address_of_generic_advertisement(self.cen_ad, self.per_ad))
+ test_result, bluetooth_gatt, gatt_callback = setup_gatt_connection(
+ self.cen_ad, mac_address, autoconnect)
+ if not disconnect_gatt_connection(self.cen_ad, bluetooth_gatt,
+ gatt_callback):
+ return False
+ autoconnect = True
+ bluetooth_gatt = self.cen_ad.droid.gattClientConnectGatt(
+ gatt_callback, mac_address, autoconnect)
+ expected_event = GattCbStrings.GATT_CONN_CHANGE.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ log.error(GattCbErr.GATT_CONN_CHANGE_ERR.value.format(
+ expected_event))
+ test_result = False
+ return True
+
+ @BluetoothBaseTest.bt_test_wrap
def test_gatt_request_min_mtu(self):
"""Test GATT connection over LE and exercise MTU sizes.
@@ -270,10 +307,20 @@
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
- self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MIN.value)
- mtu_event = self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt))
- if mtu_event['data']['MTU'] != BluetoothMtuSize.MIN.value:
+ expected_mtu = MtuSize.MIN.value
+ self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt, expected_mtu)
+ expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
+ try:
+ mtu_event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ mtu_size_found = mtu_event['data']['MTU']
+ if mtu_size_found != expected_mtu:
+ self.log.error("MTU size found: {}, expected: {}".format(
+ mtu_size_found, expected_mtu))
+ return False
+ except Empty:
+ self.log.error(GattCbErr.MTU_CHANGED_ERR.value.format(
+ expected_event))
return False
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -310,10 +357,20 @@
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
- self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MAX.value)
- mtu_event = self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt))
- if mtu_event['data']['MTU'] != BluetoothMtuSize.MAX.value:
+ expected_mtu = MtuSize.MAX.value
+ self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt, expected_mtu)
+ expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
+ try:
+ mtu_event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ mtu_size_found = mtu_event['data']['MTU']
+ if mtu_size_found != expected_mtu:
+ self.log.error("MTU size found: {}, expected: {}".format(
+ mtu_size_found, expected_mtu))
+ return False
+ except Empty:
+ self.log.error(GattCbErr.MTU_CHANGED_ERR.value.format(
+ expected_event))
return False
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -352,16 +409,16 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MIN.value - 1)
+ MtuSize.MIN.value - 1)
+ expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
try:
- self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt),
- self.default_timeout)
- self.log.error("Found {} event when it wasn't expected".
- format(mtu_changed.format(bluetooth_gatt)))
+ self.cen_ad.ed.pop_event(expected_event, self.default_timeout)
+ self.log.error("Found {} event when it wasn't expected".format(
+ expected_event))
return False
- except Exception:
- self.log.debug("Successfully didn't find {} event"
- .format(mtu_changed.format(bluetooth_gatt)))
+ except Empty:
+ self.log.debug("Successfully didn't find {} event".format(
+ expected_event))
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -395,9 +452,14 @@
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
+ expected_event = GattCbStrings.RD_REMOTE_RSSI.value.format(
+ gatt_callback)
if self.cen_ad.droid.gattClientReadRSSI(bluetooth_gatt):
- self.cen_ad.ed.pop_event(
- read_remote_rssi.format(gatt_callback), self.default_timeout)
+ try:
+ self.cen_ad.ed.pop_event(expected_event, self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.RD_REMOTE_RSSI_ERR.value.format(
+ expected_event))
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -432,14 +494,21 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@BluetoothBaseTest.bt_test_wrap
- def test_gatt_connect_trigger_on_services_discovered_iterate_attributes(self):
+ def test_gatt_connect_trigger_on_services_discovered_iterate_attributes(
+ self):
"""Test GATT connection and iterate peripherals attributes.
Test establishing a gatt connection between a GATT server and GATT
@@ -474,10 +543,16 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
- discovered_services_index = event['data']['ServicesIndex']
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ discovered_services_index = event['data']['ServicesIndex']
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
self._iterate_attributes(discovered_services_index)
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -517,11 +592,19 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
discovered_services_index = event['data']['ServicesIndex']
self._iterate_attributes(discovered_services_index)
+
+ self._cleanup_services(gatt_server)
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -555,19 +638,19 @@
mac_address, adv_callback = get_mac_address_of_generic_advertisement(
self.cen_ad, self.per_ad)
autoconnect = False
- for i in range(20):
+ for i in range(1000):
+ self.log.info("Starting connection iteration {}".format(i + 1))
test_result, bluetooth_gatt, gatt_callback = setup_gatt_connection(
self.cen_ad, mac_address, autoconnect)
if not test_result:
self.log.info("Could not connect to peripheral.")
return False
- test_result = self._orchestrate_gatt_disconnection(
- bluetooth_gatt, gatt_callback)
- # Temporary fix
- time.sleep(3)
+ test_result = self._orchestrate_gatt_disconnection(bluetooth_gatt,
+ gatt_callback)
if not test_result:
self.log.info("Failed to disconnect from peripheral device.")
return False
+ self.adv_instances.append(adv_callback)
return True
@BluetoothBaseTest.bt_test_wrap
@@ -606,9 +689,15 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
discovered_services_index = event['data']['ServicesIndex']
else:
self.log.info("Failed to discover services.")
@@ -624,8 +713,8 @@
bt_device_id = 0
status = 1
offset = 1
- test_value = "1,2,3,4,5,6,7"
- test_value_return = "1,2,3"
+ test_value = [1,2,3,4,5,6,7]
+ test_value_return = [1,2,3]
for i in range(services_count):
characteristic_uuids = (
self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
@@ -636,33 +725,46 @@
discovered_services_index, i, characteristic))
for x in range(100):
for descriptor in descriptor_uuids:
+ self.log.info(
+ "Starting write iteration {} on (Characteristic::Descriptor) {}::{}".format(
+ x + 1, characteristic, descriptor))
self.cen_ad.droid.gattClientDescriptorSetValue(
bluetooth_gatt, discovered_services_index, i,
characteristic, descriptor, test_value)
self.cen_ad.droid.gattClientWriteDescriptor(
bluetooth_gatt, discovered_services_index, i,
characteristic, descriptor)
- event = self.per_ad.ed.pop_event(
- descriptor_write_request.format(
- gatt_server_callback), self.default_timeout)
- self.log.info("{} event found: {}".format(
- descriptor_write_request.format(
- gatt_callback), event))
+ expected_event = GattCbStrings.DESC_WRITE_REQ.value.format(
+ gatt_server_callback)
+ try:
+ event = self.per_ad.ed.pop_event(
+ expected_event, self.default_timeout)
+ except Empty:
+ self.log.error(
+ GattCbErr.DESC_WRITE_REQ_ERR.value.format(
+ expected_event))
+ return False
request_id = event['data']['requestId']
found_value = event['data']['value']
if found_value != test_value:
- self.log.info("Values didn't match. Found: {}, "
- "Expected: {}".format(found_value,
- test_value))
+ self.log.error("Values didn't match. Found: {}, "
+ "Expected: {}".format(found_value,
+ test_value))
return False
self.per_ad.droid.gattServerSendResponse(
gatt_server, bt_device_id, request_id, status,
offset, test_value_return)
- self.log.info("onDescriptorWrite event found: {}"
- .format(
- self.cen_ad.ed.pop_event(
- descriptor_write.format(gatt_callback),
- self.default_timeout)))
+ expected_event = GattCbStrings.DESC_WRITE.value.format(
+ gatt_callback)
+ try:
+ self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(
+ GattCbErr.DESC_WRITE_ERR.value.format(
+ expected_event))
+ return False
+ self._cleanup_services(gatt_server)
return True
@BluetoothBaseTest.bt_test_wrap
@@ -695,56 +797,29 @@
Characteristics, Descriptors
Priority: 1
"""
- gatt_server_callback = self.per_ad.droid.gattServerCreateGattServerCallback(
- )
- gatt_server = self.per_ad.droid.gattServerOpenGattServer(
- gatt_server_callback)
+ gatt_server_callback, gatt_server = self._setup_multiple_services()
+ if not gatt_server_callback or not gatt_server:
+ return False
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
+ self.adv_instances.append(adv_callback)
service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
characteristic_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
- descriptor_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
-
- characteristic = (
- self.per_ad.droid.gattServerCreateBluetoothGattCharacteristic(
- characteristic_uuid,
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE.value))
-
- descriptor = self.per_ad.droid.gattServerCreateBluetoothGattDescriptor(
- descriptor_uuid,
- BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattDescriptor.PERMISSION_WRITE.value,
- )
- self.per_ad.droid.gattServerCharacteristicAddDescriptor(
- characteristic, descriptor)
-
- gatt_service = self.per_ad.droid.gattServerCreateService(
- service_uuid,
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value
- )
-
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
- characteristic)
-
- self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
- result = self._find_service_added_event(
- gatt_server_callback, service_uuid)
- if not result:
- return False
-
- bluetooth_gatt, gatt_callback, adv_callback = (
- orchestrate_gatt_connection(self.cen_ad, self.per_ad))
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
discovered_services_index = event['data']['ServicesIndex']
services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
- disc_service_index = 0
+ disc_service_index = None
for i in range(services_count):
disc_service_uuid = (
self.cen_ad.droid.gattClientGetDiscoveredServiceUuid(
@@ -753,55 +828,51 @@
disc_service_index = i
break
- self.cen_ad.droid.gattClientSetCharacteristicNotification(
- gatt_callback,
- discovered_services_index,
- disc_service_index,
- characteristic_uuid,
- True
- )
+ test_value = [1,2,3,4,5,6,7]
- test_value = "1,2,3,4,5,6,7"
self.cen_ad.droid.gattClientCharacteristicSetValue(
- bluetooth_gatt,
- discovered_services_index,
- disc_service_index,
- characteristic_uuid,
- test_value
- )
+ bluetooth_gatt, discovered_services_index, disc_service_index,
+ characteristic_uuid, test_value)
self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt,
- discovered_services_index,
- disc_service_index,
- characteristic_uuid
- )
+ bluetooth_gatt, discovered_services_index, disc_service_index,
+ characteristic_uuid)
- event = self.per_ad.ed.pop_event(
- characteristic_write_request.format(gatt_server_callback),
- self.default_timeout
- )
+ expected_event = GattCbStrings.CHAR_WRITE_REQ.value.format(
+ gatt_server_callback)
+ try:
+ event = self.per_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.CHAR_WRITE_REQ_ERR.value.format(
+ expected_event))
+ return False
request_id = event['data']['requestId']
bt_device_id = 0
- status = 1
- offset = 1
- test_value_return = "1,2,3"
+ status = 0
+ offset = 0
+ test_value_return = [1,2,3]
self.per_ad.droid.gattServerGetConnectedDevices(gatt_server)
- self.per_ad.droid.gattServerSendResponse(
- gatt_server,
- bt_device_id,
- request_id,
- status,
- offset,
- test_value_return
- )
+ self.per_ad.droid.gattServerSendResponse(gatt_server, bt_device_id,
+ request_id, status, offset,
+ test_value_return)
- self.cen_ad.ed.pop_event(
- characteristic_write.format(bluetooth_gatt),
- self.default_timeout
- )
- return True
+ expected_event = GattCbStrings.CHAR_WRITE.value.format(gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event, self.default_timeout)
+ if event["data"]["Status"] != status:
+ self.log.error("Write status should be 0")
+ return False;
+
+ except Empty:
+ self.log.error(GattCbErr.CHAR_WRITE_ERR.value.format(
+ expected_event))
+ return False
+
+ self._cleanup_services(gatt_server)
+ return self._orchestrate_gatt_disconnection(bluetooth_gatt,
+ gatt_callback)
@BluetoothBaseTest.bt_test_wrap
def test_write_characteristic_stress(self):
@@ -839,10 +910,20 @@
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
+
+ service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
+ characteristic_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
+
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
discovered_services_index = event['data']['ServicesIndex']
else:
self.log.info("Failed to discover services.")
@@ -850,63 +931,76 @@
services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
+ disc_service_index = None
+ for i in range(services_count):
+ disc_service_uuid = (
+ self.cen_ad.droid.gattClientGetDiscoveredServiceUuid(
+ discovered_services_index, i).upper())
+ if disc_service_uuid == service_uuid:
+ disc_service_index = i
+ break
+
+ self.cen_ad.droid.gattClientRequestConnectionPriority(
+ bluetooth_gatt, GattConnectionPriority.CONNECTION_PRIORITY_HIGH.value)
+
connected_device_list = self.per_ad.droid.gattServerGetConnectedDevices(
gatt_server)
if len(connected_device_list) == 0:
self.log.info("No devices connected from peripheral.")
return False
bt_device_id = 0
- status = 1
- offset = 1
- test_value = "1,2,3,4,5,6,7"
- test_value_return = "1,2,3"
- for i in range(services_count):
- characteristic_uuids = (
- self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
- discovered_services_index, i))
- for i in range(100):
- for characteristic in characteristic_uuids:
- self.cen_ad.droid.gattClientCharacteristicSetValue(
- bluetooth_gatt, discovered_services_index, i,
- characteristic, test_value)
- self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic)
- self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic)
- self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic)
- self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic)
- time.sleep(8)
- event = self.per_ad.ed.pop_event(
- characteristic_write_request.format(
- gatt_server_callback), self.default_timeout)
- self.log.info("{} event found: {}".format(
- characteristic_write_request.format(
- gatt_server_callback), event))
- request_id = event['data']['requestId']
- found_value = event['data']['value']
- if found_value != test_value:
- self.log.info("Values didn't match. Found: {}, "
- "Expected: {}".format(found_value,
- test_value))
- return False
- self.per_ad.droid.gattServerSendResponse(
- gatt_server, bt_device_id, request_id, status, offset,
- test_value_return)
- self.log.info(
- "onCharacteristicWrite event found: {}".format(
- characteristic_write_request.format(
- gatt_server_callback),
- self.cen_ad.ed.pop_event(
- characteristic_write.format(bluetooth_gatt),
- self.default_timeout)))
- return True
+ status = 0
+ offset = 0
+ test_value = [1,2,3,4,5,6,7]
+ test_value_return = [1,2,3]
+ for i in range(100):
+ self.cen_ad.droid.gattClientCharacteristicSetValue(
+ bluetooth_gatt, discovered_services_index,
+ disc_service_index, characteristic_uuid, test_value)
+ self.cen_ad.droid.gattClientWriteCharacteristic(
+ bluetooth_gatt, discovered_services_index,
+ disc_service_index, characteristic_uuid)
+ expected_event = GattCbStrings.CHAR_WRITE_REQ.value.format(
+ gatt_server_callback)
+ try:
+ event = self.per_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(
+ GattCbErr.CHAR_WRITE_REQ_ERR.value.format(
+ expected_event))
+ return False
+
+ self.log.info("{} event found: {}".format(
+ GattCbStrings.CHAR_WRITE_REQ.value.format(
+ gatt_server_callback), event))
+ request_id = event['data']['requestId']
+ found_value = event['data']['value']
+ if found_value != test_value:
+ self.log.info("Values didn't match. Found: {}, "
+ "Expected: {}".format(found_value,
+ test_value))
+ return False
+ self.per_ad.droid.gattServerSendResponse(
+ gatt_server, bt_device_id, request_id, status, offset,
+ test_value_return)
+ expected_event = GattCbStrings.CHAR_WRITE.value.format(
+ gatt_callback)
+ try:
+ self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(
+ GattCbErr.CHAR_WRITE_ERR.value.format(
+ expected_event))
+ return False
+
+ self._cleanup_services(gatt_server)
+ return self._orchestrate_gatt_disconnection(bluetooth_gatt,
+ gatt_callback)
+
+ @BluetoothBaseTest.bt_test_wrap
def test_gatt_connect_mitm_attack(self):
"""Test GATT connection with permission write encrypted mitm.
@@ -919,8 +1013,8 @@
1. Create a GATT server and server callback on the peripheral device.
2. Create a unique service and characteristic uuid on the peripheral.
3. Create a characteristic on the peripheral with these properties:
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
+ GattCharacteristic.PROPERTY_WRITE.value,
+ GattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
4. Create a GATT service on the peripheral.
5. Add the characteristic to the GATT service.
6. Create a GATT connection between your central and peripheral device.
@@ -946,144 +1040,29 @@
TAGS: LE, Advertising, Filtering, Scanning, GATT, Characteristic, MITM
Priority: 1
"""
- gatt_server_callback = (
- self.per_droid.gattServerCreateGattServerCallback())
- gatt_server = self.per_droid.gattServerOpenGattServer(
- gatt_server_callback)
- service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
- test_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
+ gatt_server_callback, gatt_server = self._setup_multiple_services()
+ if not gatt_server_callback or not gatt_server:
+ return False
bonded = False
- characteristic = self.per_droid.gattServerCreateBluetoothGattCharacteristic(
- test_uuid,
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- )
- gatt_service = self.per_droid.gattServerCreateService(
- service_uuid,
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value
- )
- self.per_droid.gattServerAddCharacteristicToService(
- gatt_service, characteristic)
- self.per_droid.gattServerAddService(gatt_server, gatt_service)
- result = self._find_service_added_event(
- gatt_server_callback,
- service_uuid)
- if not result:
- return False
- bluetooth_gatt, gatt_callback, adv_callback = (
- orchestrate_gatt_connection(self.cen_droid, self.cen_ed,
- self.per_droid, self.per_ed))
- self.adv_instances.append(adv_callback)
- if self.cen_droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
- discovered_services_index = event['data']['ServicesIndex']
- else:
- self.log.info("Failed to discover services.")
- return False
- test_value = "1,2,3,4,5,6,7"
- services_count = self.cen_droid.gattClientGetDiscoveredServicesCount(
- discovered_services_index)
- for i in range(services_count):
- characteristic_uuids = (
- self.cen_droid.gattClientGetDiscoveredCharacteristicUuids(
- discovered_services_index, i))
- for characteristic_uuid in characteristic_uuids:
- if characteristic_uuid == test_uuid:
- self.cen_droid.bluetoothStartPairingHelper()
- self.per_droid.bluetoothStartPairingHelper()
- self.cen_droid.gattClientCharacteristicSetValue(
- bluetooth_gatt, discovered_services_index, i,
- characteristic_uuid, test_value)
- self.cen_droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic_uuid)
- start_time = time.time() + self.default_timeout
- target_name = self.per_droid.bluetoothGetLocalName()
- while time.time() < start_time and bonded == False:
- bonded_devices = self.cen_droid.bluetoothGetBondedDevices()
- for device in bonded_devices:
- if 'name' in device.keys() and device['name'] == target_name:
- bonded = True
- break
- return True
-
- def test_gatt_connect_mitm_attack(self):
- """Test GATT connection with permission write encrypted mitm.
-
- Test establishing a gatt connection between a GATT server and GATT
- client while the GATT server's characteristic includes the property
- write value and the permission write encrypted mitm value. This will
- prompt LE pairing and then the devices will create a bond.
-
- Steps:
- 1. Create a GATT server and server callback on the peripheral device.
- 2. Create a unique service and characteristic uuid on the peripheral.
- 3. Create a characteristic on the peripheral with these properties:
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- 4. Create a GATT service on the peripheral.
- 5. Add the characteristic to the GATT service.
- 6. Create a GATT connection between your central and peripheral device.
- 7. From the central device, discover the peripheral's services.
- 8. Iterate the services found until you find the unique characteristic
- created in step 3.
- 9. Once found, write a random but valid value to the characteristic.
- 10. Start pairing helpers on both devices immediately after attempting
- to write to the characteristic.
- 11. Within 10 seconds of writing the characteristic, there should be
- a prompt to bond the device from the peripheral. The helpers will
- handle the UI interaction automatically. (see
- BluetoothConnectionFacade.java bluetoothStartPairingHelper).
- 12. Verify that the two devices are bonded.
-
- Expected Result:
- Verify that a connection was established and the devices are bonded.
-
- Returns:
- Pass if True
- Fail if False
-
- TAGS: LE, Advertising, Filtering, Scanning, GATT, Characteristic, MITM
- Priority: 1
- """
- gatt_server_callback = (
- self.per_ad.droid.gattServerCreateGattServerCallback())
- gatt_server = self.per_ad.droid.gattServerOpenGattServer(
- gatt_server_callback)
- service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
test_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
- bonded = False
- characteristic = self.per_ad.droid.gattServerCreateBluetoothGattCharacteristic(
- test_uuid,
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- )
- gatt_service = self.per_ad.droid.gattServerCreateService(
- service_uuid,
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value
- )
- self.per_ad.droid.gattServerAddCharacteristicToService(
- gatt_service, characteristic)
- self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
- result = self._find_service_added_event(
- gatt_server_callback,
- service_uuid)
- if not result:
- return False
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.adv_instances.append(adv_callback)
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
+ expected_event = GattCbStrings.GATT_SERV_DISC.value.format(
+ gatt_callback)
+ try:
+ event = self.cen_ad.ed.pop_event(expected_event,
+ self.default_timeout)
+ except Empty:
+ self.log.error(GattCbErr.GATT_SERV_DISC_ERR.value.format(
+ expected_event))
+ return False
discovered_services_index = event['data']['ServicesIndex']
else:
self.log.info("Failed to discover services.")
return False
- test_value = "1,2,3,4,5,6,7"
+ test_value = [1,2,3,4,5,6,7]
services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
for i in range(services_count):
@@ -1103,110 +1082,14 @@
start_time = time.time() + self.default_timeout
target_name = self.per_ad.droid.bluetoothGetLocalName()
while time.time() < start_time and bonded == False:
- bonded_devices = self.cen_ad.droid.bluetoothGetBondedDevices()
+ bonded_devices = self.cen_ad.droid.bluetoothGetBondedDevices(
+ )
for device in bonded_devices:
- if 'name' in device.keys() and device['name'] == target_name:
+ if 'name' in device.keys() and device[
+ 'name'] == target_name:
bonded = True
break
- return True
+ self._cleanup_services(gatt_server)
+ return self._orchestrate_gatt_disconnection(bluetooth_gatt,
+ gatt_callback)
- def test_gatt_connect_mitm_attack(self):
- """Test GATT connection with permission write encrypted mitm.
-
- Test establishing a gatt connection between a GATT server and GATT
- client while the GATT server's characteristic includes the property
- write value and the permission write encrypted mitm value. This will
- prompt LE pairing and then the devices will create a bond.
-
- Steps:
- 1. Create a GATT server and server callback on the peripheral device.
- 2. Create a unique service and characteristic uuid on the peripheral.
- 3. Create a characteristic on the peripheral with these properties:
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- 4. Create a GATT service on the peripheral.
- 5. Add the characteristic to the GATT service.
- 6. Create a GATT connection between your central and peripheral device.
- 7. From the central device, discover the peripheral's services.
- 8. Iterate the services found until you find the unique characteristic
- created in step 3.
- 9. Once found, write a random but valid value to the characteristic.
- 10. Start pairing helpers on both devices immediately after attempting
- to write to the characteristic.
- 11. Within 10 seconds of writing the characteristic, there should be
- a prompt to bond the device from the peripheral. The helpers will
- handle the UI interaction automatically. (see
- BluetoothConnectionFacade.java bluetoothStartPairingHelper).
- 12. Verify that the two devices are bonded.
-
- Expected Result:
- Verify that a connection was established and the devices are bonded.
-
- Returns:
- Pass if True
- Fail if False
-
- TAGS: LE, Advertising, Filtering, Scanning, GATT, Characteristic, MITM
- Priority: 1
- """
- gatt_server_callback = (
- self.per_ad.droid.gattServerCreateGattServerCallback())
- gatt_server = self.per_ad.droid.gattServerOpenGattServer(
- gatt_server_callback)
- service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
- test_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
- bonded = False
- characteristic = self.per_ad.droid.gattServerCreateBluetoothGattCharacteristic(
- test_uuid,
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- )
- gatt_service = self.per_ad.droid.gattServerCreateService(
- service_uuid,
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value
- )
- self.per_ad.droid.gattServerAddCharacteristicToService(
- gatt_service, characteristic)
- self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
- result = self._find_service_added_event(
- gatt_server_callback,
- service_uuid)
- if not result:
- return False
- bluetooth_gatt, gatt_callback, adv_callback = (
- orchestrate_gatt_connection(self.cen_ad, self.per_ad))
- self.adv_instances.append(adv_callback)
- if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
- event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
- self.default_timeout)
- discovered_services_index = event['data']['ServicesIndex']
- else:
- self.log.info("Failed to discover services.")
- return False
- test_value = "1,2,3,4,5,6,7"
- services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
- discovered_services_index)
- for i in range(services_count):
- characteristic_uuids = (
- self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
- discovered_services_index, i))
- for characteristic_uuid in characteristic_uuids:
- if characteristic_uuid == test_uuid:
- self.cen_ad.droid.bluetoothStartPairingHelper()
- self.per_ad.droid.bluetoothStartPairingHelper()
- self.cen_ad.droid.gattClientCharacteristicSetValue(
- bluetooth_gatt, discovered_services_index, i,
- characteristic_uuid, test_value)
- self.cen_ad.droid.gattClientWriteCharacteristic(
- bluetooth_gatt, discovered_services_index, i,
- characteristic_uuid)
- start_time = time.time() + self.default_timeout
- target_name = self.per_ad.droid.bluetoothGetLocalName()
- while time.time() < start_time and bonded == False:
- bonded_devices = self.cen_ad.droid.bluetoothGetBondedDevices()
- for device in bonded_devices:
- if 'name' in device.keys() and device['name'] == target_name:
- bonded = True
- break
- return True
diff --git a/acts/tests/google/ble/scan/BleBackgroundScanTest.py b/acts/tests/google/ble/scan/BleBackgroundScanTest.py
index 9f8f440..cc3df3a 100644
--- a/acts/tests/google/ble/scan/BleBackgroundScanTest.py
+++ b/acts/tests/google/ble/scan/BleBackgroundScanTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises background scan test scenarios.
"""
@@ -33,7 +32,6 @@
class BleBackgroundScanTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
max_scan_instances = 28
report_delay = 2000
@@ -50,10 +48,6 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_background_scan",
- "test_background_scan_ble_disabled",
- )
def setup_test(self):
self.log.debug(log_energy_info(self.android_devices, "Start"))
@@ -61,23 +55,23 @@
BluetoothAdapterState.STATE_OFF.value):
self.scn_ad.droid.bluetoothEnableBLE()
self.scn_ad.ed.pop_event("BleStateChangedOn")
- for e in self.eds:
- e.clear_all_events()
+ for a in self.android_devices:
+ a.ed.clear_all_events()
return True
def teardown_test(self):
self.log.debug(log_energy_info(self.android_devices, "End"))
cleanup_scanners_and_advertisers(
- self.scn_ad, self.active_adv_callback_list,
- self.adv_ad, self.active_adv_callback_list)
+ self.scn_ad, self.active_adv_callback_list, self.adv_ad,
+ self.active_adv_callback_list)
self.active_adv_callback_list = []
self.active_scan_callback_list = []
def _setup_generic_advertisement(self):
adv_callback, adv_data, adv_settings = generate_ble_advertise_objects(
self.adv_ad.droid)
- self.adv_ad.droid.bleStartBleAdvertising(
- adv_callback, adv_data, adv_settings)
+ self.adv_ad.droid.bleStartBleAdvertising(adv_callback, adv_data,
+ adv_settings)
self.active_adv_callback_list.append(adv_callback)
def _verify_no_events_found(self, event_name):
@@ -89,10 +83,6 @@
self.log.info("No scan result found as expected.")
return True
- def _delete_me(self):
- import time
- time.sleep(5)
-
@BluetoothBaseTest.bt_test_wrap
def test_background_scan(self):
"""Test generic background scan.
@@ -120,18 +110,36 @@
import time
self._setup_generic_advertisement()
self.scn_ad.droid.bluetoothToggleState(False)
- self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
+ try:
+ self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
+ except Empty:
+ self.log.error("Bluetooth Off event not found. Expected {}".format(
+ bluetooth_off))
+ return False
self.scn_ad.droid.bluetoothDisableBLE()
- self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
+ try:
+ self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
+ except Empty:
+ self.log.error("Bluetooth Off event not found. Expected {}".format(
+ bluetooth_off))
+ return False
self.scn_ad.droid.bluetoothEnableBLE()
- self._delete_me()
- self.scn_ad.ed.pop_event(bluetooth_on, self.default_timeout * 2)
+ try:
+ self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout*2)
+ except Empty:
+ self.log.error("Bluetooth On event not found. Expected {}".format(
+ bluetooth_on))
+ return False
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
- self.scn_ad.ed.pop_event(
- scan_result.format(scan_callback), self.default_timeout)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
+ expected_event = scan_result.format(scan_callback)
+ try:
+ self.scn_ad.ed.pop_event(expected_event, self.default_timeout)
+ except Empty:
+ self.log.error("Scan Result event not found. Expected {}".format(expected_event))
+ return False
return True
@BluetoothBaseTest.bt_test_wrap
@@ -161,14 +169,23 @@
self._setup_generic_advertisement()
self.scn_ad.droid.bluetoothEnableBLE()
self.scn_ad.droid.bluetoothToggleState(False)
- self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
- self._delete_me()
+ try:
+ self.scn_ad.ed.pop_event(bluetooth_off, self.default_timeout)
+ except Empty:
+ self.log.error("Bluetooth Off event not found. Expected {}".format(
+ bluetooth_off))
+ return False
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
try:
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
- self.scn_ad.ed.pop_event(scan_result.format(scan_callback))
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
+ expected_event = scan_result.format(scan_callback)
+ try:
+ self.scn_ad.ed.pop_event(expected_event, self.default_timeout)
+ except Empty:
+ self.log.error("Scan Result event not found. Expected {}".format(expected_event))
+ return False
self.log.info("Was able to start background scan even though ble "
"was disabled.")
return False
diff --git a/acts/tests/google/ble/scan/BleOnLostOnFoundTest.py b/acts/tests/google/ble/scan/BleOnLostOnFoundTest.py
index 60f8a45..4cd72dc 100644
--- a/acts/tests/google/ble/scan/BleOnLostOnFoundTest.py
+++ b/acts/tests/google/ble/scan/BleOnLostOnFoundTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises different onLost/onFound scenarios.
"""
@@ -34,7 +33,6 @@
class BleOnLostOnFoundTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
max_scan_instances = 28
active_scan_callback_list = []
@@ -48,17 +46,12 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_onlost_onfound_defaults",
- "test_onlost_onfound_match_mode_sticky",
- "test_onlost_onfound_match_num_few",
- )
def teardown_test(self):
- self.log.info(log_energy_info(self.droids, "End"))
+ self.log.info(log_energy_info(self.android_devices, "End"))
cleanup_scanners_and_advertisers(
- self.scn_ad, self.active_adv_callback_list,
- self.adv_ad, self.active_adv_callback_list)
+ self.scn_ad, self.active_adv_callback_list, self.adv_ad,
+ self.active_adv_callback_list)
self.active_adv_callback_list = []
self.active_scan_callback_list = []
@@ -74,8 +67,8 @@
advertise_callback = self.adv_ad.droid.bleGenBleAdvertiseCallback()
self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- self.adv_ad.ed.pop_event(adv_succ.format(advertise_callback),
- self.default_timeout)
+ self.adv_ad.ed.pop_event(
+ adv_succ.format(advertise_callback), self.default_timeout)
self.active_adv_callback_list.append(advertise_callback)
return advertise_callback
@@ -130,24 +123,29 @@
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
adv_callback = self._start_generic_advertisement_include_device_name()
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 3)
found_callback_type = event['data']['CallbackType']
- if event['data']['CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
- self.log.info("Found Callbacreset_bluetoothkType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
+ if event['data'][
+ 'CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
+ self.log.info(
+ "Found Callbacreset_bluetoothkType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
return False
self.adv_ad.droid.bleStopBleAdvertising(adv_callback)
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 4)
found_callback_type = event['data']['CallbackType']
if found_callback_type != ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value:
- self.log.info("Found CallbackType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
+ self.log.info(
+ "Found CallbackType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
return False
return True
@@ -193,24 +191,29 @@
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
adv_callback = self._start_generic_advertisement_include_device_name()
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 3)
found_callback_type = event['data']['CallbackType']
- if event['data']['CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
- self.log.info("Found CallbackType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
+ if event['data'][
+ 'CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
+ self.log.info(
+ "Found CallbackType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
return False
self.adv_ad.droid.bleStopBleAdvertising(adv_callback)
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 4)
found_callback_type = event['data']['CallbackType']
if found_callback_type != ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value:
- self.log.info("Found CallbackType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
+ self.log.info(
+ "Found CallbackType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
return False
return True
@@ -256,23 +259,28 @@
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
adv_callback = self._start_generic_advertisement_include_device_name()
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 3)
found_callback_type = event['data']['CallbackType']
- if event['data']['CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
- self.log.info("Found CallbackType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
+ if event['data'][
+ 'CallbackType'] != ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value:
+ self.log.info(
+ "Found CallbackType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value))
return False
self.adv_ad.droid.bleStopBleAdvertising(adv_callback)
event = self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout * 4)
found_callback_type = event['data']['CallbackType']
if found_callback_type != ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value:
- self.log.info("Found CallbackType:{}, Expected CallbackType:{}".format(
- found_callback_type, ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
+ self.log.info(
+ "Found CallbackType:{}, Expected CallbackType:{}".format(
+ found_callback_type,
+ ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value))
return False
return True
diff --git a/acts/tests/google/ble/scan/BleOpportunisticScanTest.py b/acts/tests/google/ble/scan/BleOpportunisticScanTest.py
index 0474041..f6c0ce5 100644
--- a/acts/tests/google/ble/scan/BleOpportunisticScanTest.py
+++ b/acts/tests/google/ble/scan/BleOpportunisticScanTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
This test script exercises different opportunistic scan scenarios.
It is expected that the second AndroidDevice is able to advertise.
@@ -37,7 +36,6 @@
class BleOpportunisticScanTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
max_scan_instances = 28
report_delay = 2000
@@ -67,14 +65,13 @@
)
if self.droid_list[0]['batch_scan_supported']:
self.tests = self.tests + (
- "test_batch_scan_result",
- "test_max_opportunistic_batch_scan_instances",
- )
+ "test_batch_scan_result",
+ "test_max_opportunistic_batch_scan_instances", )
def teardown_test(self):
cleanup_scanners_and_advertisers(
- self.scn_ad, self.active_adv_callback_list,
- self.adv_ad, self.active_adv_callback_list)
+ self.scn_ad, self.active_adv_callback_list, self.adv_ad,
+ self.active_adv_callback_list)
self.active_adv_callback_list = []
self.active_scan_callback_list = []
@@ -84,15 +81,15 @@
def _setup_generic_advertisement(self):
adv_callback, adv_data, adv_settings = generate_ble_advertise_objects(
self.adv_ad.droid)
- self.adv_ad.droid.bleStartBleAdvertising(
- adv_callback, adv_data, adv_settings)
+ self.adv_ad.droid.bleStartBleAdvertising(adv_callback, adv_data,
+ adv_settings)
self.active_adv_callback_list.append(adv_callback)
def _verify_no_events_found(self, event_name):
try:
event = self.scn_ad.ed.pop_event(event_name, self.default_timeout)
- self.log.error(
- "Found an event when none was expected: {}".format(event))
+ self.log.error("Found an event when none was expected: {}".format(
+ event))
return False
except Empty:
self.log.info("No scan result found as expected.")
@@ -124,8 +121,8 @@
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
@@ -158,14 +155,15 @@
"""
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value)
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(batch_scan_result.format(
- scan_callback)):
+ scan_callback)):
return False
self.scn_ad.droid.bleStopBleScan(scan_callback)
return True
@@ -202,8 +200,8 @@
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
@@ -211,8 +209,8 @@
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback2), self.default_timeout)
@@ -253,23 +251,25 @@
self._setup_generic_advertisement()
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value)
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(batch_scan_result.format(
- scan_callback)):
+ scan_callback)):
return False
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2 = self.scn_ad.droid.bleGenFilterList()
scan_settings2 = self.scn_ad.droid.bleBuildScanSetting()
scan_callback2 = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
batch_scan_result.format(scan_callback2), self.default_timeout)
@@ -311,22 +311,23 @@
self._setup_generic_advertisement()
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value)
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(batch_scan_result.format(
- scan_callback)):
+ scan_callback)):
return False
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback2), self.default_timeout)
@@ -367,18 +368,19 @@
filter_list = self.scn_ad.droid.bleGenFilterList()
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
batch_scan_result.format(scan_callback2), self.default_timeout)
@@ -418,16 +420,16 @@
filter_list = self.scn_ad.droid.bleGenFilterList()
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
for callback in self.active_scan_callback_list:
@@ -473,17 +475,18 @@
filter_list = self.scn_ad.droid.bleGenFilterList()
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
self.scn_ad.droid.bleSetScanSettingsScanMode(
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
- self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(self.report_delay)
+ self.scn_ad.droid.bleSetScanSettingsReportDelayMillis(
+ self.report_delay)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
for callback in self.active_scan_callback_list:
@@ -493,7 +496,8 @@
return True
@BluetoothBaseTest.bt_test_wrap
- def test_discover_opportunistic_scan_result_off_secondary_scan_filter(self):
+ def test_discover_opportunistic_scan_result_off_secondary_scan_filter(
+ self):
"""Test opportunistic scan result from secondary scan filter.
Tests opportunistic scan where the secondary scan instance does not find
@@ -528,8 +532,8 @@
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
@@ -539,17 +543,19 @@
generate_ble_scan_objects(self.scn_ad.droid))
self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test")
self.scn_ad.droid.bleBuildScanFilter(filter_list2)
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
- if not self._verify_no_events_found(scan_result.format(scan_callback2)):
+ if not self._verify_no_events_found(scan_result.format(
+ scan_callback2)):
return False
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback), self.default_timeout)
return True
@BluetoothBaseTest.bt_test_wrap
- def test_negative_opportunistic_scan_filter_result_off_secondary_scan_result(self):
+ def test_negative_opportunistic_scan_filter_result_off_secondary_scan_result(
+ self):
"""Test opportunistic scan not found scenario.
Tests opportunistic scan where the secondary scan instance does find an
@@ -585,8 +591,8 @@
self.scn_ad.droid)
self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test")
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
@@ -594,8 +600,8 @@
ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
filter_list2, scan_settings2, scan_callback2 = (
generate_ble_scan_objects(self.scn_ad.droid))
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback2), self.default_timeout)
@@ -640,8 +646,8 @@
self.scn_ad.droid)
self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name)
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
if not self._verify_no_events_found(scan_result.format(scan_callback)):
return False
@@ -651,8 +657,8 @@
generate_ble_scan_objects(self.scn_ad.droid))
self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name)
self.scn_ad.droid.bleBuildScanFilter(filter_list2)
- self.scn_ad.droid.bleStartBleScan(
- filter_list2, scan_settings2, scan_callback2)
+ self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2,
+ scan_callback2)
self.active_scan_callback_list.append(scan_callback2)
self.scn_ad.ed.pop_event(
scan_result.format(scan_callback2), self.default_timeout)
diff --git a/acts/tests/google/ble/scan/DeathToBluetoothTest.py b/acts/tests/google/ble/scan/DeathToBluetoothTest.py
index 9b20dee..4cb9f83 100644
--- a/acts/tests/google/ble/scan/DeathToBluetoothTest.py
+++ b/acts/tests/google/ble/scan/DeathToBluetoothTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
"""
@@ -38,9 +37,7 @@
BluetoothBaseTest.__init__(self, controllers)
self.droid_list = get_advanced_droid_list(self.android_devices)
self.scn_ad = self.android_devices[0]
- self.tests = (
- "test_death",
- )
+ self.tests = ("test_death", )
def teardown_test(self):
self.active_adv_callback_list = []
@@ -55,8 +52,8 @@
def _setup_generic_advertisement(self):
adv_callback, adv_data, adv_settings = generate_ble_advertise_objects(
self.adv_droid)
- self.adv_droid.bleStartBleAdvertising(
- adv_callback, adv_data, adv_settings)
+ self.adv_droid.bleStartBleAdvertising(adv_callback, adv_data,
+ adv_settings)
self.active_adv_callback_list.append(adv_callback)
def _verify_no_events_found(self, event_name):
@@ -85,8 +82,8 @@
self.scn_ad.droid.bleSetScanSettingsNumOfMatches(1)
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
for _ in range(10000):
self.scn_ad.ed.pop_event(scan_result.format(scan_callback))
return True
diff --git a/acts/tests/google/ble/system_tests/BleOnLostOnFoundStressTest.py b/acts/tests/google/ble/system_tests/BleOnLostOnFoundStressTest.py
index e3c9f4e..04d5cfd 100644
--- a/acts/tests/google/ble/system_tests/BleOnLostOnFoundStressTest.py
+++ b/acts/tests/google/ble/system_tests/BleOnLostOnFoundStressTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
OnLost onFound Stress Test.
"""
@@ -30,14 +29,13 @@
from acts.test_utils.bt.BleEnum import ScanSettingsMatchNum
from acts.test_utils.bt.bt_test_utils import cleanup_scanners_and_advertisers
from acts.test_utils.bt.bt_test_utils import get_advanced_droid_list
-from acts.test_utils.bt.bt_test_utils import orchestrate_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import orchestrate_gatt_connection
from acts.test_utils.bt.bt_test_utils import reset_bluetooth
-from acts.test_utils.bt.bt_test_utils import run_continuous_write_descriptor
-from acts.test_utils.bt.bt_test_utils import setup_multiple_services
+from acts.test_utils.bt.bt_gatt_utils import run_continuous_write_descriptor
+from acts.test_utils.bt.bt_gatt_utils import setup_multiple_services
class BleOnLostOnFoundStressTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
max_scan_instances = 28
report_delay = 2000
@@ -54,15 +52,11 @@
if self.droid_list[1]['max_advertisements'] == 0:
self.tests = ()
return
- self.tests = (
- "test_on_star_while_polling_energy_stats",
- "test_more_stress_test",
- )
def teardown_test(self):
cleanup_scanners_and_advertisers(
- self.scn_ad, self.active_adv_callback_list,
- self.scn_ad, self.active_adv_callback_list)
+ self.scn_ad, self.active_adv_callback_list, self.scn_ad,
+ self.active_adv_callback_list)
self.active_adv_callback_list = []
self.active_scan_callback_list = []
@@ -125,8 +119,8 @@
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
on_found_count = 0
on_lost_count = 0
@@ -159,8 +153,7 @@
gatt_server_callback, gatt_server = setup_multiple_services(
self.adv_ad)
bluetooth_gatt, gatt_callback, adv_callback = (
- orchestrate_gatt_connection(self.scn_ad.droid, self.scn_ad.ed,
- self.adv_ad.droid, self.adv_ad.ed))
+ orchestrate_gatt_connection(self.scn_ad, self.adv_ad))
self.active_scan_callback_list.append(adv_callback)
if self.scn_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.scn_ad.ed.pop_event(
@@ -173,10 +166,10 @@
services_count = self.scn_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
thread = threading.Thread(
- target=run_continuous_write_descriptor, args=(
- self.scn_ad.droid, self.scn_ad.ed, self.adv_ad.droid, self.adv_ad.ed,
- gatt_server, gatt_server_callback, bluetooth_gatt,
- services_count, discovered_services_index))
+ target=run_continuous_write_descriptor,
+ args=(self.scn_ad.droid, self.scn_ad.ed, self.adv_ad.droid,
+ self.adv_ad.ed, gatt_server, gatt_server_callback,
+ bluetooth_gatt, services_count, discovered_services_index))
thread.start()
thread2 = threading.Thread(target=self._poll_energy)
thread2.start()
@@ -195,8 +188,8 @@
scan_settings = self.scn_ad.droid.bleBuildScanSetting()
scan_callback = self.scn_ad.droid.bleGenScanCallback()
self.scn_ad.droid.bleBuildScanFilter(filter_list)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.active_scan_callback_list.append(scan_callback)
on_found_count = 0
on_lost_count = 0
diff --git a/acts/tests/google/ble/system_tests/BleStressTest.py b/acts/tests/google/ble/system_tests/BleStressTest.py
index a4a1777..e0df616 100644
--- a/acts/tests/google/ble/system_tests/BleStressTest.py
+++ b/acts/tests/google/ble/system_tests/BleStressTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Basic LE Stress tests.
"""
@@ -30,8 +29,8 @@
from acts.test_utils.bt.bt_test_utils import reset_bluetooth
from acts.test_utils.bt.bt_test_utils import scan_result
+
class BleStressTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
def __init__(self, controllers):
@@ -39,16 +38,16 @@
self.droid_list = get_advanced_droid_list(self.android_devices)
self.scn_ad = self.android_devices[0]
self.adv_ad = self.android_devices[1]
- self.tests = (
- "test_loop_scanning_1000",
- "test_restart_scan_callback_after_bt_toggle",
- "test_start_le_scan_while_toggling_bt",
- )
+ self.tests = ("test_loop_scanning_1000",
+ "test_restart_scan_callback_after_bt_toggle",
+ "test_start_le_scan_while_toggling_bt", )
if self.droid_list[0]['max_advertisements'] > 0:
- self.tests = self.tests + ("test_loop_advertising_100",
- "test_restart_advertise_callback_after_bt_toggle",)
+ self.tests = self.tests + (
+ "test_loop_advertising_100",
+ "test_restart_advertise_callback_after_bt_toggle", )
if self.droid_list[1]['max_advertisements'] >= 4:
- self.tests = self.tests + ("test_loop_scanning_100_verify_no_hci_timeout",)
+ self.tests = self.tests + (
+ "test_loop_scanning_100_verify_no_hci_timeout", )
def bleadvertise_verify_onsuccess_handler(self, event):
test_result = True
@@ -79,13 +78,12 @@
TAGS: LE, Scanning, Stress
Priority: 1
"""
- scan_droid, scan_event_dispatcher = self.droid, self.ed
test_result = True
for _ in range(1000):
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
- scan_droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
+ self.scn_ad.droid)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
self.scn_ad.droid.bleStopBleScan(scan_callback)
return test_result
@@ -116,15 +114,15 @@
for _ in range(self.droid_list[1]['max_advertisements']):
adv_callback, adv_data, adv_settings = generate_ble_advertise_objects(
self.adv_ad.droid)
- self.adv_ad.droid.bleStartBleAdvertising(
- adv_callback, adv_data, adv_settings)
+ self.adv_ad.droid.bleStartBleAdvertising(adv_callback, adv_data,
+ adv_settings)
for _ in range(100):
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
self.scn_ad.droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
- self.log.info(self.scn_ad.ed.pop_event(
- scan_result.format(scan_callback)))
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
+ self.log.info(self.scn_ad.ed.pop_event(scan_result.format(
+ scan_callback)))
self.scn_ad.droid.bleStopBleScan(scan_callback)
time.sleep(1)
return True
@@ -151,31 +149,30 @@
TAGS: LE, Advertising, Stress
Priority: 1
"""
- advertise_droid, advertise_event_dispatcher = self.droid, self.ed
test_result = True
for _ in range(100):
advertise_callback, advertise_data, advertise_settings = generate_ble_advertise_objects(
- advertise_droid)
- advertise_droid.bleStartBleAdvertising(
+ self.adv_ad.droid)
+ self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- expected_advertise_event_name = "".join(
- ["BleAdvertise", str(advertise_callback), "onSuccess"])
- worker = advertise_event_dispatcher.handle_event(
- self.bleadvertise_verify_onsuccess_handler, expected_advertise_event_name, (
- []),
- self.default_timeout)
+ expected_advertise_event_name = "".join(["BleAdvertise", str(
+ advertise_callback), "onSuccess"])
+ worker = self.adv_ad.ed.handle_event(
+ self.bleadvertise_verify_onsuccess_handler,
+ expected_advertise_event_name, ([]), self.default_timeout)
try:
self.log.debug(worker.result(self.default_timeout))
except Empty as error:
- self.log.debug(
- " ".join(["Test failed with Empty error:", str(error)]))
+ self.log.debug(" ".join(["Test failed with Empty error:", str(
+ error)]))
test_result = False
except concurrent.futures._base.TimeoutError as error:
- self.log.debug(
- " ".join(["Test failed, filtering callback onSuccess never occurred:",
- str(error)]))
+ self.log.debug(" ".join([
+ "Test failed, filtering callback onSuccess never occurred:",
+ str(error)
+ ]))
test_result = False
- advertise_droid.bleStopBleAdvertising(advertise_callback)
+ self.adv_ad.droid.bleStopBleAdvertising(advertise_callback)
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -204,47 +201,44 @@
Priority: 1
"""
test_result = True
- advertise_droid, advertise_event_dispatcher = self.droid, self.ed
advertise_callback, advertise_data, advertise_settings = generate_ble_advertise_objects(
- advertise_droid)
- advertise_droid.bleStartBleAdvertising(
+ self.adv_ad.droid)
+ self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- expected_advertise_event_name = "".join(
- ["BleAdvertise", str(advertise_callback), "onSuccess"])
- worker = advertise_event_dispatcher.handle_event(
- self.bleadvertise_verify_onsuccess_handler, expected_advertise_event_name, (
- []),
- self.default_timeout)
+ expected_advertise_event_name = "".join(["BleAdvertise", str(
+ advertise_callback), "onSuccess"])
+ worker = self.adv_ad.ed.handle_event(
+ self.bleadvertise_verify_onsuccess_handler,
+ expected_advertise_event_name, ([]), self.default_timeout)
try:
self.log.debug(worker.result(self.default_timeout))
except Empty as error:
- self.log.debug(
- " ".join(["Test failed with Empty error:", str(error)]))
+ self.log.debug(" ".join(["Test failed with Empty error:", str(
+ error)]))
test_result = False
except concurrent.futures._base.TimeoutError as error:
- self.log.debug(
- " ".join(["Test failed, filtering callback onSuccess never occurred:",
- str(error)]))
+ self.log.debug(" ".join(
+ ["Test failed, filtering callback onSuccess never occurred:",
+ str(error)]))
test_result = reset_bluetooth([self.scn_ad])
if not test_result:
return test_result
time.sleep(5)
- advertise_droid.bleStartBleAdvertising(
+ self.adv_ad.droid.bleStartBleAdvertising(
advertise_callback, advertise_data, advertise_settings)
- worker = advertise_event_dispatcher.handle_event(
- self.bleadvertise_verify_onsuccess_handler, expected_advertise_event_name, (
- []),
- self.default_timeout)
+ worker = self.adv_ad.ed.handle_event(
+ self.bleadvertise_verify_onsuccess_handler,
+ expected_advertise_event_name, ([]), self.default_timeout)
try:
self.log.debug(worker.result(self.default_timeout))
except Empty as error:
- self.log.debug(
- " ".join(["Test failed with Empty error:", str(error)]))
+ self.log.debug(" ".join(["Test failed with Empty error:", str(
+ error)]))
test_result = False
except concurrent.futures._base.TimeoutError as error:
- self.log.debug(
- " ".join(["Test failed, filtering callback onSuccess never occurred:",
- str(error)]))
+ self.log.debug(" ".join(
+ ["Test failed, filtering callback onSuccess never occurred:",
+ str(error)]))
return test_result
@BluetoothBaseTest.bt_test_wrap
@@ -272,11 +266,10 @@
"""
test_result = True
filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
- scan_droid)
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
- reset_bluetooth([self.scan_ad])
- self.scn_ad.droid.bleStartBleScan(
- filter_list, scan_settings, scan_callback)
-
+ self.scn_ad.droid)
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
+ reset_bluetooth([self.scn_ad])
+ self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
+ scan_callback)
return test_result
diff --git a/acts/tests/google/bt/BtBasicFunctionalityTest.py b/acts/tests/google/bt/BtBasicFunctionalityTest.py
index d7806e8..5419674 100644
--- a/acts/tests/google/bt/BtBasicFunctionalityTest.py
+++ b/acts/tests/google/bt/BtBasicFunctionalityTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to execute Bluetooth basic functionality test cases.
This test was designed to be run in a shield box.
@@ -41,16 +40,6 @@
BluetoothBaseTest.__init__(self, controllers)
self.droid_ad = self.android_devices[0]
self.droid1_ad = self.android_devices[1]
- self.tests = (
- "test_bluetooth_reset",
- "test_make_device_discoverable",
- "test_make_device_undiscoverable",
- "test_set_device_name",
- "test_scan_mode_off",
- "test_scan_mode_none",
- "test_scan_mode_connectable",
- "test_scan_mode_connectable_discoverable",
- )
def setup_class(self):
return setup_multiple_devices_for_bt_test(self.android_devices)
@@ -130,11 +119,13 @@
# Give Bluetooth time to discover advertising devices
time.sleep(self.scan_discovery_time)
droid_name = self.droid_ad.droid.bluetoothGetLocalName()
- get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices()
+ get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices(
+ )
find_flag = False
if get_all_discovered_devices:
- self.log.debug("Android device2 get all the discovered devices "
- "list {}".format(get_all_discovered_devices))
+ self.log.debug(
+ "Android device2 get all the discovered devices "
+ "list {}".format(get_all_discovered_devices))
for i in get_all_discovered_devices:
if 'name' in i and i['name'] == droid_name:
self.log.debug("Android device1 is in the discovery "
@@ -142,8 +133,9 @@
find_flag = True
break
else:
- self.log.debug("Android device2 get all the discovered devices "
- "list is empty")
+ self.log.debug(
+ "Android device2 get all the discovered devices "
+ "list is empty")
return False
else:
self.log.debug("Android device2 start discovery process error")
@@ -178,7 +170,7 @@
"""
self.droid_ad.droid.bluetoothMakeUndiscoverable()
set_bt_scan_mode(self.droid1_ad,
- BluetoothScanModeType.SCAN_MODE_NONE.value)
+ BluetoothScanModeType.SCAN_MODE_NONE.value)
scan_mode = self.droid1_ad.droid.bluetoothGetScanMode()
if scan_mode == BluetoothScanModeType.SCAN_MODE_NONE.value:
self.log.debug("Android device1 scan mode is SCAN_MODE_NONE")
@@ -190,11 +182,13 @@
# Give Bluetooth time to discover advertising devices
time.sleep(self.scan_discovery_time)
droid_name = self.droid_ad.droid.bluetoothGetLocalName()
- get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices()
+ get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices(
+ )
find_flag = False
if get_all_discovered_devices:
- self.log.debug("Android device2 get all the discovered devices "
- "list {}".format(get_all_discovered_devices))
+ self.log.debug(
+ "Android device2 get all the discovered devices "
+ "list {}".format(get_all_discovered_devices))
for i in get_all_discovered_devices:
if 'name' in i and i['name'] == droid_name:
self.log.debug(
@@ -307,8 +301,8 @@
Priority: 2
"""
self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE.")
- return set_bt_scan_mode(self.droid_ad,
- BluetoothScanModeType.SCAN_MODE_CONNECTABLE.value)
+ return set_bt_scan_mode(
+ self.droid_ad, BluetoothScanModeType.SCAN_MODE_CONNECTABLE.value)
@BluetoothBaseTest.bt_test_wrap
def test_scan_mode_connectable_discoverable(self):
@@ -332,7 +326,8 @@
Priority: 2
"""
self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE_DISCOVERABLE.")
- return set_bt_scan_mode(self.droid_ad,
+ return set_bt_scan_mode(
+ self.droid_ad,
BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value)
@BluetoothBaseTest.bt_test_wrap
diff --git a/acts/tests/google/bt/RfcommTest.py b/acts/tests/google/bt/RfcommTest.py
new file mode 100644
index 0000000..b3de132
--- /dev/null
+++ b/acts/tests/google/bt/RfcommTest.py
@@ -0,0 +1,192 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""
+Test script to execute Bluetooth basic functionality test cases.
+This test was designed to be run in a shield box.
+"""
+
+from contextlib import suppress
+import threading
+import time
+
+from queue import Empty
+from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
+from acts.test_utils.bt.bt_test_utils import log_energy_info
+from acts.test_utils.bt.bt_test_utils import kill_bluetooth_process
+from acts.test_utils.bt.bt_test_utils import reset_bluetooth
+from acts.test_utils.bt.bt_test_utils import rfcomm_accept
+from acts.test_utils.bt.bt_test_utils import rfcomm_connect
+from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
+from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
+from acts.test_utils.bt.bt_test_utils import write_read_verify_data
+
+
+class RfcommTest(BluetoothBaseTest):
+ default_timeout = 10
+ rf_client_th = 0
+ scan_discovery_time = 5
+ thread_list = []
+ message = (
+ "Space: the final frontier. These are the voyages of "
+ "the starship Enterprise. Its continuing mission: to explore "
+ "strange new worlds, to seek out new life and new civilizations,"
+ " to boldly go where no man has gone before.")
+
+ def __init__(self, controllers):
+ BluetoothBaseTest.__init__(self, controllers)
+ self.client_ad = self.android_devices[0]
+ self.server_ad = self.android_devices[1]
+
+ def _clear_bonded_devices(self):
+ for a in self.android_devices:
+ bonded_device_list = a.droid.bluetoothGetBondedDevices()
+ for device in bonded_device_list:
+ a.droid.bluetoothUnbond(device['address'])
+
+ def setup_class(self):
+ return setup_multiple_devices_for_bt_test(self.android_devices)
+
+ def setup_test(self):
+ self._clear_bonded_devices()
+ self.log.debug(log_energy_info(self.android_devices, "Start"))
+ for a in self.android_devices:
+ a.ed.clear_all_events()
+ return True
+
+ def teardown_test(self):
+ self.log.debug(log_energy_info(self.android_devices, "End"))
+ return True
+
+ def on_fail(self, test_name, begin_time):
+ take_btsnoop_logs(self.android_devices, self, test_name)
+ reset_bluetooth(self.android_devices)
+
+ def teardown_test(self):
+ with suppress(Exception):
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ self.client_ad.droid.bluetoothRfcommCloseSocket()
+ self.server_ad.droid.bluetoothRfcommCloseSocket()
+ for thread in self.thread_list:
+ thread.join()
+ self.thread_list.clear()
+
+ def orchestrate_rfcomm_connect(self, server_mac):
+ accept_thread = threading.Thread(target=rfcomm_accept,
+ args=(self.server_ad, ))
+ self.thread_list.append(accept_thread)
+ accept_thread.start()
+ connect_thread = threading.Thread(target=rfcomm_connect,
+ args=(self.client_ad, server_mac))
+ self.rf_client_th = connect_thread
+ self.thread_list.append(connect_thread)
+ connect_thread.start()
+ for thread in self.thread_list:
+ thread.join()
+ end_time = time.time() + self.default_timeout
+ result = False
+ while time.time() < end_time:
+ if len(self.client_ad.droid.bluetoothRfcommActiveConnections(
+ )) > 0:
+ self.log.info("RFCOMM Connection Active")
+ return True
+ self.log.error("Failed to establish an RFCOMM connection")
+ return False
+
+ @BluetoothBaseTest.bt_test_wrap
+ def test_rfcomm_connection_write_ascii(self):
+ """Test bluetooth RFCOMM writing and reading ascii data
+
+ Test RFCOMM though establishing a connection.
+
+ Steps:
+ 1. Get the mac address of the server device.
+ 2. Establish an RFCOMM connection from the client to the server AD.
+ 3. Verify that the RFCOMM connection is active from both the client and
+ server.
+ 4. Write data from the client and read received data from the server.
+ 5. Verify data matches from client and server
+ 6. Disconnect the RFCOMM connection.
+
+ Expected Result:
+ RFCOMM connection is established then disconnected succcessfully.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, RFCOMM
+ Priority: 1
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ if not self.orchestrate_rfcomm_connect(server_mac):
+ return False
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ self.message, False):
+ return False
+ if len(self.server_ad.droid.bluetoothRfcommActiveConnections()) == 0:
+ self.log.info("No rfcomm connections found on server.")
+ return False
+ if len(self.client_ad.droid.bluetoothRfcommActiveConnections()) == 0:
+ self.log.info("no rfcomm connections found on client.")
+ return False
+
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ return True
+
+ @BluetoothBaseTest.bt_test_wrap
+ def test_rfcomm_write_binary(self):
+ """Test bluetooth RFCOMM writing and reading binary data
+
+ Test profile though establishing an RFCOMM connection.
+
+ Steps:
+ 1. Get the mac address of the server device.
+ 2. Establish an RFCOMM connection from the client to the server AD.
+ 3. Verify that the RFCOMM connection is active from both the client and
+ server.
+ 4. Write data from the client and read received data from the server.
+ 5. Verify data matches from client and server
+ 6. Disconnect the RFCOMM connection.
+
+ Expected Result:
+ RFCOMM connection is established then disconnected succcessfully.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, RFCOMM
+ Priority: 1
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ if not self.orchestrate_rfcomm_connect(server_mac):
+ return False
+ binary_message = "11010101"
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ binary_message, True):
+ return False
+ if len(self.server_ad.droid.bluetoothRfcommActiveConnections()) == 0:
+ self.log.info("No rfcomm connections found on server.")
+ return False
+ if len(self.client_ad.droid.bluetoothRfcommActiveConnections()) == 0:
+ self.log.info("no rfcomm connections found on client.")
+ return False
+
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ return True
diff --git a/acts/tests/google/bt/SppTest.py b/acts/tests/google/bt/SppTest.py
deleted file mode 100644
index 01d7ecd..0000000
--- a/acts/tests/google/bt/SppTest.py
+++ /dev/null
@@ -1,134 +0,0 @@
-#/usr/bin/env python3.4
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-"""
-Test script to execute Bluetooth basic functionality test cases.
-This test was designed to be run in a shield box.
-"""
-
-import threading
-import time
-
-from queue import Empty
-from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
-from acts.test_utils.bt.bt_test_utils import get_bt_mac_address
-from acts.test_utils.bt.bt_test_utils import log_energy_info
-from acts.test_utils.bt.bt_test_utils import reset_bluetooth
-from acts.test_utils.bt.bt_test_utils import rfcomm_accept
-from acts.test_utils.bt.bt_test_utils import rfcomm_connect
-from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
-from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
-
-
-class SppTest(BluetoothBaseTest):
- default_timeout = 10
- scan_discovery_time = 5
- thread_list = []
- message = ("Space: the final frontier. These are the voyages of "
- "the starship Enterprise. Its continuing mission: to explore "
- "strange new worlds, to seek out new life and new civilizations,"
- " to boldly go where no man has gone before.")
-
- def __init__(self, controllers):
- BluetoothBaseTest.__init__(self, controllers)
- self.server_ad = self.android_devices[0]
- self.client_ad = self.android_devices[1]
- self.tests = (
- "test_spp_connection",
- )
-
- def _clear_bonded_devices(self):
- for a in self.android_devices:
- bonded_device_list = a.droid.bluetoothGetBondedDevices()
- for device in bonded_device_list:
- a.droid.bluetoothUnbond(device['address'])
-
- def setup_class(self):
- return setup_multiple_devices_for_bt_test(self.android_devices)
-
- def setup_test(self):
- self._clear_bonded_devices()
- self.log.debug(log_energy_info(self.android_devices, "Start"))
- for a in self.android_devices:
- a.ed.clear_all_events()
- return True
-
- def teardown_test(self):
- self.log.debug(log_energy_info(self.android_devices, "End"))
- return True
-
- def on_fail(self, test_name, begin_time):
- take_btsnoop_logs(self.android_devices, self, test_name)
- reset_bluetooth(self.android_devices)
-
- def teardown_test(self):
- for thread in self.thread_list:
- thread.join()
-
- def orchestrate_rfcomm_connect(self, server_mac):
- accept_thread = threading.Thread(
- target=rfcomm_accept, args=(self.server_ad.droid,))
- self.thread_list.append(accept_thread)
- accept_thread.start()
- connect_thread = threading.Thread(
- target=rfcomm_connect, args=(self.client_ad.droid, server_mac))
- self.thread_list.append(connect_thread)
- connect_thread.start()
-
- @BluetoothBaseTest.bt_test_wrap
- def test_spp_connection(self):
- """Test bluetooth SPP profile.
-
- Test SPP profile though establishing an RFCOMM connection.
-
- Steps:
- 1. Get the mac address of the server device.
- 2. Establish an RFCOMM connection from the client to the server AD.
- 3. Verify that the RFCOMM connection is active from both the client and
- server.
- 4. Disconnect the RFCOMM connection.
-
- Expected Result:
- RFCOMM connection is established then disconnected succcessfully.
-
- Returns:
- Pass if True
- Fail if False
-
- TAGS: Classic, SPP, RFCOMM
- Priority: 1
- """
- server_mac = get_bt_mac_address(self.client_ad.droid,
- self.server_ad.droid)
- # temporary workaround. Need to find out why I can't connect after I do
- # a device discovery from get_bt_mac_address
- reset_bluetooth([self.server_ad])
- self.orchestrate_rfcomm_connect(server_mac)
- self.log.info("Write message.")
- self.client_ad.droid.bluetoothRfcommWrite(self.message)
- self.log.info("Read message.")
- read_msg = self.server_ad.droid.bluetoothRfcommRead()
- self.log.info("Verify message.")
- assert self.message == read_msg, "Mismatch! Read {}".format(read_msg)
- if len(self.server_ad.droid.bluetoothRfcommActiveConnections()) == 0:
- self.log.info("No rfcomm connections found on server.")
- return False
- if len(self.client_ad.droid.bluetoothRfcommActiveConnections()) == 0:
- self.log.info("no rfcomm connections found on client.")
- return False
- self.client_ad.droid.bluetoothRfcommStop()
- self.server_ad.droid.bluetoothRfcommStop()
- return True
diff --git a/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py b/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
index 6c1b72f..7168edb 100644
--- a/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
+++ b/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
@@ -29,51 +29,33 @@
import time
from acts.base_test import BaseTestClass
-from acts.test_utils.bt.bt_test_utils import log_energy_info
-from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
-from acts.test_utils.bt.bt_test_utils import reset_bluetooth
-from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
-from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
+from acts.test_utils.bt import bt_test_utils
+from acts import asserts
class BtCarPairedConnectDisconnectTest(BaseTestClass):
- def __init__(self, controllers):
- BaseTestClass.__init__(self, controllers)
+ def setup_class(self):
self.droid_ad = self.android_devices[0]
self.droid1_ad = self.android_devices[1]
- self.tests = (
- "test_connect_disconnect_paired",
- )
-
- def setup_class(self):
- return True
def setup_test(self):
# Reset the devices in a clean state.
- setup_multiple_devices_for_bt_test(self.android_devices)
- reset_bluetooth(self.android_devices)
+ bt_test_utils.setup_multiple_devices_for_bt_test(self.android_devices)
+ bt_test_utils.reset_bluetooth(self.android_devices)
for a in self.android_devices:
a.ed.clear_all_events()
# Pair the devices.
# This call may block until some specified timeout in bt_test_utils.py.
- result = pair_pri_to_sec(self.droid_ad.droid, self.droid1_ad.droid)
+ result = bt_test_utils.pair_pri_to_sec(self.droid_ad.droid, self.droid1_ad.droid)
- if result is False:
- self.log.info("pair_pri_to_sec returned false.")
- return False
+ asserts.assert_true(result, "pair_pri_to_sec returned false.");
# Check for successful setup of test.
devices = self.droid_ad.droid.bluetoothGetBondedDevices()
- if (len(devices) == 0):
- self.log.info("pair_pri_to_sec succeeded but no bonded devices.")
- return False
- return True
-
- def teardown_test(self):
- return True
+ asserts.assert_equal(len(devices), 1, "pair_pri_to_sec succeeded but no bonded devices.")
def on_fail(self, test_name, begin_time):
- take_btsnoop_logs(self.android_devices, self, test_name)
+ bt_test_utils.take_btsnoop_logs(self.android_devices, self, test_name)
def test_connect_disconnect_paired(self):
NUM_TEST_RUNS = 2
@@ -89,9 +71,13 @@
self.log.info("Attempting to connect.")
self.droid_ad.droid.bluetoothConnectBonded(devices[0]['address'])
- end_time = time.time() + 10
+ end_time = time.time() + 20
expected_address = self.droid1_ad.droid.bluetoothGetLocalAddress()
connected = False
+ a2dp_sink_connected = False
+ pbap_client_connected = False
+ hfp_client_connected = False
+
# Busy loop to check if we found a matching device.
while time.time() < end_time:
connected_devices = self.droid_ad.droid.bluetoothGetConnectedDevices()
@@ -99,13 +85,44 @@
if d['address'] == expected_address:
connected = True
break
- if connected is True:
+ a2dp_sink_connected_devices = (self.droid_ad.droid
+ .bluetoothGetConnectedDevicesOnProfile(11))
+ for d in a2dp_sink_connected_devices:
+ if d['address'] == expected_address:
+ a2dp_sink_connected = True
+ break
+
+ hfp_client_connected_devices = (self.droid_ad.droid.
+ bluetoothGetConnectedDevicesOnProfile(16))
+ for d in hfp_client_connected_devices:
+ if d['address'] == expected_address:
+ hfp_client_connected = True
+ break
+
+ pbap_client_connected_devices = (self.droid_ad.droid.
+ bluetoothGetConnectedDevicesOnProfile(17))
+ for d in hfp_client_connected_devices:
+ if d['address'] == expected_address:
+ pbap_client_connected = True
+ break
+ time.sleep(5)
+
+ self.log.info("Connected " + str(connected))
+ self.log.info("A2DP Sink Connected " + str(a2dp_sink_connected))
+ self.log.info("HFP client connected " + str(hfp_client_connected))
+ self.log.info("PBAP Client connected " + str(pbap_client_connected))
+
+ if (all([connected, a2dp_sink_connected,
+ hfp_client_connected, pbap_client_connected])):
break
- time.sleep(1)
+
+ # Try again to overcome occasional throw away by bluetooth
+ self.droid_ad.droid.bluetoothConnectBonded(devices[0]['address'])
# Check if we got connected.
- if connected is False:
- self.log.info("No connected devices.")
+ if (not all([connected, a2dp_sink_connected, pbap_client_connected,
+ hfp_client_connected])):
+ self.log.info("Not all profiles connected.")
failure = failure + 1
continue
@@ -135,7 +152,4 @@
failure = failure + 1
continue
self.log.info("Failure {} total tests {}".format(failure, NUM_TEST_RUNS))
- if failure > 0:
- return False
- else:
- return True
+ asserts.assert_equal(failure, 0, "")
diff --git a/acts/tests/google/bt/car_bt/BtCarToggleTest.py b/acts/tests/google/bt/car_bt/BtCarToggleTest.py
new file mode 100644
index 0000000..12c3680
--- /dev/null
+++ b/acts/tests/google/bt/car_bt/BtCarToggleTest.py
@@ -0,0 +1,52 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+"""
+This test is used to test basic functionality of bluetooth adapter by turning it ON/OFF.
+"""
+
+from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
+from acts.test_utils.bt import bt_test_utils
+
+class BtCarToggleTest(BluetoothBaseTest):
+ def setup_class(self):
+ self.droid_ad = self.android_devices[0]
+
+ def setup_test(self):
+ self.log.debug(log_energy_info(self.android_devices, "Start"))
+ self.droid_ad.ed.clear_all_events()
+
+ def teardown_test(self):
+ self.log.debug(log_energy_info(self.android_devices, "End"))
+
+ def on_fail(self, test_name, begin_time):
+ bt_test_utils.take_btsnoop_logs(self.android_devices, self, test_name)
+
+ @BluetoothBaseTest.bt_test_wrap
+ def test_bluetooth_reset(self):
+ """Test resetting bluetooth.
+
+ Test the integrity of resetting bluetooth on Android.
+
+ Steps:
+ 1. Toggle bluetooth off.
+ 2. Toggle bluetooth on.
+
+ Returns:
+ Pass if True
+ Fail if False
+ """
+ asserts.assert_true(bt_test_utils.reset_bluetooth([self.droid_ad]), "")
diff --git a/acts/tests/google/bt/gatt/GattOverBrEdrTest.py b/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
index bf24b5a..5d79459 100644
--- a/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
+++ b/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
@@ -13,35 +13,31 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test suite for GATT over BR/EDR.
"""
+import time
+
from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
from acts.test_utils.bt.bt_test_utils import reset_bluetooth
-from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
-from acts.test_utils.bt.BleEnum import BluetoothGattCharacteristic
-from acts.test_utils.bt.BleEnum import BluetoothGattDescriptor
-from acts.test_utils.bt.BleEnum import BluetoothGattService
-from acts.test_utils.bt.BleEnum import BluetoothMtuSize
-from acts.test_utils.bt.bt_test_utils import descriptor_write
-from acts.test_utils.bt.bt_test_utils import descriptor_write_request
-from acts.test_utils.bt.bt_test_utils import disconnect_gatt_connection
-from acts.test_utils.bt.bt_test_utils import gatt_services_discovered
+from acts.test_utils.bt.GattEnum import GattCharacteristic
+from acts.test_utils.bt.GattEnum import GattDescriptor
+from acts.test_utils.bt.GattEnum import GattService
+from acts.test_utils.bt.GattEnum import MtuSize
+from acts.test_utils.bt.GattEnum import GattCbStrings
+from acts.test_utils.bt.bt_gatt_utils import disconnect_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import orchestrate_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_characteristics
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_connection
+from acts.test_utils.bt.bt_gatt_utils import setup_gatt_descriptors
from acts.test_utils.bt.bt_test_utils import get_advanced_droid_list
-from acts.test_utils.bt.bt_test_utils import get_bt_mac_address
-from acts.test_utils.bt.bt_test_utils import orchestrate_gatt_connection
-from acts.test_utils.bt.bt_test_utils import mtu_changed
-from acts.test_utils.bt.bt_test_utils import read_remote_rssi
-from acts.test_utils.bt.bt_test_utils import service_added
-from acts.test_utils.bt.bt_test_utils import setup_gatt_characteristics
-from acts.test_utils.bt.bt_test_utils import setup_gatt_descriptors
+from acts.test_utils.bt.bt_test_utils import log_energy_info
from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
+
class GattOverBrEdrTest(BluetoothBaseTest):
- tests = None
default_timeout = 10
default_discovery_timeout = 3
droid_list = ()
@@ -52,26 +48,13 @@
self.droid_list = get_advanced_droid_list(self.android_devices)
self.cen_ad = self.android_devices[0]
self.per_ad = self.android_devices[1]
- self.tests = (
- "test_gatt_bredr_connect",
- "test_gatt_bredr_request_min_mtu",
- "test_gatt_bredr_request_max_mtu",
- "test_gatt_bredr_request_out_of_bounds_mtu",
- "test_gatt_bredr_connect_trigger_on_read_rssi",
- "test_gatt_bredr_connect_trigger_on_services_discovered",
- "test_gatt_bredr_connect_trigger_on_services_discovered_iterate_attributes",
- "test_gatt_bredr_connect_with_service_uuid_variations",
- "test_gatt_bredr_connect_multiple_iterations",
- "test_bredr_write_descriptor_stress",
- "test_gatt_bredr_connect_mitm_attack",
- )
def setup_class(self):
self.log.info("Setting up devices for bluetooth testing.")
if not setup_multiple_devices_for_bt_test(self.android_devices):
return False
- self.per_droid_mac_address = get_bt_mac_address(
- self.cen_ad.droid, self.per_ad.droid, False)
+ self.per_droid_mac_address = self.per_ad.droid.bluetoothGetLocalAddress(
+ )
if not self.per_droid_mac_address:
return False
return True
@@ -84,44 +67,43 @@
characteristic_input = [
{
'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattCharacteristic.PROPERTY_WRITE.value |
- BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
- 'permission': BluetoothGattCharacteristic.PROPERTY_WRITE.value
+ 'property': GattCharacteristic.PROPERTY_WRITE.value
+ | GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
+ 'permission': GattCharacteristic.PROPERTY_WRITE.value
},
{
'uuid': "21c0a0bf-ad51-4a2d-8124-b74003e4e8c8",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
},
{
'uuid': "6774191f-6ec3-4aa2-b8a8-cf830e41fda6",
- 'property': BluetoothGattCharacteristic.PROPERTY_NOTIFY.value |
- BluetoothGattCharacteristic.PROPERTY_READ.value,
- 'permission': BluetoothGattCharacteristic.PERMISSION_READ.value
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_READ.value,
+ 'permission': GattCharacteristic.PERMISSION_READ.value
},
]
descriptor_input = [
{
'uuid': "aa7edd5a-4d1d-4f0e-883a-d145616a1630",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattDescriptor.PERMISSION_WRITE.value,
- },
- {
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
+ }, {
'uuid': "76d5ed92-ca81-4edb-bb6b-9f019665fb32",
- 'property': BluetoothGattDescriptor.PERMISSION_READ.value |
- BluetoothGattCharacteristic.PERMISSION_WRITE.value,
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattCharacteristic.PERMISSION_WRITE.value,
}
]
- characteristic_list = setup_gatt_characteristics(
- droid, characteristic_input)
+ characteristic_list = setup_gatt_characteristics(droid,
+ characteristic_input)
descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
return characteristic_list, descriptor_list
def _orchestrate_gatt_disconnection(self, bluetooth_gatt, gatt_callback):
self.log.info("Disconnecting from peripheral device.")
- test_result = disconnect_gatt_connection(
- self.cen_ad, bluetooth_gatt, gatt_callback)
+ test_result = disconnect_gatt_connection(self.cen_ad, bluetooth_gatt,
+ gatt_callback)
if not test_result:
self.log.info("Failed to disconnect from peripheral device.")
return False
@@ -138,24 +120,22 @@
self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
discovered_services_index, i))
for characteristic in characteristic_uuids:
- self.log.info(
- "Discovered characteristic uuid {}".format(characteristic))
+ self.log.info("Discovered characteristic uuid {}".format(
+ characteristic))
descriptor_uuids = (
self.cen_ad.droid.gattClientGetDiscoveredDescriptorUuids(
discovered_services_index, i, characteristic))
for descriptor in descriptor_uuids:
- self.log.info(
- "Discovered descriptor uuid {}".format(descriptor))
+ self.log.info("Discovered descriptor uuid {}".format(
+ descriptor))
def _find_service_added_event(self, gatt_server_callback, uuid):
event = self.per_ad.ed.pop_event(
- service_added.format(gatt_server_callback),
+ GattCbStrings.SERV_ADDED.value.format(gatt_server_callback),
self.default_timeout)
if event['data']['serviceUuid'].lower() != uuid.lower():
- self.log.info(
- "Uuid mismatch. Found: {}, Expected {}.".format(
- event['data']['serviceUuid'],
- uuid))
+ self.log.info("Uuid mismatch. Found: {}, Expected {}.".format(
+ event['data']['serviceUuid'], uuid))
return False
return True
@@ -172,38 +152,35 @@
characteristic_list[2], descriptor_list[1])
gatt_service = self.per_ad.droid.gattServerCreateService(
"00000000-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
gatt_service2 = self.per_ad.droid.gattServerCreateService(
"FFFFFFFF-0000-1000-8000-00805f9b34fb",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
gatt_service3 = self.per_ad.droid.gattServerCreateService(
"3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY.value)
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
result = self._find_service_added_event(
- gatt_server_callback,
- "00000000-0000-1000-8000-00805f9b34fb")
+ gatt_server_callback, "00000000-0000-1000-8000-00805f9b34fb")
if not result:
return False
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service2,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service2, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service2)
result = self._find_service_added_event(
- gatt_server_callback,
- "FFFFFFFF-0000-1000-8000-00805f9b34fb")
+ gatt_server_callback, "FFFFFFFF-0000-1000-8000-00805f9b34fb")
if not result:
return False
for characteristic in characteristic_list:
- self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service3,
- characteristic)
+ self.per_ad.droid.gattServerAddCharacteristicToService(
+ gatt_service3, characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service3)
result = self._find_service_added_event(
- gatt_server_callback,
- "3846D7A0-69C8-11E4-BA00-0002A5D5C51B")
+ gatt_server_callback, "3846D7A0-69C8-11E4-BA00-0002A5D5C51B")
if not result:
return False, False
return gatt_server_callback, gatt_server
@@ -273,9 +250,11 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad, False,
self.per_droid_mac_address))
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MIN.value)
- mtu_event = self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt))
- if mtu_event['data']['MTU'] != BluetoothMtuSize.MIN.value:
+ MtuSize.MIN.value)
+ mtu_event = self.cen_ad.ed.pop_event(
+ GattCbStrings.MTU_CHANGED.value.format(
+ bluetooth_gatt), self.default_timeout)
+ if mtu_event['data']['MTU'] != MtuSize.MIN.value:
return False
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -313,9 +292,11 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad, False,
self.per_droid_mac_address))
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MAX.value)
- mtu_event = self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt))
- if mtu_event['data']['MTU'] != BluetoothMtuSize.MAX.value:
+ MtuSize.MAX.value)
+ mtu_event = self.cen_ad.ed.pop_event(
+ GattCbStrings.MTU_CHANGED.value.format(
+ bluetooth_gatt), self.default_timeout)
+ if mtu_event['data']['MTU'] != MtuSize.MAX.value:
return False
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -354,16 +335,17 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad, False,
self.per_droid_mac_address))
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- BluetoothMtuSize.MIN.value - 1)
+ MtuSize.MIN.value - 1)
try:
- self.cen_ad.ed.pop_event(mtu_changed.format(bluetooth_gatt),
- self.default_timeout)
- self.log.error("Found {} event when it wasn't expected".
- format(mtu_changed.format(bluetooth_gatt)))
+ self.cen_ad.ed.pop_event(
+ GattCbStrings.MTU_CHANGED.value.format(bluetooth_gatt),
+ self.default_timeout)
+ self.log.error("Found {} event when it wasn't expected".format(
+ GattCbStrings.MTU_CHANGED.format(bluetooth_gatt)))
return False
except Exception:
- self.log.debug("Successfully didn't find {} event"
- .format(mtu_changed.format(bluetooth_gatt)))
+ self.log.debug("Successfully didn't find {} event".format(
+ GattCbStrings.MTU_CHANGED.value.format(bluetooth_gatt)))
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -399,7 +381,8 @@
self.per_droid_mac_address))
if self.cen_ad.droid.gattClientReadRSSI(bluetooth_gatt):
self.cen_ad.ed.pop_event(
- read_remote_rssi.format(gatt_callback), self.default_timeout)
+ GattCbStrings.RD_REMOTE_RSSI.value.format(
+ gatt_callback), self.default_timeout)
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@@ -436,14 +419,15 @@
discovered_services_index = -1
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
+ GattCbStrings.GATT_SERV_DISC.value.format(gatt_callback),
self.default_timeout)
discovered_services_index = event['data']['ServicesIndex']
return self._orchestrate_gatt_disconnection(bluetooth_gatt,
gatt_callback)
@BluetoothBaseTest.bt_test_wrap
- def test_gatt_bredr_connect_trigger_on_services_discovered_iterate_attributes(self):
+ def test_gatt_bredr_connect_trigger_on_services_discovered_iterate_attributes(
+ self):
"""Test GATT connection and iterate peripherals attributes.
Test establishing a gatt connection between a GATT server and GATT
@@ -480,7 +464,7 @@
discovered_services_index = -1
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
+ GattCbStrings.GATT_SERV_DISC.value.format(gatt_callback),
self.default_timeout)
discovered_services_index = event['data']['ServicesIndex']
self._iterate_attributes(discovered_services_index)
@@ -524,7 +508,7 @@
discovered_services_index = -1
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
+ GattCbStrings.GATT_SERV_DISC.value.format(gatt_callback),
self.default_timeout)
discovered_services_index = event['data']['ServicesIndex']
self._iterate_attributes(discovered_services_index)
@@ -559,14 +543,14 @@
Priority: 1
"""
autoconnect = False
- mac_address = get_bt_mac_address(self.cen_ad.droid, self.per_ad.droid)
+ mac_address = self.per_ad.droid.bluetoothGetLocalAddress()
for i in range(20):
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad, False,
self.per_droid_mac_address))
self.log.info("Disconnecting from peripheral device.")
- test_result = self._orchestrate_gatt_disconnection(
- bluetooth_gatt, gatt_callback)
+ test_result = self._orchestrate_gatt_disconnection(bluetooth_gatt,
+ gatt_callback)
if not test_result:
self.log.info("Failed to disconnect from peripheral device.")
return False
@@ -608,7 +592,7 @@
self.per_droid_mac_address))
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
+ GattCbStrings.GATT_SERV_DISC.value.format(gatt_callback),
self.default_timeout)
discovered_services_index = event['data']['ServicesIndex']
else:
@@ -625,8 +609,8 @@
bt_device_id = 0
status = 1
offset = 1
- test_value = "1,2,3,4,5,6,7"
- test_value_return = "1,2,3"
+ test_value = [1,2,3,4,5,6,7]
+ test_value_return = [1,2,3]
for i in range(services_count):
characteristic_uuids = (
self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
@@ -644,8 +628,8 @@
bluetooth_gatt, discovered_services_index, i,
characteristic, descriptor)
event = self.per_ad.ed.pop_event(
- descriptor_write_request.format(gatt_callback),
- self.default_timeout)
+ GattCbStrings.DESC_WRITE_REQ.value.format(
+ gatt_callback), self.default_timeout)
self.log.info(
"onDescriptorWriteRequest event found: {}".format(
event))
@@ -662,8 +646,9 @@
self.log.info(
"onDescriptorWrite event found: {}".format(
self.cen_ad.ed.pop_event(
- descriptor_write.format(bluetooth_gatt),
- self.default_timeout)))
+ GattCbStrings.DESC_WRITE.value.format(
+ bluetooth_gatt),
+ self.default_timeout)))
return True
@BluetoothBaseTest.bt_test_wrap
@@ -679,8 +664,8 @@
1. Create a GATT server and server callback on the peripheral device.
2. Create a unique service and characteristic uuid on the peripheral.
3. Create a characteristic on the peripheral with these properties:
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
+ GattCharacteristic.PROPERTY_WRITE.value,
+ GattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
4. Create a GATT service on the peripheral.
5. Add the characteristic to the GATT service.
6. Create a GATT connection between your central and peripheral device.
@@ -714,34 +699,31 @@
test_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
bonded = False
characteristic = self.per_ad.droid.gattServerCreateBluetoothGattCharacteristic(
- test_uuid,
- BluetoothGattCharacteristic.PROPERTY_WRITE.value,
- BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value
- )
+ test_uuid, GattCharacteristic.PROPERTY_WRITE.value,
+ GattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value)
gatt_service = self.per_ad.droid.gattServerCreateService(
- service_uuid,
- BluetoothGattService.SERVICE_TYPE_PRIMARY.value
- )
- self.per_ad.droid.gattServerAddCharacteristicToService(
- gatt_service, characteristic)
+ service_uuid, GattService.SERVICE_TYPE_PRIMARY.value)
+ self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
+ characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
- result = self._find_service_added_event(
- gatt_server_callback,
- service_uuid)
+ result = self._find_service_added_event(gatt_server_callback,
+ service_uuid)
if not result:
return False
bluetooth_gatt, gatt_callback, adv_callback = (
orchestrate_gatt_connection(self.cen_ad, self.per_ad, False,
- self.per_droid_mac_address))
+ self.per_droid_mac_address))
+ if bluetooth_gatt is False:
+ return False
if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
event = self.cen_ad.ed.pop_event(
- gatt_services_discovered.format(gatt_callback),
+ GattCbStrings.GATT_SERV_DISC.value.format(gatt_callback),
self.default_timeout)
discovered_services_index = event['data']['ServicesIndex']
else:
self.log.info("Failed to discover services.")
return False
- test_value = "1,2,3,4,5,6,7"
+ test_value = [1,2,3,4,5,6,7]
services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
for i in range(services_count):
@@ -761,9 +743,11 @@
start_time = time.time() + self.default_timeout
target_name = self.per_ad.droid.bluetoothGetLocalName()
while time.time() < start_time and bonded == False:
- bonded_devices = self.cen_ad.droid.bluetoothGetBondedDevices()
+ bonded_devices = self.cen_ad.droid.bluetoothGetBondedDevices(
+ )
for device in bonded_devices:
- if 'name' in device.keys() and device['name'] == target_name:
+ if 'name' in device.keys() and device[
+ 'name'] == target_name:
bonded = True
break
- return True
\ No newline at end of file
+ return True
diff --git a/acts/tests/google/bt/native/BtNativeTest.py b/acts/tests/google/bt/native/BtNativeTest.py
index d91eb1e..2b5d21b 100644
--- a/acts/tests/google/bt/native/BtNativeTest.py
+++ b/acts/tests/google/bt/native/BtNativeTest.py
@@ -16,27 +16,25 @@
import time
from acts.base_test import BaseTestClass
+from acts.controllers import native_android_device
from acts.test_utils.bt.native_bt_test_utils import setup_native_bluetooth
from acts.test_utils.bt.bt_test_utils import generate_id_by_size
+
class BtNativeTest(BaseTestClass):
tests = None
def __init__(self, controllers):
BaseTestClass.__init__(self, controllers)
- setup_native_bluetooth(self.native_android_devices)
- self.droid = self.native_android_devices[0].droid
- self.tests = (
- "test_binder_get_name",
- "test_binder_get_name_invalid_parameter",
- "test_binder_set_name_get_name",
- "test_binder_get_address",
- )
- if len(self.native_android_devices) > 1:
- self.droid1 = self.native_android_devices[1].droid
- self.tests = self.tests + (
- "test_two_devices_set_get_name",
- )
+ setup_native_bluetooth(self.native_devices)
+ self.droid = self.native_devices[0].droid
+ self.tests = ("test_binder_get_name",
+ "test_binder_get_name_invalid_parameter",
+ "test_binder_set_name_get_name",
+ "test_binder_get_address", )
+ if len(self.native_devices) > 1:
+ self.droid1 = self.native_devices[1].droid
+ self.tests = self.tests + ("test_two_devices_set_get_name", )
def test_binder_get_name(self):
result = self.droid.BluetoothBinderGetName()
@@ -69,10 +67,11 @@
def test_two_devices_set_get_name(self):
test_name = generate_id_by_size(4)
- for n in self.native_android_devices:
+ for n in self.native_devices:
d = n.droid
d.BluetoothBinderSetName(test_name)
name = d.BluetoothBinderGetName()
if name != test_name:
return False
- return True
\ No newline at end of file
+ return True
+
diff --git a/acts/tests/google/bt/setup/BtPreFlightTest.py b/acts/tests/google/bt/setup/BtPreFlightTest.py
index a0ccccc..2cf7e9a 100644
--- a/acts/tests/google/bt/setup/BtPreFlightTest.py
+++ b/acts/tests/google/bt/setup/BtPreFlightTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See thea
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Bluetooth Pre-Flight Test.
"""
@@ -24,20 +23,17 @@
class BtPreFlightTest(BaseTestClass):
-
def __init__(self, controllers):
BaseTestClass.__init__(self, controllers)
- self.tests = (
- "test_setup_logging",
- )
+ self.tests = ("test_setup_logging", )
def setup_class(self):
for a in self.android_devices:
d = a.droid
serial = d.getBuildSerial()
self.log.debug("****START: {} DEVICE INFO****".format(serial))
- self.log.debug(
- "BOOTLOADER VERSION {}".format(d.getBuildBootloader()))
+ self.log.debug("BOOTLOADER VERSION {}".format(d.getBuildBootloader(
+ )))
self.log.debug("BUILD HARDWARE {}".format(d.getBuildHardware()))
self.log.debug("BUILD PRODUCT {}".format(d.getBuildProduct()))
self.log.debug("*ENVIRONMENT DETAILS*")
@@ -46,8 +42,8 @@
return True
def test_setup_logging(self):
- conf_path = "{}/bt_stack.conf".format(
- os.path.dirname(os.path.realpath(__file__)))
+ conf_path = "{}/bt_stack.conf".format(os.path.dirname(os.path.realpath(
+ __file__)))
log_level_check = "TRC_BTM=5"
remount_check = "remount succeeded"
for ad in self.android_devices:
@@ -63,8 +59,8 @@
except Exception as e:
self.abort_all("Exception in BT pre-flight test: {}"
.format(e))
- ad.adb.push(
- "{} /system/etc/bluetooth/bt_stack.conf".format(conf_path))
+ ad.adb.push("{} /system/etc/bluetooth/bt_stack.conf".format(
+ conf_path))
result = ad.adb.shell("cat /system/etc/bluetooth/bt_stack.conf")
# Verify that the log levels have been raised
if log_level_check not in str(result):
diff --git a/acts/tests/google/bt/system_tests/BtStressTest.py b/acts/tests/google/bt/system_tests/BtStressTest.py
index 3689457..193fa52 100644
--- a/acts/tests/google/bt/system_tests/BtStressTest.py
+++ b/acts/tests/google/bt/system_tests/BtStressTest.py
@@ -13,26 +13,23 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Basic Bluetooth Classic stress tests.
"""
+import time
from acts.base_test import BaseTestClass
from acts.test_utils.bt.bt_test_utils import log_energy_info
+from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
from acts.test_utils.bt.bt_test_utils import reset_bluetooth
from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
class BtStressTest(BaseTestClass):
- tests = None
default_timeout = 10
def __init__(self, controllers):
BaseTestClass.__init__(self, controllers)
- self.tests = (
- "test_toggle_bluetooth",
- )
def setup_class(self):
return setup_multiple_devices_for_bt_test(self.android_devices)
@@ -72,14 +69,58 @@
TAGS: Classic, Stress
Priority: 1
"""
- n = 0
test_result = True
test_result_list = []
- while n < 100:
- self.log.info("Toggling bluetooth iteration {}.".format(n))
+ for n in range(100):
+ self.log.info("Toggling bluetooth iteration {}.".format(n + 1))
test_result = reset_bluetooth([self.android_devices[0]])
test_result_list.append(test_result)
- n += 1
+ if not test_result:
+ self.log.debug("Failure to reset Bluetooth... continuing")
+ self.log.info("Toggling Bluetooth failed {}/100 times".format(len(
+ test_result_list)))
if False in test_result_list:
return False
return test_result
+
+ def test_pair_bluetooth_stress(self):
+ """Stress test for pairing BT devices.
+
+ Test the integrity of Bluetooth pairing.
+
+ Steps:
+ 1. Pair two Android devices
+ 2. Verify both devices are paired
+ 3. Unpair devices.
+ 4. Verify devices unpaired.
+ 5. Repeat steps 1-4 100 times.
+
+ Expected Result:
+ Each iteration of toggling Bluetooth pairing and unpairing
+ should succeed.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Stress
+ Priority: 1
+ """
+ for n in range(100):
+ self.log.info("Pair bluetooth iteration {}.".format(n + 1))
+ if (pair_pri_to_sec(self.android_devices[0].droid,
+ self.android_devices[1].droid) == False):
+ self.log.error("Failed to bond devices.")
+ return False
+ for ad in self.android_devices:
+ bonded_devices = ad.droid.bluetoothGetBondedDevices()
+ for b in bonded_devices:
+ ad.droid.bluetoothUnbond(b['address'])
+ #Necessary sleep time for entries to update unbonded state
+ time.sleep(1)
+ bonded_devices = ad.droid.bluetoothGetBondedDevices()
+ if len(bonded_devices) > 0:
+ self.log.error("Failed to unbond devices: {}".format(
+ bonded_devices))
+ return False
+ return True
diff --git a/acts/tests/google/bt/system_tests/RfcommLongevityTest.py b/acts/tests/google/bt/system_tests/RfcommLongevityTest.py
new file mode 100644
index 0000000..119b857
--- /dev/null
+++ b/acts/tests/google/bt/system_tests/RfcommLongevityTest.py
@@ -0,0 +1,404 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""
+Test script to execute Bluetooth basic functionality test cases.
+This test was designed to be run in a shield box.
+"""
+
+import threading
+import time
+from contextlib import suppress
+from random import randint
+
+from queue import Empty
+from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
+from acts.test_utils.bt.bt_test_utils import reset_bluetooth
+from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
+from acts.test_utils.bt.bt_test_utils import rfcomm_accept
+from acts.test_utils.bt.bt_test_utils import rfcomm_connect
+from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
+from acts.test_utils.bt.bt_test_utils import write_read_verify_data
+
+class RfcommLongevityTest(BluetoothBaseTest):
+ default_timeout = 10
+ longev_iterations = 200
+ thread_list = []
+ generic_message = (
+ "Space: the final frontier. These are the voyages of "
+ "the starship Enterprise. Its continuing mission: to explore "
+ "strange new worlds, to seek out new life and new civilizations,"
+ " to boldly go where no man has gone before.")
+
+ def __init__(self, controllers):
+ BluetoothBaseTest.__init__(self, controllers)
+ self.client_ad = self.android_devices[0]
+ self.server_ad = self.android_devices[1]
+
+ def on_fail(self, test_name, begin_time):
+ take_btsnoop_logs(self.android_devices, self, test_name)
+ for _ in range(5):
+ if reset_bluetooth(self.android_devices):
+ break
+ else:
+ self.log.info("Failed to reset bluetooth state, retrying...")
+
+ def teardown_test(self):
+ with suppress(Exception):
+ for thread in self.thread_list:
+ thread.join()
+ for _ in range(5):
+ if reset_bluetooth(self.android_devices):
+ break
+ else:
+ self.log.info("Failed to reset bluetooth state, retrying...")
+ time.sleep(20) #safeguard in case of connId errors
+
+ def orchestrate_rfcomm_connect(self, server_mac):
+ accept_thread = threading.Thread(target=rfcomm_accept,
+ args=(self.server_ad, ))
+ self.thread_list.append(accept_thread)
+ accept_thread.start()
+ connect_thread = threading.Thread(
+ target=rfcomm_connect,
+ args=(self.client_ad, server_mac))
+ self.thread_list.append(connect_thread)
+ connect_thread.start()
+
+ def test_rfcomm_longev_read_write_message(self):
+ """Longevity test an RFCOMM connection's I/O with a generic message
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Repeat steps 2-4 5000 times.
+ 6. Disconnect RFCOMM connection.
+ 7. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ self.generic_message, False):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
+
+ def test_rfcomm_longev_read_write_small_message(self):
+ """Longevity test an RFCOMM connection's I/O with a small message
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence. The data being transfered is only
+ one character in size.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Repeat steps 2-4 5000 times.
+ 6. Disconnect RFCOMM connection.
+ 7. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ message = "x"
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ message, False):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
+
+ def test_rfcomm_longev_read_write_binary_message(self):
+ """Longevity test an RFCOMM connection's I/O with a binary message
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence. The data being transfered is in a
+ binary format.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Repeat steps 2-4 5000 times.
+ 6. Disconnect RFCOMM connection.
+ 7. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ binary_message = "11010101"
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ binary_message, True):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
+
+ def test_rfcomm_longev_read_write_large_message(self):
+ """Longevity test an RFCOMM connection's I/O with a large message
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence. The data being transfered is 990 chars
+ in size.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Repeat steps 2-4 5000 times.
+ 6. Disconnect RFCOMM connection.
+ 7. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ message = "x" * 990 #largest message size till sl4a fixed
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ message, False):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
+
+ def test_rfcomm_longev_connection_interuption(self):
+ """Longevity test an RFCOMM connection's with socket interuptions
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence. Randomly in the sequence of reads and
+ writes the socket on the client side will close. There should be
+ an exception thrown for writing the next set of data and the
+ test should start up a new connection and continue.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Repeat steps 2-4 5000 times or until the random interupt occurs.
+ 6. Re-establish an RFCOMM connection.
+ 7. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+ Devices should recover a new connection after each interruption.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ try:
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ random_interup_iteration = randint(0, write_iterations)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ self.generic_message, False):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ if n > random_interup_iteration:
+ self.client_ad.droid.bluetoothRfcommCloseSocket()
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ except Exception:
+ self.log.info("Exception found as expected. Continuing...")
+ try:
+ self.client_ad.droid.bluetoothRfcommStop()
+ except Exception as err:
+ self.log.error(
+ "Error closing client connection: {}".format(err))
+ return False
+ try:
+ self.server_ad.droid.bluetoothRfcommStop()
+ except Exception as err:
+ self.log.error(
+ "Error closing server connection: {}".format(err))
+ return False
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
+
+ def test_rfcomm_longev_data_elasticity(self):
+ """Longevity test an RFCOMM connection's I/O with changing data size
+
+ Test the longevity of RFCOMM with a basic read/write
+ connect/disconnect sequence. The data being transfered changes
+ in size after each write/read sequence to increase up to 990
+ chars in size and decrease down to 1 in size. This repeats through
+ the entire test in order to exercise different size values being
+ written.
+
+ Steps:
+ 1. Establish a bonding between two Android devices.
+ 2. Write data to RFCOMM from the client droid.
+ 3. Read data from RFCOMM from the server droid.
+ 4. Verify data written matches data read.
+ 5. Change data size according to above description.
+ 6. Repeat steps 2-5 5000 times.
+ 7. Disconnect RFCOMM connection.
+ 8. Repeat steps 1-6 1000 times.
+
+ Expected Result:
+ Each iteration should read and write to the RFCOMM connection
+ successfully. Each connect and disconnect should be successful.
+
+ Returns:
+ Pass if True
+ Fail if False
+
+ TAGS: Classic, Longevity, RFCOMM
+ Priority: 2
+ """
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
+ message = "x"
+ resize_toggle = 1
+ write_iterations = 5000
+ for i in range(self.longev_iterations):
+ try:
+ self.log.info("iteration {} connection".format(i))
+ self.orchestrate_rfcomm_connect(server_mac)
+ for n in range(write_iterations):
+ self.log.info("iteration {} data".format(((n + 1) + (
+ i * write_iterations))))
+ if not write_read_verify_data(self.client_ad, self.server_ad,
+ message, False):
+ return False
+ self.log.info("Iteration {} completed".format(n))
+ size_of_message = len(message)
+ #max size is 990 due to a bug in sl4a.
+ if size_of_message >= 990:
+ resize_toggle = 0
+ elif size_of_message <= 1:
+ resize_toggle = 1
+ if resize_toggle == 0:
+ message = "x" * (size_of_message - 1)
+ else:
+ message = "x" * (size_of_message + 1)
+ self.client_ad.droid.bluetoothRfcommStop()
+ self.server_ad.droid.bluetoothRfcommStop()
+ except Exception as err:
+ self.log.info("Error in longevity test: {}".format(err))
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return False
+
+ for t in self.thread_list:
+ t.join()
+ self.thread_list.clear()
+ return True
diff --git a/acts/tests/google/bt/system_tests/SppStressTest.py b/acts/tests/google/bt/system_tests/RfcommStressTest.py
similarity index 77%
rename from acts/tests/google/bt/system_tests/SppStressTest.py
rename to acts/tests/google/bt/system_tests/RfcommStressTest.py
index cc31303..e9a0e2f 100644
--- a/acts/tests/google/bt/system_tests/SppStressTest.py
+++ b/acts/tests/google/bt/system_tests/RfcommStressTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Test script to execute Bluetooth basic functionality test cases.
This test was designed to be run in a shield box.
@@ -23,7 +22,6 @@
import time
from contextlib import suppress
-
from queue import Empty
from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
from acts.test_utils.bt.bt_test_utils import reset_bluetooth
@@ -34,31 +32,25 @@
from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
-class SppStressTest(BluetoothBaseTest):
+class RfcommStressTest(BluetoothBaseTest):
default_timeout = 10
scan_discovery_time = 5
thread_list = []
- message = ("Space: the final frontier. These are the voyages of "
- "the starship Enterprise. Its continuing mission: to explore "
- "strange new worlds, to seek out new life and new civilizations,"
- " to boldly go where no man has gone before.")
+ message = (
+ "Space: the final frontier. These are the voyages of "
+ "the starship Enterprise. Its continuing mission: to explore "
+ "strange new worlds, to seek out new life and new civilizations,"
+ " to boldly go where no man has gone before.")
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
- self.server_ad = self.android_devices[0]
- self.client_ad = self.android_devices[1]
+ self.client_ad = self.android_devices[0]
+ self.server_ad = self.android_devices[1]
self.tests = (
"test_rfcomm_connection_stress",
"test_rfcomm_read_write_stress",
)
- def _clear_bonded_devices(self):
- for d in self.droids:
- bonded_device_list = d.bluetoothGetConnectedDevices()
- for device in bonded_device_list:
- d.bluetoothUnbond(device)
-
-
def on_fail(self, test_name, begin_time):
take_btsnoop_logs(self.android_devices, self, test_name)
reset_bluetooth(self.android_devices)
@@ -69,12 +61,13 @@
thread.join()
def orchestrate_rfcomm_connect(self, server_mac):
- accept_thread = threading.Thread(
- target=rfcomm_accept, args=(self.server_ad.droid,))
+ accept_thread = threading.Thread(target=rfcomm_accept,
+ args=(self.server_ad.droid, ))
self.thread_list.append(accept_thread)
accept_thread.start()
connect_thread = threading.Thread(
- target=rfcomm_connect, args=(self.client_ad.droid, server_mac))
+ target=rfcomm_connect,
+ args=(self.client_ad, server_mac))
self.thread_list.append(connect_thread)
connect_thread.start()
@@ -99,15 +92,10 @@
Pass if True
Fail if False
- TAGS: Classic, Stress, RFCOMM, SPP
+ TAGS: Classic, Stress, RFCOMM
Priority: 1
"""
- server_mac = get_bt_mac_address(self.client_ad.droid,
- self.server_ad.droid)
- self._clear_bonded_devices()
- # temporary workaround. Need to find out why I can't connect after
- # I do a device discovery from get_bt_mac_address.
- reset_bluetooth([self.server_ad])
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
for n in range(1000):
self.orchestrate_rfcomm_connect(server_mac)
self.log.info("Write message.")
@@ -146,14 +134,10 @@
Pass if True
Fail if False
- TAGS: Classic, Stress, RFCOMM, SPP
+ TAGS: Classic, Stress, RFCOMM
Priority: 1
"""
- server_mac = get_bt_mac_address(self.client_ad.droid,
- self.server_ad.droid)
- self._clear_bonded_devices()
- # temporary workaround. Need to find out why I can't connect after
- # I do a device discovery from get_bt_mac_address.
+ server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
reset_bluetooth([self.server_ad])
self.orchestrate_rfcomm_connect(server_mac)
for n in range(10000):
diff --git a/acts/tests/google/bt/test_tools/BtReconnectTest.py b/acts/tests/google/bt/test_tools/BtReconnectTest.py
index 78933e6..37bbbf6 100644
--- a/acts/tests/google/bt/test_tools/BtReconnectTest.py
+++ b/acts/tests/google/bt/test_tools/BtReconnectTest.py
@@ -26,9 +26,7 @@
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
- self.tests = (
- "test_tool_reconnect",
- )
+ self.tests = ("test_tool_reconnect", )
def setup_class(self):
return setup_multiple_devices_for_bt_test(self.android_devices)
@@ -47,7 +45,7 @@
@BluetoothBaseTest.bt_test_wrap
def test_tool_reconnect(self):
- droid, ed = self.droid, self.ed
+ droid, ed = self.android_devices[0].droid, self.android_devices[0].ed
n = 0
test_result = True
test_result_list = []
@@ -68,13 +66,15 @@
connected_devices = droid.bluetoothGetConnectedDevices()
self.log.info(
"Waiting up to 10 seconds for device to reconnect...")
- while time.time() < start_time + 10 and len(connected_devices) != 1:
+ while time.time() < start_time + 10 and len(
+ connected_devices) != 1:
connected_devices = droid.bluetoothGetConnectedDevices()
if len(connected_devices) > 0:
break
if len(connected_devices) != 1:
- print (
- "Failed to reconnect at iteration {}... continuing".format(n))
+ print(
+ "Failed to reconnect at iteration {}... continuing".format(
+ n))
test_result_list.append(test_result)
n += 1
if False in test_result_list:
diff --git a/acts/tests/google/bt/test_tools/EnergyTest.py b/acts/tests/google/bt/test_tools/EnergyTest.py
index 24a48f3..663cefb 100644
--- a/acts/tests/google/bt/test_tools/EnergyTest.py
+++ b/acts/tests/google/bt/test_tools/EnergyTest.py
@@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-
"""
Continuously poll for energy info for a single Android Device
"""
@@ -24,17 +23,14 @@
class EnergyTest(BluetoothBaseTest):
-
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
- self.tests = (
- "test_continuous_energy_report",
- )
+ self.tests = ("test_continuous_energy_report", )
@BluetoothBaseTest.bt_test_wrap
def test_continuous_energy_report(self):
while (True):
with suppress(Exception):
- self.log.info(
- self.android_devices[0].droid.bluetoothGetControllerActivityEnergyInfo(1))
+ self.log.info(self.android_devices[
+ 0].droid.bluetoothGetControllerActivityEnergyInfo(1))
return True
diff --git a/acts/tests/google/bt/test_tools/ToolsTest.py b/acts/tests/google/bt/test_tools/ToolsTest.py
index 8129854..d1a0aeb 100644
--- a/acts/tests/google/bt/test_tools/ToolsTest.py
+++ b/acts/tests/google/bt/test_tools/ToolsTest.py
@@ -27,13 +27,10 @@
def __init__(self, controllers):
BluetoothBaseTest.__init__(self, controllers)
- self.tests = (
- "test_toggle_bluetooth",
- "test_toggle_airplane_mode",
- "test_create_10_sms",
- "test_continuously_log_battery_stats",
-
- )
+ self.tests = ("test_toggle_bluetooth",
+ "test_toggle_airplane_mode",
+ "test_create_10_sms",
+ "test_continuously_log_battery_stats", )
@BluetoothBaseTest.bt_test_wrap
def test_toggle_bluetooth(self):
@@ -45,8 +42,7 @@
3. Repeat steps 1 and 2 one-hundred times.
:return: boolean test_result
"""
- droid, ed = (self.android_devices[0].droid,
- self.android_devices[0].ed)
+ droid, ed = (self.android_devices[0].droid, self.android_devices[0].ed)
n = 0
test_result = True
test_result_list = []
@@ -55,13 +51,14 @@
test_result = reset_bluetooth([self.android_devices[0]])
start_time = time.time()
connected_devices = droid.bluetoothGetConnectedDevices()
- print (pprint.pformat(connected_devices))
- while time.time() < start_time + 10 and len(connected_devices) != 1:
+ print(pprint.pformat(connected_devices))
+ while time.time() < start_time + 10 and len(
+ connected_devices) != 1:
time.sleep(1)
connected_devices = droid.bluetoothGetConnectedDevices()
- print (pprint.pformat(connected_devices))
+ print(pprint.pformat(connected_devices))
if len(connected_devices) != 1:
- print ("died at iteration {}".format(n))
+ print("died at iteration {}".format(n))
return False
test_result_list.append(test_result)
n += 1
@@ -79,8 +76,7 @@
3. Repeat steps 1 and 2 one-hundred times.
:return: boolean test_result
"""
- droid, ed = (self.android_devices[0].droid,
- self.android_devices[0].ed)
+ droid, ed = (self.android_devices[0].droid, self.android_devices[0].ed)
n = 0
test_result = True
test_result_list = []
@@ -91,13 +87,14 @@
droid.toggleAirplaneMode(False)
start_time = time.time()
connected_devices = droid.bluetoothGetConnectedDevices()
- print (pprint.pformat(connected_devices))
- while time.time() < start_time + 10 and len(connected_devices) != 1:
+ print(pprint.pformat(connected_devices))
+ while time.time() < start_time + 10 and len(
+ connected_devices) != 1:
time.sleep(1)
connected_devices = droid.bluetoothGetConnectedDevices()
- print (pprint.pformat(connected_devices))
+ print(pprint.pformat(connected_devices))
if len(connected_devices) != 1:
- print ("died at iteration {}".format(n))
+ print("died at iteration {}".format(n))
return False
test_result_list.append(test_result)
n += 1
@@ -119,8 +116,7 @@
def test_continuously_log_battery_stats(self):
interval = input("Enter time interval to collect stats: ")
while True:
- self.log.info(
- log_energy_info([self.android_devices[0]], "Log_time: {}"
- .format(time.time())))
+ self.log.info(log_energy_info(
+ [self.android_devices[0]], "Log_time: {}".format(time.time())))
time.sleep(int(interval))
return True