diff --git a/bluetooth/aidl/TEST_MAPPING b/bluetooth/aidl/TEST_MAPPING index 342a1e45ad..f059c04ed2 100644 --- a/bluetooth/aidl/TEST_MAPPING +++ b/bluetooth/aidl/TEST_MAPPING @@ -1,7 +1,13 @@ { "presubmit" : [ { - "name" : "VtsHalBluetoothTargetTest" + "name" : "VtsHalBluetoothTargetTest", + "options": [ + { + // TODO(b/275847929) + "exclude-filter": "VtsHalBluetoothTargetTest.PerInstance/BluetoothAidlTest#Cdd_C_12_1_Bluetooth5Requirements/0_android_hardware_bluetooth_IBluetoothHci_default" + } + ] } ] } diff --git a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp index 7f89853b44..529e092dc7 100644 --- a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp +++ b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp @@ -48,6 +48,27 @@ using aidl::android::hardware::bluetooth::Status; using ndk::ScopedAStatus; using ndk::SpAIBinder; +using ::bluetooth::hci::CommandBuilder; +using ::bluetooth::hci::CommandCompleteView; +using ::bluetooth::hci::CommandView; +using ::bluetooth::hci::ErrorCode; +using ::bluetooth::hci::EventView; +using ::bluetooth::hci::LeReadLocalSupportedFeaturesBuilder; +using ::bluetooth::hci::LeReadLocalSupportedFeaturesCompleteView; +using ::bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsBuilder; +using ::bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsCompleteView; +using ::bluetooth::hci::LeReadResolvingListSizeBuilder; +using ::bluetooth::hci::LeReadResolvingListSizeCompleteView; +using ::bluetooth::hci::LLFeaturesBits; +using ::bluetooth::hci::OpCode; +using ::bluetooth::hci::OpCodeText; +using ::bluetooth::hci::PacketView; +using ::bluetooth::hci::ReadLocalVersionInformationBuilder; +using ::bluetooth::hci::ReadLocalVersionInformationCompleteView; + +static constexpr uint8_t kMinLeAdvSetForBt5 = 16; +static constexpr uint8_t kMinLeResolvingListForBt5 = 8; + static constexpr size_t kNumHciCommandsBandwidth = 100; static constexpr size_t kNumScoPacketsBandwidth = 100; static constexpr size_t kNumAclPacketsBandwidth = 100; @@ -156,8 +177,14 @@ class BluetoothAidlTest : public ::testing::TestWithParam { void handle_no_ops(); void discard_qca_debugging(); void wait_for_event(bool timeout_is_error); - void wait_for_command_complete_event(::bluetooth::hci::OpCode opCode); + void wait_for_command_complete_event(OpCode opCode, + std::vector& complete_event); + // Wait until a command complete is received. + // Command complete will be consumed after this method + void wait_and_validate_command_complete_event(OpCode opCode); int wait_for_completed_packets_event(uint16_t handle); + void send_and_wait_for_cmd_complete(std::unique_ptr cmd, + std::vector& cmd_complete); // A simple test implementation of BluetoothHciCallbacks. class BluetoothHciCallbacks @@ -180,7 +207,7 @@ class BluetoothAidlTest : public ::testing::TestWithParam { const std::vector& event) override { parent_.event_cb_count++; parent_.event_queue.push(event); - ALOGV("Event received (length = %d)", static_cast(event.size())); + ALOGI("Event received (length = %d)", static_cast(event.size())); return ScopedAStatus::ok(); }; @@ -375,22 +402,27 @@ void BluetoothAidlTest::wait_for_event(bool timeout_is_error = true) { } } -// Wait until a command complete is received. void BluetoothAidlTest::wait_for_command_complete_event( - ::bluetooth::hci::OpCode opCode) { + OpCode opCode, std::vector& complete_event) { ASSERT_NO_FATAL_FAILURE(wait_for_event()); - std::vector event; ASSERT_FALSE(event_queue.empty()); - ASSERT_TRUE(event_queue.pop(event)); + ASSERT_TRUE(event_queue.pop(complete_event)); auto complete_view = ::bluetooth::hci::CommandCompleteView::Create( ::bluetooth::hci::EventView::Create(::bluetooth::hci::PacketView( - std::make_shared>(event)))); + std::make_shared>(complete_event)))); ASSERT_TRUE(complete_view.IsValid()); ASSERT_EQ(complete_view.GetCommandOpCode(), opCode); ASSERT_EQ(complete_view.GetPayload()[0], static_cast(::bluetooth::hci::ErrorCode::SUCCESS)); } +void BluetoothAidlTest::wait_and_validate_command_complete_event( + ::bluetooth::hci::OpCode opCode) { + std::vector complete_event; + ASSERT_NO_FATAL_FAILURE( + wait_for_command_complete_event(opCode, complete_event)); +} + // Send the command to read the controller's buffer sizes. void BluetoothAidlTest::setBufferSizes() { std::vector cmd; @@ -430,7 +462,7 @@ void BluetoothAidlTest::setSynchronousFlowControlEnable() { ->Serialize(bi); hci->sendHciCommand(cmd); - wait_for_command_complete_event( + wait_and_validate_command_complete_event( ::bluetooth::hci::OpCode::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE); } @@ -620,6 +652,20 @@ void BluetoothAidlTest::enterLoopbackMode() { } } +void BluetoothAidlTest::send_and_wait_for_cmd_complete( + std::unique_ptr cmd, std::vector& cmd_complete) { + std::vector cmd_bytes = cmd->SerializeToBytes(); + hci->sendHciCommand(cmd_bytes); + + auto view = CommandView::Create( + PacketView(std::make_shared>(cmd_bytes))); + ASSERT_TRUE(view.IsValid()); + ALOGI("Waiting for %s[0x%x]", OpCodeText(view.GetOpCode()).c_str(), + static_cast(view.GetOpCode())); + ASSERT_NO_FATAL_FAILURE( + wait_for_command_complete_event(view.GetOpCode(), cmd_complete)); +} + // Empty test: Initialize()/Close() are called in SetUp()/TearDown(). TEST_P(BluetoothAidlTest, InitializeAndClose) {} @@ -630,7 +676,7 @@ TEST_P(BluetoothAidlTest, HciReset) { ::bluetooth::hci::ResetBuilder::Create()->Serialize(bi); hci->sendHciCommand(reset); - wait_for_command_complete_event(::bluetooth::hci::OpCode::RESET); + wait_and_validate_command_complete_event(::bluetooth::hci::OpCode::RESET); } // Read and check the HCI version of the controller. @@ -807,7 +853,8 @@ TEST_P(BluetoothAidlTest, SetEventMask) { uint64_t full_mask = UINT64_MAX; ::bluetooth::hci::SetEventMaskBuilder::Create(full_mask)->Serialize(bi); hci->sendHciCommand(cmd); - wait_for_command_complete_event(::bluetooth::hci::OpCode::SET_EVENT_MASK); + wait_and_validate_command_complete_event( + ::bluetooth::hci::OpCode::SET_EVENT_MASK); } // Set all bits in the LE event mask @@ -817,7 +864,8 @@ TEST_P(BluetoothAidlTest, SetLeEventMask) { uint64_t full_mask = UINT64_MAX; ::bluetooth::hci::LeSetEventMaskBuilder::Create(full_mask)->Serialize(bi); hci->sendHciCommand(cmd); - wait_for_command_complete_event(::bluetooth::hci::OpCode::LE_SET_EVENT_MASK); + wait_and_validate_command_complete_event( + ::bluetooth::hci::OpCode::LE_SET_EVENT_MASK); } // Call initialize twice, second one should fail. @@ -866,6 +914,66 @@ TEST_P(BluetoothAidlTest, CallInitializeTwice) { ASSERT_EQ(status, std::future_status::ready); } +TEST_P(BluetoothAidlTest, Cdd_C_12_1_Bluetooth5Requirements) { + std::vector version_event; + send_and_wait_for_cmd_complete(ReadLocalVersionInformationBuilder::Create(), + version_event); + auto version_view = ReadLocalVersionInformationCompleteView::Create( + CommandCompleteView::Create(EventView::Create(PacketView( + std::make_shared>(version_event))))); + ASSERT_TRUE(version_view.IsValid()); + ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, version_view.GetStatus()); + auto version = version_view.GetLocalVersionInformation(); + if (version.hci_version_ < ::bluetooth::hci::HciVersion::V_5_0) { + // This test does not apply to controllers below 5.0 + return; + }; + // When HCI version is 5.0, LMP version must also be at least 5.0 + ASSERT_GE(static_cast(version.lmp_version_), + static_cast(version.hci_version_)); + + std::vector le_features_event; + send_and_wait_for_cmd_complete(LeReadLocalSupportedFeaturesBuilder::Create(), + le_features_event); + auto le_features_view = LeReadLocalSupportedFeaturesCompleteView::Create( + CommandCompleteView::Create(EventView::Create(PacketView( + std::make_shared>(le_features_event))))); + ASSERT_TRUE(le_features_view.IsValid()); + ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, le_features_view.GetStatus()); + auto le_features = le_features_view.GetLeFeatures(); + ASSERT_TRUE(le_features & static_cast(LLFeaturesBits::LL_PRIVACY)); + ASSERT_TRUE(le_features & static_cast(LLFeaturesBits::LE_2M_PHY)); + ASSERT_TRUE(le_features & + static_cast(LLFeaturesBits::LE_CODED_PHY)); + ASSERT_TRUE(le_features & + static_cast(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); + + std::vector num_adv_set_event; + send_and_wait_for_cmd_complete( + LeReadNumberOfSupportedAdvertisingSetsBuilder::Create(), + num_adv_set_event); + auto num_adv_set_view = + LeReadNumberOfSupportedAdvertisingSetsCompleteView::Create( + CommandCompleteView::Create(EventView::Create(PacketView( + std::make_shared>(num_adv_set_event))))); + ASSERT_TRUE(num_adv_set_view.IsValid()); + ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, num_adv_set_view.GetStatus()); + auto num_adv_set = num_adv_set_view.GetNumberSupportedAdvertisingSets(); + ASSERT_GE(num_adv_set, kMinLeAdvSetForBt5); + + std::vector num_resolving_list_event; + send_and_wait_for_cmd_complete(LeReadResolvingListSizeBuilder::Create(), + num_resolving_list_event); + auto num_resolving_list_view = LeReadResolvingListSizeCompleteView::Create( + CommandCompleteView::Create(EventView::Create(PacketView( + std::make_shared>(num_resolving_list_event))))); + ASSERT_TRUE(num_resolving_list_view.IsValid()); + ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, + num_resolving_list_view.GetStatus()); + auto num_resolving_list = num_resolving_list_view.GetResolvingListSize(); + ASSERT_GE(num_resolving_list, kMinLeResolvingListForBt5); +} + GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothAidlTest); INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAidlTest, testing::ValuesIn(android::getAidlHalInstanceNames(