Loading system/main/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ cc_test { ":TestMockBta", ":TestMockBtif", ":TestMockLegacyHciCommands", ":TestMockLegacyHciInterface", ":TestMockMainShimEntry", ":TestMockStack", "shim/acl_api.cc", Loading system/stack/Android.bp +4 −2 Original line number Diff line number Diff line Loading @@ -365,10 +365,10 @@ cc_test { ":TestMockBtif", ":TestMockCommon", ":TestMockDevice", ":TestMockLegacyHciCommands", ":TestMockMainShim", ":TestMockStackAcl", ":TestMockStackBtm", ":TestMockStackHcic", ":TestMockStackL2cap", ":TestMockStackMetrics", "smp/p_256_curvepara.cc", Loading Loading @@ -794,12 +794,13 @@ cc_test { ":TestMockBta", ":TestMockBtif", ":TestMockDevice", ":TestMockLegacyHciCommands", ":TestMockLegacyHciInterface", ":TestMockMainBte", ":TestMockMainShim", ":TestMockStackBtu", ":TestMockStackGap", ":TestMockStackGatt", ":TestMockStackHcic", ":TestMockStackL2cap", ":TestMockStackSmp", "acl/acl.cc", Loading Loading @@ -976,6 +977,7 @@ cc_test { ":TestMockStackAcl", ":TestMockStackBtm", ":TestMockStackL2cap", ":TestMockStackHcic", ":TestMockStackMetrics", ":TestMockStackSmp", "btu/btu_hcif.cc", Loading system/stack/test/btm/stack_btm_test.cc +19 −15 Original line number Diff line number Diff line Loading @@ -37,10 +37,10 @@ #include "stack/include/btm_client_interface.h" #include "stack/include/hcidefs.h" #include "stack/l2cap/l2c_int.h" #include "test/mock/mock_hcic_hcicmds.h" #include "test/mock/mock_stack_hcic_hcicmds.h" #include "types/raw_address.h" namespace mock = test::mock::hcic_hcicmds; namespace mock = test::mock::stack_hcic_hcicmds; extern tBTM_CB btm_cb; Loading Loading @@ -163,26 +163,30 @@ TEST_F(StackBtmTest, change_packet_type) { uint64_t features = 0xffffffffffffffff; acl_process_supported_features(0x123, features); mock::btsnd_hcic_change_conn_type = {}; uint16_t pkt_types = 0x55aa; btm_set_packet_types_from_address(bda, pkt_types); uint16_t handle{0}; uint16_t packet_types{0}; mock::btsnd_hcic_change_conn_type.body = [&handle, &packet_types]( uint16_t h, uint16_t p) { handle = h; packet_types = p; }; btm_set_packet_types_from_address(bda, 0x55aa); ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]); ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1), Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; btm_set_packet_types_from_address(bda, 0xffff); ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]); ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0xcc00 | HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; btm_set_packet_types_from_address(bda, 0x0); // NOTE: The call should not be executed with no bits set ASSERT_EQ(0x0, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(Hex16(0x0), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0xcc18), Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; get_btm_client_interface().lifecycle.btm_free(); } Loading system/test/Android.bp +14 −0 Original line number Diff line number Diff line Loading @@ -406,3 +406,17 @@ filegroup { "mock/mock_bluetooth_interface.cc", ], } filegroup { name: "TestMockStackHcic", srcs: [ "mock/mock_stack_hcic*.cc", ], } filegroup { name: "TestMockLegacyHciInterface", srcs: [ "mock/mock_legacy_hci_iterface.cc" ], } system/test/mock/mock_legacy_hci_iterface.cc 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <map> #include <string> extern std::map<std::string, int> mock_function_count_map; #define UNUSED_ATTR #include <base/callback.h> #include <stddef.h> #include "bt_target.h" #include "btu.h" #include "hcimsgs.h" #include "stack/include/acl_hci_link_interface.h" #include "stack/include/bt_octets.h" #include "types/raw_address.h" namespace test { namespace mock { namespace hcic_hcicmds { struct btsnd_hcic_change_conn_type { uint16_t handle{0}; uint16_t packet_types{0}; } btsnd_hcic_change_conn_type; } // namespace hcic_hcicmds } // namespace mock } // namespace test namespace mock = test::mock::hcic_hcicmds; namespace { void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) { mock_function_count_map[__func__]++; } void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) { mock_function_count_map[__func__]++; } } // namespace bluetooth::legacy::hci::Interface interface_ = { .Disconnect = btsnd_hcic_disconnect, .StartRoleSwitch = btsnd_hcic_switch_role, .ChangeConnectionPacketType = btsnd_hcic_change_conn_type, }; const bluetooth::legacy::hci::Interface& bluetooth::legacy::hci::GetInterface() { return interface_; } Loading
system/main/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ cc_test { ":TestMockBta", ":TestMockBtif", ":TestMockLegacyHciCommands", ":TestMockLegacyHciInterface", ":TestMockMainShimEntry", ":TestMockStack", "shim/acl_api.cc", Loading
system/stack/Android.bp +4 −2 Original line number Diff line number Diff line Loading @@ -365,10 +365,10 @@ cc_test { ":TestMockBtif", ":TestMockCommon", ":TestMockDevice", ":TestMockLegacyHciCommands", ":TestMockMainShim", ":TestMockStackAcl", ":TestMockStackBtm", ":TestMockStackHcic", ":TestMockStackL2cap", ":TestMockStackMetrics", "smp/p_256_curvepara.cc", Loading Loading @@ -794,12 +794,13 @@ cc_test { ":TestMockBta", ":TestMockBtif", ":TestMockDevice", ":TestMockLegacyHciCommands", ":TestMockLegacyHciInterface", ":TestMockMainBte", ":TestMockMainShim", ":TestMockStackBtu", ":TestMockStackGap", ":TestMockStackGatt", ":TestMockStackHcic", ":TestMockStackL2cap", ":TestMockStackSmp", "acl/acl.cc", Loading Loading @@ -976,6 +977,7 @@ cc_test { ":TestMockStackAcl", ":TestMockStackBtm", ":TestMockStackL2cap", ":TestMockStackHcic", ":TestMockStackMetrics", ":TestMockStackSmp", "btu/btu_hcif.cc", Loading
system/stack/test/btm/stack_btm_test.cc +19 −15 Original line number Diff line number Diff line Loading @@ -37,10 +37,10 @@ #include "stack/include/btm_client_interface.h" #include "stack/include/hcidefs.h" #include "stack/l2cap/l2c_int.h" #include "test/mock/mock_hcic_hcicmds.h" #include "test/mock/mock_stack_hcic_hcicmds.h" #include "types/raw_address.h" namespace mock = test::mock::hcic_hcicmds; namespace mock = test::mock::stack_hcic_hcicmds; extern tBTM_CB btm_cb; Loading Loading @@ -163,26 +163,30 @@ TEST_F(StackBtmTest, change_packet_type) { uint64_t features = 0xffffffffffffffff; acl_process_supported_features(0x123, features); mock::btsnd_hcic_change_conn_type = {}; uint16_t pkt_types = 0x55aa; btm_set_packet_types_from_address(bda, pkt_types); uint16_t handle{0}; uint16_t packet_types{0}; mock::btsnd_hcic_change_conn_type.body = [&handle, &packet_types]( uint16_t h, uint16_t p) { handle = h; packet_types = p; }; btm_set_packet_types_from_address(bda, 0x55aa); ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]); ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1), Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; btm_set_packet_types_from_address(bda, 0xffff); ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]); ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0xcc00 | HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; btm_set_packet_types_from_address(bda, 0x0); // NOTE: The call should not be executed with no bits set ASSERT_EQ(0x0, mock::btsnd_hcic_change_conn_type.handle); ASSERT_EQ(Hex16(0x0), Hex16(mock::btsnd_hcic_change_conn_type.packet_types)); ASSERT_EQ(0x123, handle); ASSERT_EQ(Hex16(0xcc18), Hex16(packet_types)); mock::btsnd_hcic_change_conn_type = {}; get_btm_client_interface().lifecycle.btm_free(); } Loading
system/test/Android.bp +14 −0 Original line number Diff line number Diff line Loading @@ -406,3 +406,17 @@ filegroup { "mock/mock_bluetooth_interface.cc", ], } filegroup { name: "TestMockStackHcic", srcs: [ "mock/mock_stack_hcic*.cc", ], } filegroup { name: "TestMockLegacyHciInterface", srcs: [ "mock/mock_legacy_hci_iterface.cc" ], }
system/test/mock/mock_legacy_hci_iterface.cc 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <map> #include <string> extern std::map<std::string, int> mock_function_count_map; #define UNUSED_ATTR #include <base/callback.h> #include <stddef.h> #include "bt_target.h" #include "btu.h" #include "hcimsgs.h" #include "stack/include/acl_hci_link_interface.h" #include "stack/include/bt_octets.h" #include "types/raw_address.h" namespace test { namespace mock { namespace hcic_hcicmds { struct btsnd_hcic_change_conn_type { uint16_t handle{0}; uint16_t packet_types{0}; } btsnd_hcic_change_conn_type; } // namespace hcic_hcicmds } // namespace mock } // namespace test namespace mock = test::mock::hcic_hcicmds; namespace { void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) { mock_function_count_map[__func__]++; } void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) { mock_function_count_map[__func__]++; } } // namespace bluetooth::legacy::hci::Interface interface_ = { .Disconnect = btsnd_hcic_disconnect, .StartRoleSwitch = btsnd_hcic_switch_role, .ChangeConnectionPacketType = btsnd_hcic_change_conn_type, }; const bluetooth::legacy::hci::Interface& bluetooth::legacy::hci::GetInterface() { return interface_; }