Added delay for BtCarMediaConnection test
1)
Updated unassigned attribute in disconnect_pri_from_sec
This should help to avoid false results
2)
Added 5 seconds delay in each BtCarMediaConnection test after pair_pri_to_sec and before disconnect_pri_from_sec.
Note:
I found it helps to minimize failures while disconnecting profiles.
From what I observed if disconnect_pri_from_sec called right after
pair_pri_to_sec a2dp profile remains connected.
3) imported missing bluetooth_socket_conn_test_uuid attribute
Test: 1) Run BtCarMediaConnectionTest:test_a2dp_connect_disconnect_from_src
2) Verify in disconnect_pri_from_sec line 942 doesn't fail with unassigned attribute error
Bug: 76460646
Change-Id: Ie774682d9d2b7754016113196de6858b3f549637
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 f51e476..564433d 100644
--- a/acts/framework/acts/test_utils/bt/bt_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_test_utils.py
@@ -1,4 +1,4 @@
-#/usr/bin/env python3.4
+# /usr/bin/env python3.4
#
# Copyright (C) 2016 The Android Open Source Project
#
@@ -53,6 +53,7 @@
from acts.test_utils.bt.bt_constants import bt_profile_states
from acts.test_utils.bt.bt_constants import bt_profile_constants
from acts.test_utils.bt.bt_constants import bt_rfcomm_uuids
+from acts.test_utils.bt.bt_constants import bluetooth_socket_conn_test_uuid
from acts.test_utils.bt.bt_constants import bt_scan_mode_types
from acts.test_utils.bt.bt_constants import btsnoop_last_log_path_on_device
from acts.test_utils.bt.bt_constants import btsnoop_log_path_on_device
@@ -323,6 +324,7 @@
"Determining number of maximum concurrent advertisements...")
advertisement_count = 0
bt_enabled = False
+ expected_bluetooth_on_event_name = bluetooth_on
if not android_device.droid.bluetoothCheckState():
android_device.droid.bluetoothToggleState(True)
try:
@@ -352,7 +354,7 @@
regex = "(" + adv_succ.format(
advertise_callback) + "|" + adv_fail.format(
- advertise_callback) + ")"
+ advertise_callback) + ")"
# wait for either success or failure event
evt = android_device.ed.pop_events(regex, bt_default_timeout,
small_timeout)
@@ -405,7 +407,7 @@
else:
max_advertisements = determine_max_advertisements(a)
max_tries = 3
- #Retry to calculate max advertisements
+ # Retry to calculate max advertisements
while max_advertisements == -1 and max_tries > 0:
a.log.info(
"Attempts left to determine max advertisements: {}".format(
@@ -428,7 +430,7 @@
def generate_id_by_size(
size,
chars=(
- string.ascii_lowercase + string.ascii_uppercase + string.digits)):
+ string.ascii_lowercase + string.ascii_uppercase + string.digits)):
"""Generate random ascii characters of input size and input char types
Args:
@@ -468,7 +470,7 @@
except Exception as err:
adv_android_device.log.debug(
"Failed to stop LE advertisement... reseting Bluetooth. Error {}".
- format(err))
+ format(err))
reset_bluetooth([adv_android_device])
@@ -834,7 +836,7 @@
paired = False
for paired_device in pri_ad.droid.bluetoothGetBondedDevices():
if paired_device['address'] == \
- sec_ad.droid.bluetoothGetLocalAddress():
+ sec_ad.droid.bluetoothGetLocalAddress():
paired = True
break
@@ -892,7 +894,7 @@
device_addr = profile_event['data']['addr']
if state == bt_profile_states['connected'] and \
- device_addr == sec_ad.droid.bluetoothGetLocalAddress():
+ device_addr == sec_ad.droid.bluetoothGetLocalAddress():
profile_connected.add(profile)
pri_ad.log.info(
"Profiles connected until now {}".format(profile_connected))
@@ -940,10 +942,10 @@
while not profile_disconnected.issuperset(profiles_list):
try:
profile_event = pri_ad.ed.pop_event(
- bluetooth_profile_connection_state_changed, default_timeout)
+ bluetooth_profile_connection_state_changed, bt_default_timeout)
pri_ad.log.info("Got event {}".format(profile_event))
- except Exception:
- pri_ad.log.error("Did not disconnect from Profiles")
+ except Exception as e:
+ pri_ad.log.error("Did not disconnect from Profiles. Reason {}".format(e))
return False
profile = profile_event['data']['profile']
@@ -951,7 +953,7 @@
device_addr = profile_event['data']['addr']
if state == bt_profile_states['disconnected'] and \
- device_addr == sec_ad.droid.bluetoothGetLocalAddress():
+ device_addr == sec_ad.droid.bluetoothGetLocalAddress():
profile_disconnected.add(profile)
pri_ad.log.info(
"Profiles disconnected so far {}".format(profile_disconnected))
diff --git a/acts/tests/google/bt/car_bt/BtCarMediaConnectionTest.py b/acts/tests/google/bt/car_bt/BtCarMediaConnectionTest.py
index 7865bc1..d8275d4 100644
--- a/acts/tests/google/bt/car_bt/BtCarMediaConnectionTest.py
+++ b/acts/tests/google/bt/car_bt/BtCarMediaConnectionTest.py
@@ -1,4 +1,4 @@
-#/usr/bin/env python3.4
+# /usr/bin/env python3.4
#
# Copyright (C) 2016 The Android Open Source Project
#
@@ -73,7 +73,7 @@
devices = device1.droid.bluetoothA2dpSinkGetConnectedDevices()
for device in devices:
self.device1.log.info("A2dp Connected device {}".format(device[
- "name"]))
+ "name"]))
if (device["address"] == device2.droid.bluetoothGetLocalAddress()):
return True
return False
@@ -106,11 +106,12 @@
self.SRC, self.SNK,
set([BtEnum.BluetoothProfile.A2DP.value]))):
return False
-
+ # Delay to establish A2DP connection before disconnecting
+ time.sleep(5)
result = bt_test_utils.disconnect_pri_from_sec(
self.SRC, self.SNK, [BtEnum.BluetoothProfile.A2DP.value])
# Grace timeout to allow a2dp time to disconnect
- time.sleep(3)
+ time.sleep(2)
if not result:
# Additional profile connection check for b/
if bt_test_utils.is_a2dp_src_device_connected(
@@ -153,11 +154,13 @@
self.SNK, self.SRC,
set([BtEnum.BluetoothProfile.A2DP_SINK.value]))):
return False
+ # Delay to establish A2DP connection before disconnecting
+ time.sleep(5)
# Disconnect
result = bt_test_utils.disconnect_pri_from_sec(
self.SNK, self.SRC, [BtEnum.BluetoothProfile.A2DP_SINK.value])
# Grace timeout to allow a2dp time to disconnect
- time.sleep(3)
+ time.sleep(2)
if not result:
# Additional profile connection check for b/
if bt_test_utils.is_a2dp_snk_device_connected(