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