Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Treehugger Robot | 5e0277f | 2023-05-12 02:44:22 +0000 | [diff] [blame] | 17 | #include <VtsCoreUtil.h> |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 18 | #include <aidl/Gtest.h> |
| 19 | #include <aidl/Vintf.h> |
| 20 | #include <aidl/android/hardware/bluetooth/BnBluetoothHciCallbacks.h> |
| 21 | #include <aidl/android/hardware/bluetooth/IBluetoothHci.h> |
| 22 | #include <aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.h> |
| 23 | #include <aidl/android/hardware/bluetooth/Status.h> |
Treehugger Robot | 5e0277f | 2023-05-12 02:44:22 +0000 | [diff] [blame] | 24 | #include <android-base/properties.h> |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 25 | #include <android/binder_auto_utils.h> |
| 26 | #include <android/binder_manager.h> |
| 27 | #include <android/binder_process.h> |
| 28 | #include <binder/IServiceManager.h> |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 29 | |
| 30 | #include <atomic> |
| 31 | #include <chrono> |
| 32 | #include <condition_variable> |
| 33 | #include <future> |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 34 | #include <queue> |
| 35 | #include <thread> |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 36 | #include <utility> |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 37 | #include <vector> |
| 38 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 39 | // TODO: Remove custom logging defines from PDL packets. |
| 40 | #undef LOG_INFO |
| 41 | #undef LOG_DEBUG |
| 42 | #undef LOG_TAG |
| 43 | #define LOG_TAG "VtsHalBluetooth" |
| 44 | #include "hci/hci_packets.h" |
| 45 | #include "packet/raw_builder.h" |
| 46 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 47 | using aidl::android::hardware::bluetooth::IBluetoothHci; |
| 48 | using aidl::android::hardware::bluetooth::IBluetoothHciCallbacks; |
| 49 | using aidl::android::hardware::bluetooth::Status; |
| 50 | using ndk::ScopedAStatus; |
| 51 | using ndk::SpAIBinder; |
| 52 | |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 53 | using ::bluetooth::hci::CommandBuilder; |
| 54 | using ::bluetooth::hci::CommandCompleteView; |
| 55 | using ::bluetooth::hci::CommandView; |
| 56 | using ::bluetooth::hci::ErrorCode; |
| 57 | using ::bluetooth::hci::EventView; |
| 58 | using ::bluetooth::hci::LeReadLocalSupportedFeaturesBuilder; |
| 59 | using ::bluetooth::hci::LeReadLocalSupportedFeaturesCompleteView; |
| 60 | using ::bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsBuilder; |
| 61 | using ::bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsCompleteView; |
| 62 | using ::bluetooth::hci::LeReadResolvingListSizeBuilder; |
| 63 | using ::bluetooth::hci::LeReadResolvingListSizeCompleteView; |
| 64 | using ::bluetooth::hci::LLFeaturesBits; |
| 65 | using ::bluetooth::hci::OpCode; |
| 66 | using ::bluetooth::hci::OpCodeText; |
| 67 | using ::bluetooth::hci::PacketView; |
| 68 | using ::bluetooth::hci::ReadLocalVersionInformationBuilder; |
| 69 | using ::bluetooth::hci::ReadLocalVersionInformationCompleteView; |
| 70 | |
| 71 | static constexpr uint8_t kMinLeAdvSetForBt5 = 16; |
Treehugger Robot | 5e0277f | 2023-05-12 02:44:22 +0000 | [diff] [blame] | 72 | static constexpr uint8_t kMinLeAdvSetForBt5FoTv = 10; |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 73 | static constexpr uint8_t kMinLeResolvingListForBt5 = 8; |
| 74 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 75 | static constexpr size_t kNumHciCommandsBandwidth = 100; |
| 76 | static constexpr size_t kNumScoPacketsBandwidth = 100; |
| 77 | static constexpr size_t kNumAclPacketsBandwidth = 100; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 78 | static constexpr std::chrono::milliseconds kWaitForInitTimeout(2000); |
| 79 | static constexpr std::chrono::milliseconds kWaitForHciEventTimeout(2000); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 80 | static constexpr std::chrono::milliseconds kWaitForScoDataTimeout(1000); |
| 81 | static constexpr std::chrono::milliseconds kWaitForAclDataTimeout(1000); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 82 | static constexpr std::chrono::milliseconds kInterfaceCloseDelayMs(200); |
| 83 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 84 | // To discard Qualcomm ACL debugging |
| 85 | static constexpr uint16_t kAclHandleQcaDebugMessage = 0xedc; |
| 86 | |
Treehugger Robot | 5e0277f | 2023-05-12 02:44:22 +0000 | [diff] [blame] | 87 | static int get_vsr_api_level() { |
| 88 | int vendor_api_level = |
| 89 | ::android::base::GetIntProperty("ro.vendor.api_level", -1); |
| 90 | if (vendor_api_level != -1) { |
| 91 | return vendor_api_level; |
| 92 | } |
| 93 | |
| 94 | // Android S and older devices do not define ro.vendor.api_level |
| 95 | vendor_api_level = ::android::base::GetIntProperty("ro.board.api_level", -1); |
| 96 | if (vendor_api_level == -1) { |
| 97 | vendor_api_level = |
| 98 | ::android::base::GetIntProperty("ro.board.first_api_level", -1); |
| 99 | } |
| 100 | |
| 101 | int product_api_level = |
| 102 | ::android::base::GetIntProperty("ro.product.first_api_level", -1); |
| 103 | if (product_api_level == -1) { |
| 104 | product_api_level = |
| 105 | ::android::base::GetIntProperty("ro.build.version.sdk", -1); |
| 106 | EXPECT_NE(product_api_level, -1) << "Could not find ro.build.version.sdk"; |
| 107 | } |
| 108 | |
| 109 | // VSR API level is the minimum of vendor_api_level and product_api_level. |
| 110 | if (vendor_api_level == -1 || vendor_api_level > product_api_level) { |
| 111 | return product_api_level; |
| 112 | } |
| 113 | return vendor_api_level; |
| 114 | } |
| 115 | |
| 116 | static bool isTv() { |
| 117 | return testing::deviceSupportsFeature("android.software.leanback") || |
| 118 | testing::deviceSupportsFeature("android.hardware.type.television"); |
| 119 | } |
| 120 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 121 | class ThroughputLogger { |
| 122 | public: |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 123 | explicit ThroughputLogger(std::string task) |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 124 | : total_bytes_(0), |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 125 | task_(std::move(task)), |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 126 | start_time_(std::chrono::steady_clock::now()) {} |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 127 | |
| 128 | ~ThroughputLogger() { |
| 129 | if (total_bytes_ == 0) { |
| 130 | return; |
| 131 | } |
| 132 | std::chrono::duration<double> duration = |
| 133 | std::chrono::steady_clock::now() - start_time_; |
| 134 | double s = duration.count(); |
| 135 | if (s == 0) { |
| 136 | return; |
| 137 | } |
| 138 | double rate_kb = (static_cast<double>(total_bytes_) / s) / 1024; |
| 139 | ALOGD("%s %.1f KB/s (%zu bytes in %.3fs)", task_.c_str(), rate_kb, |
| 140 | total_bytes_, s); |
| 141 | } |
| 142 | |
| 143 | void setTotalBytes(size_t total_bytes) { total_bytes_ = total_bytes; } |
| 144 | |
| 145 | private: |
| 146 | size_t total_bytes_; |
| 147 | std::string task_; |
| 148 | std::chrono::steady_clock::time_point start_time_; |
| 149 | }; |
| 150 | |
| 151 | // The main test class for Bluetooth HAL. |
| 152 | class BluetoothAidlTest : public ::testing::TestWithParam<std::string> { |
| 153 | public: |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 154 | void SetUp() override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 155 | // currently test passthrough mode only |
| 156 | hci = IBluetoothHci::fromBinder( |
| 157 | SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 158 | ASSERT_NE(hci, nullptr); |
| 159 | ALOGI("%s: getService() for bluetooth hci is %s", __func__, |
| 160 | hci->isRemote() ? "remote" : "local"); |
| 161 | |
| 162 | // Lambda function |
| 163 | auto on_binder_death = [](void* /*cookie*/) { FAIL(); }; |
| 164 | |
| 165 | bluetooth_hci_death_recipient = |
| 166 | AIBinder_DeathRecipient_new(on_binder_death); |
| 167 | ASSERT_NE(bluetooth_hci_death_recipient, nullptr); |
| 168 | ASSERT_EQ(STATUS_OK, |
| 169 | AIBinder_linkToDeath(hci->asBinder().get(), |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 170 | bluetooth_hci_death_recipient, nullptr)); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 171 | |
| 172 | hci_cb = ndk::SharedRefBase::make<BluetoothHciCallbacks>(*this); |
| 173 | ASSERT_NE(hci_cb, nullptr); |
| 174 | |
| 175 | max_acl_data_packet_length = 0; |
| 176 | max_sco_data_packet_length = 0; |
| 177 | max_acl_data_packets = 0; |
| 178 | max_sco_data_packets = 0; |
| 179 | |
| 180 | event_cb_count = 0; |
| 181 | acl_cb_count = 0; |
| 182 | sco_cb_count = 0; |
| 183 | |
| 184 | ASSERT_TRUE(hci->initialize(hci_cb).isOk()); |
| 185 | auto future = initialized_promise.get_future(); |
| 186 | auto timeout_status = future.wait_for(kWaitForInitTimeout); |
| 187 | ASSERT_EQ(timeout_status, std::future_status::ready); |
| 188 | ASSERT_TRUE(future.get()); |
| 189 | } |
| 190 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 191 | void TearDown() override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 192 | ALOGI("TearDown"); |
| 193 | // Should not be checked in production code |
| 194 | ASSERT_TRUE(hci->close().isOk()); |
| 195 | std::this_thread::sleep_for(kInterfaceCloseDelayMs); |
| 196 | handle_no_ops(); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 197 | discard_qca_debugging(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 198 | EXPECT_EQ(static_cast<size_t>(0), event_queue.size()); |
| 199 | EXPECT_EQ(static_cast<size_t>(0), sco_queue.size()); |
| 200 | EXPECT_EQ(static_cast<size_t>(0), acl_queue.size()); |
| 201 | EXPECT_EQ(static_cast<size_t>(0), iso_queue.size()); |
| 202 | } |
| 203 | |
| 204 | void setBufferSizes(); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 205 | void setSynchronousFlowControlEnable(); |
| 206 | |
| 207 | // Functions called from within tests in loopback mode |
| 208 | void sendAndCheckHci(int num_packets); |
| 209 | void sendAndCheckSco(int num_packets, size_t size, uint16_t handle); |
| 210 | void sendAndCheckAcl(int num_packets, size_t size, uint16_t handle); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 211 | |
| 212 | // Helper functions to try to get a handle on verbosity |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 213 | void enterLoopbackMode(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 214 | void handle_no_ops(); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 215 | void discard_qca_debugging(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 216 | void wait_for_event(bool timeout_is_error); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 217 | void wait_for_command_complete_event(OpCode opCode, |
| 218 | std::vector<uint8_t>& complete_event); |
| 219 | // Wait until a command complete is received. |
| 220 | // Command complete will be consumed after this method |
| 221 | void wait_and_validate_command_complete_event(OpCode opCode); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 222 | int wait_for_completed_packets_event(uint16_t handle); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 223 | void send_and_wait_for_cmd_complete(std::unique_ptr<CommandBuilder> cmd, |
| 224 | std::vector<uint8_t>& cmd_complete); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 225 | |
| 226 | // A simple test implementation of BluetoothHciCallbacks. |
| 227 | class BluetoothHciCallbacks |
| 228 | : public aidl::android::hardware::bluetooth::BnBluetoothHciCallbacks { |
| 229 | BluetoothAidlTest& parent_; |
| 230 | |
| 231 | public: |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 232 | explicit BluetoothHciCallbacks(BluetoothAidlTest& parent) |
| 233 | : parent_(parent){}; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 234 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 235 | ~BluetoothHciCallbacks() override = default; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 236 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 237 | ndk::ScopedAStatus initializationComplete(Status status) override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 238 | parent_.initialized_promise.set_value(status == Status::SUCCESS); |
| 239 | ALOGV("%s (status = %d)", __func__, static_cast<int>(status)); |
| 240 | return ScopedAStatus::ok(); |
| 241 | }; |
| 242 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 243 | ndk::ScopedAStatus hciEventReceived( |
| 244 | const std::vector<uint8_t>& event) override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 245 | parent_.event_cb_count++; |
| 246 | parent_.event_queue.push(event); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 247 | ALOGI("Event received (length = %d)", static_cast<int>(event.size())); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 248 | return ScopedAStatus::ok(); |
| 249 | }; |
| 250 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 251 | ndk::ScopedAStatus aclDataReceived( |
| 252 | const std::vector<uint8_t>& data) override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 253 | parent_.acl_cb_count++; |
| 254 | parent_.acl_queue.push(data); |
| 255 | return ScopedAStatus::ok(); |
| 256 | }; |
| 257 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 258 | ndk::ScopedAStatus scoDataReceived( |
| 259 | const std::vector<uint8_t>& data) override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 260 | parent_.sco_cb_count++; |
| 261 | parent_.sco_queue.push(data); |
| 262 | return ScopedAStatus::ok(); |
| 263 | }; |
| 264 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 265 | ndk::ScopedAStatus isoDataReceived( |
| 266 | const std::vector<uint8_t>& data) override { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 267 | parent_.iso_cb_count++; |
| 268 | parent_.iso_queue.push(data); |
| 269 | return ScopedAStatus::ok(); |
| 270 | }; |
| 271 | }; |
| 272 | |
| 273 | template <class T> |
| 274 | class WaitQueue { |
| 275 | public: |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 276 | WaitQueue() = default; |
| 277 | ; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 278 | |
| 279 | virtual ~WaitQueue() = default; |
| 280 | |
| 281 | bool empty() const { |
| 282 | std::lock_guard<std::mutex> lock(m_); |
| 283 | return q_.empty(); |
| 284 | }; |
| 285 | |
| 286 | size_t size() const { |
| 287 | std::lock_guard<std::mutex> lock(m_); |
| 288 | return q_.size(); |
| 289 | }; |
| 290 | |
| 291 | void push(const T& v) { |
| 292 | std::lock_guard<std::mutex> lock(m_); |
| 293 | q_.push(v); |
| 294 | ready_.notify_one(); |
| 295 | }; |
| 296 | |
| 297 | bool pop(T& v) { |
| 298 | std::lock_guard<std::mutex> lock(m_); |
| 299 | if (q_.empty()) { |
| 300 | return false; |
| 301 | } |
| 302 | v = std::move(q_.front()); |
| 303 | q_.pop(); |
| 304 | return true; |
| 305 | }; |
| 306 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 307 | void pop() { |
| 308 | std::lock_guard<std::mutex> lock(m_); |
| 309 | if (q_.empty()) { |
| 310 | return; |
| 311 | } |
| 312 | q_.pop(); |
| 313 | }; |
| 314 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 315 | bool front(T& v) { |
| 316 | std::lock_guard<std::mutex> lock(m_); |
| 317 | if (q_.empty()) { |
| 318 | return false; |
| 319 | } |
| 320 | v = q_.front(); |
| 321 | return true; |
| 322 | }; |
| 323 | |
| 324 | void wait() { |
| 325 | std::unique_lock<std::mutex> lock(m_); |
| 326 | while (q_.empty()) { |
| 327 | ready_.wait(lock); |
| 328 | } |
| 329 | }; |
| 330 | |
| 331 | bool waitWithTimeout(std::chrono::milliseconds timeout) { |
| 332 | std::unique_lock<std::mutex> lock(m_); |
| 333 | while (q_.empty()) { |
| 334 | if (ready_.wait_for(lock, timeout) == std::cv_status::timeout) { |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | return true; |
| 339 | }; |
| 340 | |
| 341 | bool tryPopWithTimeout(T& v, std::chrono::milliseconds timeout) { |
| 342 | std::unique_lock<std::mutex> lock(m_); |
| 343 | while (q_.empty()) { |
| 344 | if (ready_.wait_for(lock, timeout) == std::cv_status::timeout) { |
| 345 | return false; |
| 346 | } |
| 347 | } |
| 348 | v = std::move(q_.front()); |
| 349 | q_.pop(); |
| 350 | return true; |
| 351 | }; |
| 352 | |
| 353 | private: |
| 354 | mutable std::mutex m_; |
| 355 | std::queue<T> q_; |
| 356 | std::condition_variable_any ready_; |
| 357 | }; |
| 358 | |
| 359 | std::shared_ptr<IBluetoothHci> hci; |
| 360 | std::shared_ptr<BluetoothHciCallbacks> hci_cb; |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 361 | AIBinder_DeathRecipient* bluetooth_hci_death_recipient{}; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 362 | WaitQueue<std::vector<uint8_t>> event_queue; |
| 363 | WaitQueue<std::vector<uint8_t>> acl_queue; |
| 364 | WaitQueue<std::vector<uint8_t>> sco_queue; |
| 365 | WaitQueue<std::vector<uint8_t>> iso_queue; |
| 366 | |
| 367 | std::promise<bool> initialized_promise; |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 368 | int event_cb_count{}; |
| 369 | int sco_cb_count{}; |
| 370 | int acl_cb_count{}; |
| 371 | int iso_cb_count{}; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 372 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 373 | int max_acl_data_packet_length{}; |
| 374 | int max_sco_data_packet_length{}; |
| 375 | int max_acl_data_packets{}; |
| 376 | int max_sco_data_packets{}; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 377 | |
| 378 | std::vector<uint16_t> sco_connection_handles; |
| 379 | std::vector<uint16_t> acl_connection_handles; |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | // Discard NO-OPs from the event queue. |
| 383 | void BluetoothAidlTest::handle_no_ops() { |
| 384 | while (!event_queue.empty()) { |
| 385 | std::vector<uint8_t> event; |
| 386 | event_queue.front(event); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 387 | auto complete_view = ::bluetooth::hci::CommandCompleteView::Create( |
| 388 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 389 | std::make_shared<std::vector<uint8_t>>(event)))); |
| 390 | auto status_view = ::bluetooth::hci::CommandCompleteView::Create( |
| 391 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 392 | std::make_shared<std::vector<uint8_t>>(event)))); |
| 393 | bool is_complete_no_op = |
| 394 | complete_view.IsValid() && |
| 395 | complete_view.GetCommandOpCode() == ::bluetooth::hci::OpCode::NONE; |
| 396 | bool is_status_no_op = |
| 397 | status_view.IsValid() && |
| 398 | status_view.GetCommandOpCode() == ::bluetooth::hci::OpCode::NONE; |
| 399 | if (is_complete_no_op || is_status_no_op) { |
| 400 | event_queue.pop(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 401 | } else { |
| 402 | break; |
| 403 | } |
| 404 | } |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | // Discard Qualcomm ACL debugging |
| 408 | void BluetoothAidlTest::discard_qca_debugging() { |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 409 | while (!acl_queue.empty()) { |
| 410 | std::vector<uint8_t> acl_packet; |
| 411 | acl_queue.front(acl_packet); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 412 | auto acl_view = |
| 413 | ::bluetooth::hci::AclView::Create(::bluetooth::hci::PacketView<true>( |
| 414 | std::make_shared<std::vector<uint8_t>>(acl_packet))); |
| 415 | EXPECT_TRUE(acl_view.IsValid()); |
| 416 | if (acl_view.GetHandle() == kAclHandleQcaDebugMessage) { |
| 417 | acl_queue.pop(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 418 | } else { |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // Receive an event, discarding NO-OPs. |
| 425 | void BluetoothAidlTest::wait_for_event(bool timeout_is_error = true) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 426 | // Wait until we get something that's not a no-op. |
| 427 | while (true) { |
| 428 | bool event_ready = event_queue.waitWithTimeout(kWaitForHciEventTimeout); |
| 429 | ASSERT_TRUE(event_ready || !timeout_is_error); |
| 430 | if (event_queue.empty()) { |
| 431 | // waitWithTimeout timed out |
| 432 | return; |
| 433 | } |
| 434 | handle_no_ops(); |
| 435 | if (!event_queue.empty()) { |
| 436 | // There's an event in the queue that's not a no-op. |
| 437 | return; |
| 438 | } |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 439 | } |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 442 | void BluetoothAidlTest::wait_for_command_complete_event( |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 443 | OpCode opCode, std::vector<uint8_t>& complete_event) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 444 | ASSERT_NO_FATAL_FAILURE(wait_for_event()); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 445 | ASSERT_FALSE(event_queue.empty()); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 446 | ASSERT_TRUE(event_queue.pop(complete_event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 447 | auto complete_view = ::bluetooth::hci::CommandCompleteView::Create( |
| 448 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 449 | std::make_shared<std::vector<uint8_t>>(complete_event)))); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 450 | ASSERT_TRUE(complete_view.IsValid()); |
| 451 | ASSERT_EQ(complete_view.GetCommandOpCode(), opCode); |
| 452 | ASSERT_EQ(complete_view.GetPayload()[0], |
| 453 | static_cast<uint8_t>(::bluetooth::hci::ErrorCode::SUCCESS)); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 456 | void BluetoothAidlTest::wait_and_validate_command_complete_event( |
| 457 | ::bluetooth::hci::OpCode opCode) { |
| 458 | std::vector<uint8_t> complete_event; |
| 459 | ASSERT_NO_FATAL_FAILURE( |
| 460 | wait_for_command_complete_event(opCode, complete_event)); |
| 461 | } |
| 462 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 463 | // Send the command to read the controller's buffer sizes. |
| 464 | void BluetoothAidlTest::setBufferSizes() { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 465 | std::vector<uint8_t> cmd; |
| 466 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 467 | ::bluetooth::hci::ReadBufferSizeBuilder::Create()->Serialize(bi); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 468 | hci->sendHciCommand(cmd); |
| 469 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 470 | ASSERT_NO_FATAL_FAILURE(wait_for_event()); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 471 | std::vector<uint8_t> event; |
| 472 | ASSERT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 473 | auto complete_view = ::bluetooth::hci::ReadBufferSizeCompleteView::Create( |
| 474 | ::bluetooth::hci::CommandCompleteView::Create( |
| 475 | ::bluetooth::hci::EventView::Create( |
| 476 | ::bluetooth::hci::PacketView<true>( |
| 477 | std::make_shared<std::vector<uint8_t>>(event))))); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 478 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 479 | ASSERT_TRUE(complete_view.IsValid()); |
| 480 | ASSERT_EQ(complete_view.GetStatus(), ::bluetooth::hci::ErrorCode::SUCCESS); |
| 481 | max_acl_data_packet_length = complete_view.GetAclDataPacketLength(); |
| 482 | max_sco_data_packet_length = complete_view.GetSynchronousDataPacketLength(); |
| 483 | max_acl_data_packets = complete_view.GetTotalNumAclDataPackets(); |
| 484 | max_sco_data_packets = complete_view.GetTotalNumSynchronousDataPackets(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 485 | |
| 486 | ALOGD("%s: ACL max %d num %d SCO max %d num %d", __func__, |
| 487 | static_cast<int>(max_acl_data_packet_length), |
| 488 | static_cast<int>(max_acl_data_packets), |
| 489 | static_cast<int>(max_sco_data_packet_length), |
| 490 | static_cast<int>(max_sco_data_packets)); |
| 491 | } |
| 492 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 493 | // Enable flow control packets for SCO |
| 494 | void BluetoothAidlTest::setSynchronousFlowControlEnable() { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 495 | std::vector<uint8_t> cmd; |
| 496 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 497 | ::bluetooth::hci::WriteSynchronousFlowControlEnableBuilder::Create( |
| 498 | ::bluetooth::hci::Enable::ENABLED) |
| 499 | ->Serialize(bi); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 500 | hci->sendHciCommand(cmd); |
| 501 | |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 502 | wait_and_validate_command_complete_event( |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 503 | ::bluetooth::hci::OpCode::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // Send an HCI command (in Loopback mode) and check the response. |
| 507 | void BluetoothAidlTest::sendAndCheckHci(int num_packets) { |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 508 | ThroughputLogger logger{__func__}; |
| 509 | size_t command_size = 0; |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 510 | char new_name[] = "John Jacob Jingleheimer Schmidt ___________________"; |
| 511 | size_t new_name_length = strlen(new_name); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 512 | for (int n = 0; n < num_packets; n++) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 513 | // The name to set is new_name |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 514 | std::array<uint8_t, 248> name_array{}; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 515 | for (size_t i = 0; i < new_name_length; i++) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 516 | name_array[i] = new_name[i]; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 517 | } |
| 518 | // And the packet number |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 519 | char number[11] = "0000000000"; |
| 520 | snprintf(number, sizeof(number), "%010d", static_cast<int>(n)); |
| 521 | for (size_t i = new_name_length; i < new_name_length + sizeof(number) - 1; |
| 522 | i++) { |
| 523 | name_array[new_name_length + i] = number[i]; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 524 | } |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 525 | std::vector<uint8_t> write_name; |
| 526 | ::bluetooth::packet::BitInserter bi{write_name}; |
| 527 | ::bluetooth::hci::WriteLocalNameBuilder::Create(name_array)->Serialize(bi); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 528 | hci->sendHciCommand(write_name); |
| 529 | |
| 530 | // Check the loopback of the HCI packet |
| 531 | ASSERT_NO_FATAL_FAILURE(wait_for_event()); |
| 532 | |
| 533 | std::vector<uint8_t> event; |
| 534 | ASSERT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 535 | auto event_view = ::bluetooth::hci::LoopbackCommandView::Create( |
| 536 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 537 | std::make_shared<std::vector<uint8_t>>(event)))); |
| 538 | ASSERT_TRUE(event_view.IsValid()); |
| 539 | std::vector<uint8_t> looped_back_command{event_view.GetPayload().begin(), |
| 540 | event_view.GetPayload().end()}; |
| 541 | ASSERT_EQ(looped_back_command, write_name); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 542 | |
| 543 | if (n == num_packets - 1) { |
| 544 | command_size = write_name.size(); |
| 545 | } |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 546 | } |
| 547 | logger.setTotalBytes(command_size * num_packets * 2); |
| 548 | } |
| 549 | |
| 550 | // Send a SCO data packet (in Loopback mode) and check the response. |
| 551 | void BluetoothAidlTest::sendAndCheckSco(int num_packets, size_t size, |
| 552 | uint16_t handle) { |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 553 | ThroughputLogger logger{__func__}; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 554 | for (int n = 0; n < num_packets; n++) { |
| 555 | // Send a SCO packet |
| 556 | std::vector<uint8_t> sco_packet; |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 557 | std::vector<uint8_t> payload; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 558 | for (size_t i = 0; i < size; i++) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 559 | payload.push_back(static_cast<uint8_t>(i + n)); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 560 | } |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 561 | ::bluetooth::packet::BitInserter bi{sco_packet}; |
| 562 | ::bluetooth::hci::ScoBuilder::Create( |
| 563 | handle, ::bluetooth::hci::PacketStatusFlag::CORRECTLY_RECEIVED, payload) |
| 564 | ->Serialize(bi); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 565 | hci->sendScoData(sco_packet); |
| 566 | |
| 567 | // Check the loopback of the SCO packet |
| 568 | std::vector<uint8_t> sco_loopback; |
| 569 | ASSERT_TRUE( |
| 570 | sco_queue.tryPopWithTimeout(sco_loopback, kWaitForScoDataTimeout)); |
| 571 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 572 | ASSERT_EQ(sco_packet, sco_loopback); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 573 | } |
| 574 | logger.setTotalBytes(num_packets * size * 2); |
| 575 | } |
| 576 | |
| 577 | // Send an ACL data packet (in Loopback mode) and check the response. |
| 578 | void BluetoothAidlTest::sendAndCheckAcl(int num_packets, size_t size, |
| 579 | uint16_t handle) { |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 580 | ThroughputLogger logger{__func__}; |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 581 | for (int n = 0; n < num_packets; n++) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 582 | // Send an ACL packet with counting data |
| 583 | auto payload = std::make_unique<::bluetooth::packet::RawBuilder>(); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 584 | for (size_t i = 0; i < size; i++) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 585 | payload->AddOctets1(static_cast<uint8_t>(i + n)); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 586 | } |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 587 | std::vector<uint8_t> acl_packet; |
| 588 | ::bluetooth::packet::BitInserter bi{acl_packet}; |
| 589 | ::bluetooth::hci::AclBuilder::Create( |
| 590 | handle, |
| 591 | ::bluetooth::hci::PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE, |
| 592 | ::bluetooth::hci::BroadcastFlag::POINT_TO_POINT, std::move(payload)) |
| 593 | ->Serialize(bi); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 594 | hci->sendAclData(acl_packet); |
| 595 | |
| 596 | std::vector<uint8_t> acl_loopback; |
| 597 | // Check the loopback of the ACL packet |
| 598 | ASSERT_TRUE( |
| 599 | acl_queue.tryPopWithTimeout(acl_loopback, kWaitForAclDataTimeout)); |
| 600 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 601 | ASSERT_EQ(acl_packet, acl_loopback); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 602 | } |
| 603 | logger.setTotalBytes(num_packets * size * 2); |
| 604 | } |
| 605 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 606 | // Return the number of completed packets reported by the controller. |
| 607 | int BluetoothAidlTest::wait_for_completed_packets_event(uint16_t handle) { |
| 608 | int packets_processed = 0; |
Myles Watson | 65b47f5 | 2023-01-26 12:59:06 -0800 | [diff] [blame] | 609 | while (true) { |
| 610 | // There should be at least one event. |
| 611 | wait_for_event(packets_processed == 0); |
| 612 | if (event_queue.empty()) { |
| 613 | if (packets_processed == 0) { |
| 614 | ALOGW("%s: waitForBluetoothCallback timed out.", __func__); |
| 615 | } |
| 616 | return packets_processed; |
| 617 | } |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 618 | std::vector<uint8_t> event; |
| 619 | EXPECT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 620 | auto event_view = ::bluetooth::hci::NumberOfCompletedPacketsView::Create( |
| 621 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 622 | std::make_shared<std::vector<uint8_t>>(event)))); |
| 623 | if (!event_view.IsValid()) { |
| 624 | ADD_FAILURE(); |
| 625 | return packets_processed; |
| 626 | } |
| 627 | auto completed_packets = event_view.GetCompletedPackets(); |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 628 | for (const auto& entry : completed_packets) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 629 | EXPECT_EQ(handle, entry.connection_handle_); |
| 630 | packets_processed += entry.host_num_of_completed_packets_; |
| 631 | } |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 632 | } |
| 633 | return packets_processed; |
| 634 | } |
| 635 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 636 | // Send local loopback command and initialize SCO and ACL handles. |
| 637 | void BluetoothAidlTest::enterLoopbackMode() { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 638 | std::vector<uint8_t> cmd; |
| 639 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 640 | ::bluetooth::hci::WriteLoopbackModeBuilder::Create( |
| 641 | bluetooth::hci::LoopbackMode::ENABLE_LOCAL) |
| 642 | ->Serialize(bi); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 643 | hci->sendHciCommand(cmd); |
| 644 | |
| 645 | // Receive connection complete events with data channels |
| 646 | int connection_event_count = 0; |
| 647 | bool command_complete_received = false; |
| 648 | while (true) { |
| 649 | wait_for_event(false); |
| 650 | if (event_queue.empty()) { |
| 651 | // Fail if there was no event received or no connections completed. |
| 652 | ASSERT_TRUE(command_complete_received); |
| 653 | ASSERT_LT(0, connection_event_count); |
| 654 | return; |
| 655 | } |
| 656 | std::vector<uint8_t> event; |
| 657 | ASSERT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 658 | auto event_view = |
| 659 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 660 | std::make_shared<std::vector<uint8_t>>(event))); |
| 661 | ASSERT_TRUE(event_view.IsValid()); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 662 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 663 | if (event_view.GetEventCode() == |
| 664 | ::bluetooth::hci::EventCode::CONNECTION_COMPLETE) { |
| 665 | auto complete_view = |
| 666 | ::bluetooth::hci::ConnectionCompleteView::Create(event_view); |
| 667 | ASSERT_TRUE(complete_view.IsValid()); |
| 668 | switch (complete_view.GetLinkType()) { |
| 669 | case ::bluetooth::hci::LinkType::ACL: |
| 670 | acl_connection_handles.push_back(complete_view.GetConnectionHandle()); |
| 671 | break; |
| 672 | case ::bluetooth::hci::LinkType::SCO: |
| 673 | sco_connection_handles.push_back(complete_view.GetConnectionHandle()); |
| 674 | break; |
| 675 | default: |
| 676 | ASSERT_EQ(complete_view.GetLinkType(), |
| 677 | ::bluetooth::hci::LinkType::ACL); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 678 | } |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 679 | connection_event_count++; |
| 680 | } else { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 681 | auto command_complete_view = |
| 682 | ::bluetooth::hci::WriteLoopbackModeCompleteView::Create( |
| 683 | ::bluetooth::hci::CommandCompleteView::Create(event_view)); |
| 684 | ASSERT_TRUE(command_complete_view.IsValid()); |
| 685 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, |
| 686 | command_complete_view.GetStatus()); |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 687 | command_complete_received = true; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 692 | void BluetoothAidlTest::send_and_wait_for_cmd_complete( |
| 693 | std::unique_ptr<CommandBuilder> cmd, std::vector<uint8_t>& cmd_complete) { |
| 694 | std::vector<uint8_t> cmd_bytes = cmd->SerializeToBytes(); |
| 695 | hci->sendHciCommand(cmd_bytes); |
| 696 | |
| 697 | auto view = CommandView::Create( |
| 698 | PacketView<true>(std::make_shared<std::vector<uint8_t>>(cmd_bytes))); |
| 699 | ASSERT_TRUE(view.IsValid()); |
| 700 | ALOGI("Waiting for %s[0x%x]", OpCodeText(view.GetOpCode()).c_str(), |
| 701 | static_cast<int>(view.GetOpCode())); |
| 702 | ASSERT_NO_FATAL_FAILURE( |
| 703 | wait_for_command_complete_event(view.GetOpCode(), cmd_complete)); |
| 704 | } |
| 705 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 706 | // Empty test: Initialize()/Close() are called in SetUp()/TearDown(). |
| 707 | TEST_P(BluetoothAidlTest, InitializeAndClose) {} |
| 708 | |
| 709 | // Send an HCI Reset with sendHciCommand and wait for a command complete event. |
Myles Watson | 65b47f5 | 2023-01-26 12:59:06 -0800 | [diff] [blame] | 710 | TEST_P(BluetoothAidlTest, HciReset) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 711 | std::vector<uint8_t> reset; |
| 712 | ::bluetooth::packet::BitInserter bi{reset}; |
| 713 | ::bluetooth::hci::ResetBuilder::Create()->Serialize(bi); |
Myles Watson | 65b47f5 | 2023-01-26 12:59:06 -0800 | [diff] [blame] | 714 | hci->sendHciCommand(reset); |
| 715 | |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 716 | wait_and_validate_command_complete_event(::bluetooth::hci::OpCode::RESET); |
Myles Watson | 65b47f5 | 2023-01-26 12:59:06 -0800 | [diff] [blame] | 717 | } |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 718 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 719 | // Read and check the HCI version of the controller. |
| 720 | TEST_P(BluetoothAidlTest, HciVersionTest) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 721 | std::vector<uint8_t> cmd; |
| 722 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 723 | ::bluetooth::hci::ReadLocalVersionInformationBuilder::Create()->Serialize(bi); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 724 | hci->sendHciCommand(cmd); |
| 725 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 726 | ASSERT_NO_FATAL_FAILURE(wait_for_event()); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 727 | |
| 728 | std::vector<uint8_t> event; |
| 729 | ASSERT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 730 | auto complete_view = |
| 731 | ::bluetooth::hci::ReadLocalVersionInformationCompleteView::Create( |
| 732 | ::bluetooth::hci::CommandCompleteView::Create( |
| 733 | ::bluetooth::hci::EventView::Create( |
| 734 | ::bluetooth::hci::PacketView<true>( |
| 735 | std::make_shared<std::vector<uint8_t>>(event))))); |
| 736 | ASSERT_TRUE(complete_view.IsValid()); |
| 737 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, complete_view.GetStatus()); |
| 738 | auto version = complete_view.GetLocalVersionInformation(); |
| 739 | ASSERT_LE(::bluetooth::hci::HciVersion::V_3_0, version.hci_version_); |
| 740 | ASSERT_LE(::bluetooth::hci::LmpVersion::V_3_0, version.lmp_version_); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | // Send an unknown HCI command and wait for the error message. |
| 744 | TEST_P(BluetoothAidlTest, HciUnknownCommand) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 745 | std::vector<uint8_t> cmd; |
| 746 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 747 | ::bluetooth::hci::CommandBuilder::Create( |
| 748 | static_cast<::bluetooth::hci::OpCode>(0x3cff), |
| 749 | std::make_unique<::bluetooth::packet::RawBuilder>()) |
| 750 | ->Serialize(bi); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 751 | hci->sendHciCommand(cmd); |
| 752 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 753 | ASSERT_NO_FATAL_FAILURE(wait_for_event()); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 754 | |
| 755 | std::vector<uint8_t> event; |
| 756 | ASSERT_TRUE(event_queue.pop(event)); |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 757 | auto event_view = |
| 758 | ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView<true>( |
| 759 | std::make_shared<std::vector<uint8_t>>(event))); |
| 760 | ASSERT_TRUE(event_view.IsValid()); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 761 | |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 762 | switch (event_view.GetEventCode()) { |
| 763 | case ::bluetooth::hci::EventCode::COMMAND_COMPLETE: { |
| 764 | auto command_complete = |
| 765 | ::bluetooth::hci::CommandCompleteView::Create(event_view); |
| 766 | ASSERT_TRUE(command_complete.IsValid()); |
| 767 | ASSERT_EQ(command_complete.GetPayload()[0], |
| 768 | static_cast<uint8_t>( |
| 769 | ::bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND)); |
| 770 | } break; |
| 771 | case ::bluetooth::hci::EventCode::COMMAND_STATUS: { |
| 772 | auto command_status = |
| 773 | ::bluetooth::hci::CommandStatusView::Create(event_view); |
| 774 | ASSERT_TRUE(command_status.IsValid()); |
| 775 | ASSERT_EQ(command_status.GetStatus(), |
| 776 | ::bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND); |
| 777 | } break; |
| 778 | default: |
| 779 | ADD_FAILURE(); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 783 | // Enter loopback mode, but don't send any packets. |
Myles Watson | 65b47f5 | 2023-01-26 12:59:06 -0800 | [diff] [blame] | 784 | TEST_P(BluetoothAidlTest, WriteLoopbackMode) { enterLoopbackMode(); } |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 785 | |
| 786 | // Enter loopback mode and send a single command. |
| 787 | TEST_P(BluetoothAidlTest, LoopbackModeSingleCommand) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 788 | setBufferSizes(); |
| 789 | |
| 790 | enterLoopbackMode(); |
| 791 | |
| 792 | sendAndCheckHci(1); |
| 793 | } |
| 794 | |
| 795 | // Enter loopback mode and send a single SCO packet. |
| 796 | TEST_P(BluetoothAidlTest, LoopbackModeSingleSco) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 797 | setBufferSizes(); |
| 798 | setSynchronousFlowControlEnable(); |
| 799 | |
| 800 | enterLoopbackMode(); |
| 801 | |
| 802 | if (!sco_connection_handles.empty()) { |
| 803 | ASSERT_LT(0, max_sco_data_packet_length); |
| 804 | sendAndCheckSco(1, max_sco_data_packet_length, sco_connection_handles[0]); |
| 805 | int sco_packets_sent = 1; |
| 806 | int completed_packets = |
| 807 | wait_for_completed_packets_event(sco_connection_handles[0]); |
| 808 | if (sco_packets_sent != completed_packets) { |
| 809 | ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, |
| 810 | sco_packets_sent, completed_packets); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | // Enter loopback mode and send a single ACL packet. |
| 816 | TEST_P(BluetoothAidlTest, LoopbackModeSingleAcl) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 817 | setBufferSizes(); |
| 818 | |
| 819 | enterLoopbackMode(); |
| 820 | |
| 821 | if (!acl_connection_handles.empty()) { |
| 822 | ASSERT_LT(0, max_acl_data_packet_length); |
| 823 | sendAndCheckAcl(1, max_acl_data_packet_length - 1, |
| 824 | acl_connection_handles[0]); |
| 825 | int acl_packets_sent = 1; |
| 826 | int completed_packets = |
| 827 | wait_for_completed_packets_event(acl_connection_handles[0]); |
| 828 | if (acl_packets_sent != completed_packets) { |
| 829 | ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, |
| 830 | acl_packets_sent, completed_packets); |
| 831 | } |
| 832 | } |
| 833 | ASSERT_GE(acl_cb_count, 1); |
| 834 | } |
| 835 | |
| 836 | // Enter loopback mode and send command packets for bandwidth measurements. |
| 837 | TEST_P(BluetoothAidlTest, LoopbackModeCommandBandwidth) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 838 | setBufferSizes(); |
| 839 | |
| 840 | enterLoopbackMode(); |
| 841 | |
| 842 | sendAndCheckHci(kNumHciCommandsBandwidth); |
| 843 | } |
| 844 | |
| 845 | // Enter loopback mode and send SCO packets for bandwidth measurements. |
| 846 | TEST_P(BluetoothAidlTest, LoopbackModeScoBandwidth) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 847 | setBufferSizes(); |
| 848 | setSynchronousFlowControlEnable(); |
| 849 | |
| 850 | enterLoopbackMode(); |
| 851 | |
| 852 | if (!sco_connection_handles.empty()) { |
| 853 | ASSERT_LT(0, max_sco_data_packet_length); |
| 854 | sendAndCheckSco(kNumScoPacketsBandwidth, max_sco_data_packet_length, |
| 855 | sco_connection_handles[0]); |
| 856 | int sco_packets_sent = kNumScoPacketsBandwidth; |
| 857 | int completed_packets = |
| 858 | wait_for_completed_packets_event(sco_connection_handles[0]); |
| 859 | if (sco_packets_sent != completed_packets) { |
| 860 | ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, |
| 861 | sco_packets_sent, completed_packets); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | // Enter loopback mode and send packets for ACL bandwidth measurements. |
| 867 | TEST_P(BluetoothAidlTest, LoopbackModeAclBandwidth) { |
Myles Watson | e1708c8 | 2023-01-18 17:07:58 -0800 | [diff] [blame] | 868 | setBufferSizes(); |
| 869 | |
| 870 | enterLoopbackMode(); |
| 871 | |
| 872 | if (!acl_connection_handles.empty()) { |
| 873 | ASSERT_LT(0, max_acl_data_packet_length); |
| 874 | sendAndCheckAcl(kNumAclPacketsBandwidth, max_acl_data_packet_length - 1, |
| 875 | acl_connection_handles[0]); |
| 876 | int acl_packets_sent = kNumAclPacketsBandwidth; |
| 877 | int completed_packets = |
| 878 | wait_for_completed_packets_event(acl_connection_handles[0]); |
| 879 | if (acl_packets_sent != completed_packets) { |
| 880 | ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, |
| 881 | acl_packets_sent, completed_packets); |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 886 | // Set all bits in the event mask |
| 887 | TEST_P(BluetoothAidlTest, SetEventMask) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 888 | std::vector<uint8_t> cmd; |
| 889 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 890 | uint64_t full_mask = UINT64_MAX; |
| 891 | ::bluetooth::hci::SetEventMaskBuilder::Create(full_mask)->Serialize(bi); |
| 892 | hci->sendHciCommand(cmd); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 893 | wait_and_validate_command_complete_event( |
| 894 | ::bluetooth::hci::OpCode::SET_EVENT_MASK); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | // Set all bits in the LE event mask |
| 898 | TEST_P(BluetoothAidlTest, SetLeEventMask) { |
Myles Watson | 51b8bae | 2023-01-27 14:22:24 -0800 | [diff] [blame] | 899 | std::vector<uint8_t> cmd; |
| 900 | ::bluetooth::packet::BitInserter bi{cmd}; |
| 901 | uint64_t full_mask = UINT64_MAX; |
| 902 | ::bluetooth::hci::LeSetEventMaskBuilder::Create(full_mask)->Serialize(bi); |
| 903 | hci->sendHciCommand(cmd); |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 904 | wait_and_validate_command_complete_event( |
| 905 | ::bluetooth::hci::OpCode::LE_SET_EVENT_MASK); |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 908 | // Call initialize twice, second one should fail. |
| 909 | TEST_P(BluetoothAidlTest, CallInitializeTwice) { |
| 910 | class SecondCb |
| 911 | : public aidl::android::hardware::bluetooth::BnBluetoothHciCallbacks { |
| 912 | public: |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 913 | ndk::ScopedAStatus initializationComplete(Status status) override { |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 914 | EXPECT_EQ(status, Status::ALREADY_INITIALIZED); |
| 915 | init_promise.set_value(); |
| 916 | return ScopedAStatus::ok(); |
| 917 | }; |
| 918 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 919 | ndk::ScopedAStatus hciEventReceived( |
| 920 | const std::vector<uint8_t>& /*event*/) override { |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 921 | ADD_FAILURE(); |
| 922 | return ScopedAStatus::ok(); |
| 923 | }; |
| 924 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 925 | ndk::ScopedAStatus aclDataReceived( |
| 926 | const std::vector<uint8_t>& /*data*/) override { |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 927 | ADD_FAILURE(); |
| 928 | return ScopedAStatus::ok(); |
| 929 | }; |
| 930 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 931 | ndk::ScopedAStatus scoDataReceived( |
| 932 | const std::vector<uint8_t>& /*data*/) override { |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 933 | ADD_FAILURE(); |
| 934 | return ScopedAStatus::ok(); |
| 935 | }; |
| 936 | |
Jack He | dbceaca | 2023-03-27 18:06:38 -0700 | [diff] [blame] | 937 | ndk::ScopedAStatus isoDataReceived( |
| 938 | const std::vector<uint8_t>& /*data*/) override { |
Myles Watson | 0daa164 | 2023-01-26 15:58:28 -0800 | [diff] [blame] | 939 | ADD_FAILURE(); |
| 940 | return ScopedAStatus::ok(); |
| 941 | }; |
| 942 | std::promise<void> init_promise; |
| 943 | }; |
| 944 | |
| 945 | std::shared_ptr<SecondCb> second_cb = ndk::SharedRefBase::make<SecondCb>(); |
| 946 | ASSERT_NE(second_cb, nullptr); |
| 947 | |
| 948 | auto future = second_cb->init_promise.get_future(); |
| 949 | ASSERT_TRUE(hci->initialize(second_cb).isOk()); |
| 950 | auto status = future.wait_for(std::chrono::seconds(1)); |
| 951 | ASSERT_EQ(status, std::future_status::ready); |
| 952 | } |
| 953 | |
Myles Watson | 5bfb3a7 | 2023-05-10 14:06:32 -0700 | [diff] [blame] | 954 | TEST_P(BluetoothAidlTest, Vsr_Bluetooth5Requirements) { |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 955 | std::vector<uint8_t> version_event; |
| 956 | send_and_wait_for_cmd_complete(ReadLocalVersionInformationBuilder::Create(), |
| 957 | version_event); |
| 958 | auto version_view = ReadLocalVersionInformationCompleteView::Create( |
| 959 | CommandCompleteView::Create(EventView::Create(PacketView<true>( |
| 960 | std::make_shared<std::vector<uint8_t>>(version_event))))); |
| 961 | ASSERT_TRUE(version_view.IsValid()); |
| 962 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, version_view.GetStatus()); |
| 963 | auto version = version_view.GetLocalVersionInformation(); |
| 964 | if (version.hci_version_ < ::bluetooth::hci::HciVersion::V_5_0) { |
| 965 | // This test does not apply to controllers below 5.0 |
| 966 | return; |
| 967 | }; |
| 968 | // When HCI version is 5.0, LMP version must also be at least 5.0 |
| 969 | ASSERT_GE(static_cast<int>(version.lmp_version_), |
| 970 | static_cast<int>(version.hci_version_)); |
| 971 | |
| 972 | std::vector<uint8_t> le_features_event; |
| 973 | send_and_wait_for_cmd_complete(LeReadLocalSupportedFeaturesBuilder::Create(), |
| 974 | le_features_event); |
| 975 | auto le_features_view = LeReadLocalSupportedFeaturesCompleteView::Create( |
| 976 | CommandCompleteView::Create(EventView::Create(PacketView<true>( |
| 977 | std::make_shared<std::vector<uint8_t>>(le_features_event))))); |
| 978 | ASSERT_TRUE(le_features_view.IsValid()); |
| 979 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, le_features_view.GetStatus()); |
| 980 | auto le_features = le_features_view.GetLeFeatures(); |
| 981 | ASSERT_TRUE(le_features & static_cast<uint64_t>(LLFeaturesBits::LL_PRIVACY)); |
| 982 | ASSERT_TRUE(le_features & static_cast<uint64_t>(LLFeaturesBits::LE_2M_PHY)); |
| 983 | ASSERT_TRUE(le_features & |
| 984 | static_cast<uint64_t>(LLFeaturesBits::LE_CODED_PHY)); |
| 985 | ASSERT_TRUE(le_features & |
| 986 | static_cast<uint64_t>(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); |
| 987 | |
| 988 | std::vector<uint8_t> num_adv_set_event; |
| 989 | send_and_wait_for_cmd_complete( |
| 990 | LeReadNumberOfSupportedAdvertisingSetsBuilder::Create(), |
| 991 | num_adv_set_event); |
| 992 | auto num_adv_set_view = |
| 993 | LeReadNumberOfSupportedAdvertisingSetsCompleteView::Create( |
| 994 | CommandCompleteView::Create(EventView::Create(PacketView<true>( |
| 995 | std::make_shared<std::vector<uint8_t>>(num_adv_set_event))))); |
| 996 | ASSERT_TRUE(num_adv_set_view.IsValid()); |
| 997 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, num_adv_set_view.GetStatus()); |
| 998 | auto num_adv_set = num_adv_set_view.GetNumberSupportedAdvertisingSets(); |
Treehugger Robot | 5e0277f | 2023-05-12 02:44:22 +0000 | [diff] [blame] | 999 | |
| 1000 | if (isTv() && get_vsr_api_level() == __ANDROID_API_U__) { |
| 1001 | ASSERT_GE(num_adv_set, kMinLeAdvSetForBt5FoTv); |
| 1002 | } else { |
| 1003 | ASSERT_GE(num_adv_set, kMinLeAdvSetForBt5); |
| 1004 | } |
Jack He | 2d2f3c2 | 2023-03-27 03:04:52 -0700 | [diff] [blame] | 1005 | |
| 1006 | std::vector<uint8_t> num_resolving_list_event; |
| 1007 | send_and_wait_for_cmd_complete(LeReadResolvingListSizeBuilder::Create(), |
| 1008 | num_resolving_list_event); |
| 1009 | auto num_resolving_list_view = LeReadResolvingListSizeCompleteView::Create( |
| 1010 | CommandCompleteView::Create(EventView::Create(PacketView<true>( |
| 1011 | std::make_shared<std::vector<uint8_t>>(num_resolving_list_event))))); |
| 1012 | ASSERT_TRUE(num_resolving_list_view.IsValid()); |
| 1013 | ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, |
| 1014 | num_resolving_list_view.GetStatus()); |
| 1015 | auto num_resolving_list = num_resolving_list_view.GetResolvingListSize(); |
| 1016 | ASSERT_GE(num_resolving_list, kMinLeResolvingListForBt5); |
| 1017 | } |
| 1018 | |
Dylan Tian | 8a6e09c | 2022-08-16 07:29:28 +0000 | [diff] [blame] | 1019 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothAidlTest); |
| 1020 | INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAidlTest, |
| 1021 | testing::ValuesIn(android::getAidlHalInstanceNames( |
| 1022 | IBluetoothHci::descriptor)), |
| 1023 | android::PrintInstanceNameToString); |
| 1024 | |
| 1025 | int main(int argc, char** argv) { |
| 1026 | ABinderProcess_startThreadPool(); |
| 1027 | ::testing::InitGoogleTest(&argc, argv); |
| 1028 | int status = RUN_ALL_TESTS(); |
| 1029 | ALOGI("Test result = %d", status); |
| 1030 | return status; |
| 1031 | } |