Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 1 | #/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
| 16 | """ |
| 17 | This test script exercises different Bluetooth 5 specific scan scenarios. |
| 18 | It is expected that the second AndroidDevice is able to advertise. |
| 19 | |
| 20 | This test script was designed with this setup in mind: |
| 21 | Shield box one: Android Device, Android Device |
| 22 | """ |
| 23 | |
| 24 | from queue import Empty |
| 25 | |
| 26 | from acts.asserts import assert_equal |
| 27 | from acts.asserts import assert_true |
| 28 | from acts.test_decorators import test_tracker_info |
| 29 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
tturney | 4a2eba1 | 2017-07-21 15:37:22 -0700 | [diff] [blame] | 30 | from acts.test_utils.bt.bt_constants import ble_scan_settings_modes |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 31 | from acts.test_utils.bt.bt_test_utils import advertising_set_started |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 32 | from acts.test_utils.bt.bt_test_utils import advertising_set_stopped |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 33 | from acts.test_utils.bt.bt_test_utils import advertising_set_enabled |
| 34 | from acts.test_utils.bt.bt_test_utils import advertising_set_data_set |
| 35 | from acts.test_utils.bt.bt_test_utils import advertising_set_scan_response_set |
| 36 | from acts.test_utils.bt.bt_test_utils import advertising_set_parameters_update |
| 37 | from acts.test_utils.bt.bt_test_utils import advertising_set_periodic_parameters_updated |
| 38 | from acts.test_utils.bt.bt_test_utils import advertising_set_periodic_data_set |
| 39 | from acts.test_utils.bt.bt_test_utils import advertising_set_periodic_enable |
| 40 | from acts.test_utils.bt.bt_test_utils import reset_bluetooth |
| 41 | from acts import signals |
| 42 | |
| 43 | |
| 44 | class AdvertisingSetTest(BluetoothBaseTest): |
| 45 | default_timeout = 10 |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 46 | report_delay = 2000 |
| 47 | scan_callbacks = [] |
| 48 | adv_callbacks = [] |
| 49 | active_scan_callback_list = [] |
| 50 | big_adv_data = { |
| 51 | "includeDeviceName": True, |
| 52 | "manufacturerData": [0x0123, "00112233445566778899AABBCCDDEE"], |
tturney | 79b11a1 | 2017-06-09 12:59:15 -0700 | [diff] [blame] | 53 | "manufacturerData2": |
| 54 | [0x2540, [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0xFF]], |
| 55 | "serviceData": [ |
| 56 | "b19d42dc-58ba-4b20-b6c1-6628e7d21de4", |
| 57 | "00112233445566778899AABBCCDDEE" |
| 58 | ], |
| 59 | "serviceData2": [ |
| 60 | "000042dc-58ba-4b20-b6c1-6628e7d21de4", |
| 61 | [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0xFF] |
| 62 | ] |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | def __init__(self, controllers): |
| 66 | BluetoothBaseTest.__init__(self, controllers) |
| 67 | self.adv_ad = self.android_devices[0] |
| 68 | |
| 69 | def setup_class(self): |
| 70 | if not self.adv_ad.droid.bluetoothIsLeExtendedAdvertisingSupported(): |
| 71 | raise signals.TestSkipClass( |
| 72 | "Advertiser does not support LE Extended Advertising") |
| 73 | |
| 74 | def teardown_test(self): |
| 75 | self.active_scan_callback_list = [] |
| 76 | |
| 77 | def on_exception(self, test_name, begin_time): |
| 78 | reset_bluetooth(self.android_devices) |
| 79 | |
| 80 | @BluetoothBaseTest.bt_test_wrap |
tturney | 79b11a1 | 2017-06-09 12:59:15 -0700 | [diff] [blame] | 81 | @test_tracker_info(uuid='58182f7e-443f-47fb-b718-1be3ac850287') |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 82 | def test_reenabling(self): |
tturney | 79b11a1 | 2017-06-09 12:59:15 -0700 | [diff] [blame] | 83 | """Test re-enabling an Advertising Set |
| 84 | |
| 85 | Test GATT notify characteristic value. |
| 86 | |
| 87 | Steps: |
| 88 | 1. Start an advertising set that only lasts for a few seconds |
| 89 | 2. Restart advertising set |
| 90 | 3. Repeat steps 1-2 |
| 91 | |
| 92 | Expected Result: |
| 93 | Verify that advertising set re-enables |
| 94 | |
| 95 | Returns: |
| 96 | Pass if True |
| 97 | Fail if False |
| 98 | |
| 99 | TAGS: LE, GATT, Characteristic |
| 100 | Priority: 1 |
| 101 | """ |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 102 | adv_callback = self.adv_ad.droid.bleAdvSetGenCallback() |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 103 | duration = 0 |
| 104 | max_ext_adv_events = 0 |
tturney | 79b11a1 | 2017-06-09 12:59:15 -0700 | [diff] [blame] | 105 | self.adv_ad.droid.bleAdvSetStartAdvertisingSet({ |
| 106 | "connectable": False, |
| 107 | "legacyMode": False, |
| 108 | "primaryPhy": "PHY_LE_1M", |
| 109 | "secondaryPhy": "PHY_LE_1M", |
| 110 | "interval": 320 |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 111 | }, self.big_adv_data, None, None, None, duration, max_ext_adv_events, |
| 112 | adv_callback) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 113 | |
| 114 | set_started_evt = self.adv_ad.ed.pop_event( |
| 115 | advertising_set_started.format(adv_callback), self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 116 | set_id = set_started_evt['data']['setId'] |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 117 | assert_equal(0, set_started_evt['data']['status']) |
| 118 | assert_equal(0, set_started_evt['data']['status']) |
| 119 | |
| 120 | self.log.info("Successfully started set " + str(set_id)) |
| 121 | |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 122 | self.adv_ad.droid.bleAdvSetEnableAdvertising(set_id, False, duration, |
| 123 | max_ext_adv_events) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 124 | enable_evt = self.adv_ad.ed.pop_event( |
| 125 | advertising_set_enabled.format(adv_callback), self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 126 | assert_equal(set_id, enable_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 127 | assert_equal(False, enable_evt['data']['enable']) |
| 128 | assert_equal(0, enable_evt['data']['status']) |
| 129 | self.log.info("Successfully disabled advertising set " + str(set_id)) |
| 130 | |
| 131 | self.log.info("Enabling advertising for 2 seconds... ") |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 132 | duration_200 = 200 |
| 133 | self.adv_ad.droid.bleAdvSetEnableAdvertising( |
| 134 | set_id, True, duration_200, max_ext_adv_events) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 135 | enable_evt = self.adv_ad.ed.pop_event( |
| 136 | advertising_set_enabled.format(adv_callback), self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 137 | assert_equal(set_id, enable_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 138 | assert_equal(True, enable_evt['data']['enable']) |
| 139 | assert_equal(0, enable_evt['data']['status']) |
| 140 | self.log.info("Enabled. Waiting for disable event ~2s ...") |
| 141 | |
| 142 | enable_evt = self.adv_ad.ed.pop_event( |
| 143 | advertising_set_enabled.format(adv_callback), self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 144 | assert_equal(set_id, enable_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 145 | assert_equal(False, enable_evt['data']['enable']) |
| 146 | assert_equal(0, enable_evt['data']['status']) |
| 147 | self.log.info("Disable event received. Now trying to set data...") |
| 148 | |
| 149 | self.adv_ad.droid.bleAdvSetSetAdvertisingData( |
| 150 | set_id, |
| 151 | {"manufacturerData": [0x0123, "00112233445566778899AABBCCDDEE"]}) |
| 152 | data_set_evt = self.adv_ad.ed.pop_event( |
| 153 | advertising_set_data_set.format(adv_callback), |
| 154 | self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 155 | assert_equal(set_id, data_set_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 156 | assert_equal(0, data_set_evt['data']['status']) |
| 157 | self.log.info("Data changed successfully.") |
| 158 | |
| 159 | max_len = self.adv_ad.droid.bluetoothGetLeMaximumAdvertisingDataLength( |
| 160 | ) |
| 161 | |
| 162 | self.log.info("Will try to set data to maximum possible length") |
| 163 | data_len = max_len - 4 |
| 164 | test_fill = '01' * data_len |
| 165 | self.adv_ad.droid.bleAdvSetSetAdvertisingData( |
| 166 | set_id, {"manufacturerData": [0x0123, test_fill]}) |
| 167 | data_set_evt = self.adv_ad.ed.pop_event( |
| 168 | advertising_set_data_set.format(adv_callback), |
| 169 | self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 170 | assert_equal(set_id, data_set_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 171 | assert_equal(0, data_set_evt['data']['status']) |
| 172 | self.log.info("Data changed successfully.") |
| 173 | |
| 174 | if max_len < 1650: |
| 175 | self.log.info("Will try to set data to more than maximum length") |
| 176 | data_len = max_len - 4 + 1 |
| 177 | test_fill = '01' * data_len |
| 178 | self.adv_ad.droid.bleAdvSetSetAdvertisingData( |
| 179 | set_id, {"manufacturerData": [0x0123, test_fill]}) |
| 180 | data_set_evt = self.adv_ad.ed.pop_event( |
| 181 | advertising_set_data_set.format(adv_callback), |
| 182 | self.default_timeout) |
Jakub Pawlowski | 2cc87a2 | 2017-04-24 08:33:27 -0700 | [diff] [blame] | 183 | assert_equal(set_id, data_set_evt['data']['setId']) |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 184 | #TODO(jpawlowski): make nicer error fot this case |
| 185 | assert_true(data_set_evt['data']['status'] != 0, |
| 186 | "Setting data should fail because data too long.") |
| 187 | |
| 188 | self.log.info("Data change failed as expected.") |
| 189 | |
| 190 | self.adv_ad.droid.bleAdvSetStopAdvertisingSet(adv_callback) |
Jakub Pawlowski | 2062ea1 | 2017-06-02 10:41:20 -0700 | [diff] [blame] | 191 | try: |
| 192 | self.adv_ad.ed.pop_event( |
| 193 | advertising_set_stopped.format(adv_callback), |
| 194 | self.default_timeout) |
| 195 | except Empty: |
| 196 | self.log.error("Failed to find advertising set stopped event.") |
| 197 | return False |
Jakub Pawlowski | e6578d9 | 2017-03-09 15:29:59 -0800 | [diff] [blame] | 198 | return True |