summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Pawłowski <jpawlowski@google.com> 2025-03-14 10:59:15 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-14 10:59:15 -0700
commitb3bb9f21ac6cf43b47dbe3abbfce5ac88957c0bf (patch)
tree5175e98a3219bf312ab88f2d5867e1a0299696fd
parent96641c762aa6160a7598dc0c41ba1e0aac3cab17 (diff)
parent36706f4baf3f36477884be8bedf17ca023250e41 (diff)
Merge changes I66f13abd,I4d5ab702,I05fe3351 into main
* changes: Test: make mock_hci_layer_ into unique_ptr Test: make mock_controller_ into unique_ptr Test: make mock_acl_manager_ into unique_ptr
-rw-r--r--system/bta/le_audio/broadcaster/broadcaster_test.cc9
-rw-r--r--system/bta/le_audio/codec_manager_test.cc14
-rw-r--r--system/bta/le_audio/devices_test.cc7
-rw-r--r--system/bta/le_audio/le_audio_client_test.cc13
-rw-r--r--system/bta/le_audio/state_machine_test.cc7
-rw-r--r--system/bta/test/bta_ag_sco_test.cc6
-rw-r--r--system/bta/test/bta_ag_test.cc6
-rw-r--r--system/bta/test/bta_dm_test.cc11
-rw-r--r--system/bta/test/bta_sdp_test.cc11
-rw-r--r--system/bta/test/bta_test_fixtures.h6
-rw-r--r--system/btif/test/btif_core_test.cc27
-rw-r--r--system/main/test/main_shim_test.cc13
-rw-r--r--system/stack/fuzzers/l2cap_fuzzer.cc20
-rw-r--r--system/stack/test/btm/stack_btm_power_mode_test.cc9
-rw-r--r--system/stack/test/btm/stack_btm_sec_test.cc5
-rw-r--r--system/stack/test/btm/stack_btm_test.cc39
-rw-r--r--system/stack/test/btm_iso_test.cc21
-rw-r--r--system/stack/test/connection_manager_test.cc59
-rw-r--r--system/stack/test/eatt/eatt_test.cc9
-rw-r--r--system/stack/test/stack_acl_test.cc6
-rw-r--r--system/stack/test/stack_l2cap_test.cc14
-rw-r--r--system/test/mock/mock_main_shim_entry.cc12
-rw-r--r--system/test/mock/mock_main_shim_entry.h9
23 files changed, 183 insertions, 150 deletions
diff --git a/system/bta/le_audio/broadcaster/broadcaster_test.cc b/system/bta/le_audio/broadcaster/broadcaster_test.cc
index a211a810ad..16177230d1 100644
--- a/system/bta/le_audio/broadcaster/broadcaster_test.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster_test.cc
@@ -63,6 +63,8 @@ using testing::Test;
using namespace bluetooth::le_audio;
using namespace bluetooth;
+using bluetooth::hci::testing::mock_controller_;
+
using bluetooth::le_audio::DsaMode;
using bluetooth::le_audio::LeAudioCodecConfiguration;
using bluetooth::le_audio::LeAudioSourceAudioHalClient;
@@ -287,8 +289,8 @@ protected:
init_message_loop_thread();
reset_mock_function_count_map();
- bluetooth::hci::testing::mock_controller_ = &mock_controller_;
- ON_CALL(mock_controller_, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
+ mock_controller_ = std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*mock_controller_, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
iso_manager_ = bluetooth::hci::IsoManager::GetInstance();
ASSERT_NE(iso_manager_, nullptr);
@@ -366,7 +368,7 @@ protected:
ContentControlIdKeeper::GetInstance()->Stop();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.release();
delete mock_audio_source_;
iso_active_callback = nullptr;
delete mock_audio_source_;
@@ -436,7 +438,6 @@ protected:
protected:
MockLeAudioBroadcasterCallbacks mock_broadcaster_callbacks_;
- bluetooth::hci::testing::MockControllerInterface mock_controller_;
bluetooth::hci::IsoManager* iso_manager_;
MockIsoManager* mock_iso_manager_;
bluetooth::hci::iso_manager::BigCallbacks* big_callbacks_ = nullptr;
diff --git a/system/bta/le_audio/codec_manager_test.cc b/system/bta/le_audio/codec_manager_test.cc
index 9ac1fde07d..c69464b72e 100644
--- a/system/bta/le_audio/codec_manager_test.cc
+++ b/system/bta/le_audio/codec_manager_test.cc
@@ -300,10 +300,12 @@ public:
bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);
- ON_CALL(controller_interface, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
- ON_CALL(controller_interface, IsSupported(OpCode::CONFIGURE_DATA_PATH))
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBleIsochronousBroadcaster)
+ .WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, IsSupported(OpCode::CONFIGURE_DATA_PATH))
.WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_interface;
codec_manager = CodecManager::GetInstance();
@@ -311,9 +313,11 @@ public:
RegisterSinkHalClientMock();
}
- virtual void TearDown() override { codec_manager->Stop(); }
+ virtual void TearDown() override {
+ codec_manager->Stop();
+ bluetooth::hci::testing::mock_controller_.release();
+ }
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_interface;
CodecManager* codec_manager;
bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
diff --git a/system/bta/le_audio/devices_test.cc b/system/bta/le_audio/devices_test.cc
index adc90e5213..cd711065c4 100644
--- a/system/bta/le_audio/devices_test.cc
+++ b/system/bta/le_audio/devices_test.cc
@@ -514,7 +514,9 @@ protected:
desired_group_size_ = -1;
bluetooth::manager::SetMockBtmInterface(&btm_interface_);
- bluetooth::hci::testing::mock_controller_ = &controller_interface_;
+
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
auto codec_location = ::bluetooth::le_audio::types::CodecLocation::HOST;
bluetooth::le_audio::AudioSetConfigurationProvider::Initialize(codec_location);
@@ -740,6 +742,8 @@ protected:
if (codec_manager_) {
codec_manager_->Stop();
}
+
+ bluetooth::hci::testing::mock_controller_.reset();
}
LeAudioDevice* AddTestDevice(int snk_ase_num, int src_ase_num, int snk_ase_num_cached = 0,
@@ -1417,7 +1421,6 @@ protected:
LeAudioDeviceGroup* group_ = nullptr;
bluetooth::manager::MockBtmInterface btm_interface_;
MockCsisClient mock_csis_client_module_;
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_interface_;
bluetooth::le_audio::CodecManager* codec_manager_;
MockCodecManager* mock_codec_manager_;
diff --git a/system/bta/le_audio/le_audio_client_test.cc b/system/bta/le_audio/le_audio_client_test.cc
index a3c52dc9e6..02104518d2 100644
--- a/system/bta/le_audio/le_audio_client_test.cc
+++ b/system/bta/le_audio/le_audio_client_test.cc
@@ -1477,11 +1477,13 @@ protected:
init_message_loop_thread();
reset_mock_function_count_map();
- ON_CALL(controller_, SupportsBleConnectedIsochronousStreamCentral).WillByDefault(Return(true));
- ON_CALL(controller_, SupportsBleConnectedIsochronousStreamPeripheral)
+ hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
+ ON_CALL(*hci::testing::mock_controller_, SupportsBleConnectedIsochronousStreamCentral)
.WillByDefault(Return(true));
- ON_CALL(controller_, SupportsBle2mPhy).WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ ON_CALL(*hci::testing::mock_controller_, SupportsBleConnectedIsochronousStreamPeripheral)
+ .WillByDefault(Return(true));
+ ON_CALL(*hci::testing::mock_controller_, SupportsBle2mPhy).WillByDefault(Return(true));
bluetooth::manager::SetMockBtmInterface(&mock_btm_interface_);
gatt::SetMockBtaGattInterface(&mock_gatt_interface_);
gatt::SetMockBtaGattQueue(&mock_gatt_queue_);
@@ -1595,7 +1597,7 @@ protected:
}
iso_manager_->Stop();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ hci::testing::mock_controller_.reset();
}
protected:
@@ -2761,7 +2763,6 @@ protected:
/* Audio track metadata */
char* test_tags_ptr_ = nullptr;
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_;
};
class UnicastTest : public UnicastTestNoInit {
diff --git a/system/bta/le_audio/state_machine_test.cc b/system/bta/le_audio/state_machine_test.cc
index d17bfda188..e0860515fb 100644
--- a/system/bta/le_audio/state_machine_test.cc
+++ b/system/bta/le_audio/state_machine_test.cc
@@ -261,7 +261,9 @@ protected:
bluetooth::manager::SetMockBtmInterface(&btm_interface);
gatt::SetMockBtaGattInterface(&gatt_interface);
gatt::SetMockBtaGattQueue(&gatt_queue);
- bluetooth::hci::testing::mock_controller_ = &controller_;
+
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
overwrite_cis_status_idx_ = 0;
use_cis_retry_cnt_ = false;
@@ -649,7 +651,7 @@ protected:
cached_remote_qos_configuration_for_ase_.clear();
LeAudioGroupStateMachine::Cleanup();
::bluetooth::le_audio::AudioSetConfigurationProvider::Cleanup();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.release();
}
std::shared_ptr<LeAudioDevice> PrepareConnectedDevice(uint8_t id,
@@ -1714,7 +1716,6 @@ protected:
std::vector<RawAddress> addresses_;
std::map<uint8_t, std::unique_ptr<LeAudioDeviceGroup>> le_audio_device_groups_;
bool group_create_command_disallowed_ = false;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class StateMachineTest : public StateMachineTestBase {
diff --git a/system/bta/test/bta_ag_sco_test.cc b/system/bta/test/bta_ag_sco_test.cc
index 16caac7665..a90198c54a 100644
--- a/system/bta/test/bta_ag_sco_test.cc
+++ b/system/bta/test/bta_ag_sco_test.cc
@@ -43,14 +43,14 @@ protected:
this->codec = codec;
return enh_esco_params_t{};
};
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
void TearDown() override {
test::mock::device_esco_parameters::esco_parameters_for_codec = {};
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
esco_codec_t codec;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
TEST_P(BtaAgScoParameterSelectionTest, create_sco_cvsd) {
diff --git a/system/bta/test/bta_ag_test.cc b/system/bta/test/bta_ag_test.cc
index 5fa3884669..2114f7e773 100644
--- a/system/bta/test/bta_ag_test.cc
+++ b/system/bta/test/bta_ag_test.cc
@@ -65,7 +65,8 @@ protected:
void SetUp() override {
reset_mock_function_count_map();
fake_osi_ = std::make_unique<test::fake::FakeOsi>();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
main_thread_start_up();
post_on_bt_main([]() { log::info("Main thread started up"); });
@@ -85,7 +86,7 @@ protected:
bta_sys_deregister(BTA_ID_AG);
post_on_bt_main([]() { log::info("Main thread shutting down"); });
main_thread_shut_down();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
std::unique_ptr<test::fake::FakeOsi> fake_osi_;
@@ -93,7 +94,6 @@ protected:
uint32_t tmp_num = 0xFFFF;
RawAddress addr;
esco_codec_t codec;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaAgSwbTest : public BtaAgTest {
diff --git a/system/bta/test/bta_dm_test.cc b/system/bta/test/bta_dm_test.cc
index 90d41d5e6f..b49008b739 100644
--- a/system/bta/test/bta_dm_test.cc
+++ b/system/bta/test/bta_dm_test.cc
@@ -65,10 +65,10 @@ class BtaDmTest : public BtaWithContextTest {
protected:
void SetUp() override {
BtaWithContextTest::SetUp();
- ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
- cb(0x1234);
- });
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, LeRand)
+ .WillByDefault([](bluetooth::hci::LeRandCallback cb) { cb(0x1234); });
BTA_dm_init();
bluetooth::legacy::testing::bta_dm_init_cb();
@@ -82,9 +82,8 @@ protected:
void TearDown() override {
bluetooth::legacy::testing::bta_dm_deinit_cb();
BtaWithContextTest::TearDown();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaDmCustomAlarmTest : public BtaDmTest {
diff --git a/system/bta/test/bta_sdp_test.cc b/system/bta/test/bta_sdp_test.cc
index 06e8ff86aa..77f1762cc0 100644
--- a/system/bta/test/bta_sdp_test.cc
+++ b/system/bta/test/bta_sdp_test.cc
@@ -30,17 +30,16 @@ class BtaSdpTest : public BtaWithHwOnTest {
protected:
void SetUp() override {
BtaWithHwOnTest::SetUp();
- ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
- cb(0x1234);
- });
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, LeRand)
+ .WillByDefault([](bluetooth::hci::LeRandCallback cb) { cb(0x1234); });
}
void TearDown() override {
BtaWithHwOnTest::TearDown();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaSdpRegisteredTest : public BtaSdpTest {
diff --git a/system/bta/test/bta_test_fixtures.h b/system/bta/test/bta_test_fixtures.h
index c259d0b916..e41e64d496 100644
--- a/system/bta/test/bta_test_fixtures.h
+++ b/system/bta/test/bta_test_fixtures.h
@@ -60,7 +60,8 @@ protected:
ASSERT_NE(get_btm_client_interface().lifecycle.btm_init, nullptr);
ASSERT_NE(get_btm_client_interface().lifecycle.btm_free, nullptr);
- bluetooth::hci::testing::mock_controller_ = &mock_controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
bluetooth::testing::stack::rnr::set_interface(&mock_stack_rnr_interface_);
test::mock::stack_gatt_api::GATT_Register.body =
@@ -85,12 +86,11 @@ protected:
mock_btm_client_interface.eir.BTM_WriteEIR = {};
bluetooth::testing::stack::rnr::reset_interface();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
BtaWithFakesTest::TearDown();
}
- bluetooth::hci::testing::MockControllerInterface mock_controller_;
bluetooth::testing::stack::rnr::Mock mock_stack_rnr_interface_;
};
diff --git a/system/btif/test/btif_core_test.cc b/system/btif/test/btif_core_test.cc
index 7342a17b99..3073bd194c 100644
--- a/system/btif/test/btif_core_test.cc
+++ b/system/btif/test/btif_core_test.cc
@@ -207,7 +207,8 @@ class BtifCoreTest : public ::testing::Test {
protected:
void SetUp() override {
callback_map_.clear();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
bluetooth::testing::set_hal_cbacks(&callbacks);
auto promise = std::promise<void>();
auto future = promise.get_future();
@@ -223,17 +224,17 @@ protected:
callback_map_["callback_thread_event"] = [&promise]() { promise.set_value(); };
CleanCoreInterface();
ASSERT_EQ(std::future_status::ready, future.wait_for(timeout_time));
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
callback_map_.erase("callback_thread_event");
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtifCoreWithControllerTest : public BtifCoreTest {
protected:
void SetUp() override {
BtifCoreTest::SetUp();
- ON_CALL(controller_, SupportsSniffSubrating).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsSniffSubrating)
+ .WillByDefault(Return(true));
}
void TearDown() override { BtifCoreTest::TearDown(); }
@@ -761,12 +762,13 @@ class BtifCoreWithVendorSupportTest : public BtifCoreWithControllerTest {
protected:
void SetUp() override {
BtifCoreWithControllerTest::SetUp();
- bluetooth::hci::testing::mock_hci_layer_ = &hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
test::mock::osi_properties::osi_property_get.body = get_properties;
std::promise<void> configuration_promise;
auto configuration_done = configuration_promise.get_future();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(
// Replace with real PDL for 0xfc17
@@ -784,7 +786,7 @@ protected:
configuration_promise.set_value();
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce([](std::unique_ptr<CommandBuilder> cmd,
ContextualOnceCallback<void(CommandCompleteView)> callback) {
@@ -798,7 +800,8 @@ protected:
callback(response);
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_, RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
.WillOnce(SaveArg<1>(&this->vse_callback_));
do_in_main_thread(BindOnce([]() { bluetooth::bqr::EnableBtQualityReport(get_main()); }));
ASSERT_EQ(std::future_status::ready, configuration_done.wait_for(std::chrono::seconds(1)));
@@ -808,18 +811,18 @@ protected:
std::promise<void> disable_promise;
auto disable_future = disable_promise.get_future();
auto set_promise = [&disable_promise]() { disable_promise.set_value(); };
- EXPECT_CALL(hci_, UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(Invoke(set_promise))
.RetiresOnSaturation();
do_in_main_thread(BindOnce([]() { bluetooth::bqr::DisableBtQualityReport(); }));
ASSERT_EQ(std::future_status::ready, disable_future.wait_for(std::chrono::seconds(1)));
- bluetooth::hci::testing::mock_hci_layer_ = nullptr;
+ bluetooth::hci::testing::mock_hci_layer_.reset();
BtifCoreWithControllerTest::TearDown();
}
- bluetooth::hci::testing::MockHciLayer hci_;
ContextualCallback<void(VendorSpecificEventView)> vse_callback_;
};
diff --git a/system/main/test/main_shim_test.cc b/system/main/test/main_shim_test.cc
index 2f4056a381..c66024cabb 100644
--- a/system/main/test/main_shim_test.cc
+++ b/system/main/test/main_shim_test.cc
@@ -332,8 +332,10 @@ protected:
thread_ = new os::Thread("acl_thread", os::Thread::Priority::NORMAL);
handler_ = new os::Handler(thread_);
- /* extern */ test::mock_controller_ = new bluetooth::hci::testing::MockControllerInterface();
- /* extern */ test::mock_acl_manager_ = new bluetooth::hci::testing::MockAclManager();
+ /* extern */ test::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ /* extern */ test::mock_acl_manager_ =
+ std::make_unique<bluetooth::hci::testing::MockAclManager>();
/* extern */ test::mock_le_scanning_manager_ =
new bluetooth::hci::testing::MockLeScanningManager();
/* extern */ test::mock_le_advertising_manager_ =
@@ -342,10 +344,8 @@ protected:
new bluetooth::hci::testing::MockDistanceMeasurementManager();
}
void TearDown() override {
- delete test::mock_controller_;
- test::mock_controller_ = nullptr;
- delete test::mock_acl_manager_;
- test::mock_acl_manager_ = nullptr;
+ test::mock_controller_.reset();
+ test::mock_acl_manager_.release();
delete test::mock_le_advertising_manager_;
test::mock_le_advertising_manager_ = nullptr;
delete test::mock_le_scanning_manager_;
@@ -567,7 +567,6 @@ TEST_F(MainShimTest, DISABLED_BleScannerInterfaceImpl_OnScanResult) {
bluetooth::shim::get_ble_scanner_instance());
EXPECT_CALL(*hci::testing::mock_le_scanning_manager_, RegisterScanningCallback(_)).Times(1);
- ;
bluetooth::shim::init_scanning_manager();
TestScanningCallbacks cb;
diff --git a/system/stack/fuzzers/l2cap_fuzzer.cc b/system/stack/fuzzers/l2cap_fuzzer.cc
index 6cb4d5170f..69243a67c4 100644
--- a/system/stack/fuzzers/l2cap_fuzzer.cc
+++ b/system/stack/fuzzers/l2cap_fuzzer.cc
@@ -121,26 +121,30 @@ public:
GetInterfaceToProfiles()->profileSpecific_HACK->GetHearingAidDeviceCount = []() { return 1; };
- ON_CALL(controller_, GetLeSuggestedDefaultDataLength).WillByDefault(Return(512));
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeSuggestedDefaultDataLength)
+ .WillByDefault(Return(512));
bluetooth::hci::LeBufferSize iso_size;
iso_size.le_data_packet_length_ = 512;
iso_size.total_num_le_packets_ = 6;
- ON_CALL(controller_, GetControllerIsoBufferSize).WillByDefault(Return(iso_size));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetControllerIsoBufferSize)
+ .WillByDefault(Return(iso_size));
bluetooth::hci::LeBufferSize le_size;
le_size.le_data_packet_length_ = 512;
le_size.total_num_le_packets_ = 6;
- ON_CALL(controller_, GetLeBufferSize).WillByDefault(Return(le_size));
- ON_CALL(controller_, SupportsBle).WillByDefault(Return(true));
- ON_CALL(controller_, GetAclPacketLength).WillByDefault(Return(512));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillByDefault(Return(le_size));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBle).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetAclPacketLength)
+ .WillByDefault(Return(512));
}
~FakeBtStack() {
test::mock::stack_acl::acl_send_data_packet_br_edr = {};
test::mock::stack_acl::acl_send_data_packet_ble = {};
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class Fakes {
diff --git a/system/stack/test/btm/stack_btm_power_mode_test.cc b/system/stack/test/btm/stack_btm_power_mode_test.cc
index a3376d8649..ad7b27a71a 100644
--- a/system/stack/test/btm/stack_btm_power_mode_test.cc
+++ b/system/stack/test/btm/stack_btm_power_mode_test.cc
@@ -49,8 +49,10 @@ std::deque<power_mode_callback> power_mode_callback_queue;
class StackBtmPowerMode : public testing::Test {
protected:
void SetUp() override {
- ON_CALL(controller_, SupportsSniffMode).WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsSniffMode)
+ .WillByDefault(Return(true));
power_mode_callback_queue.clear();
reset_mock_function_count_map();
ASSERT_EQ(tBTM_STATUS::BTM_SUCCESS,
@@ -71,10 +73,9 @@ protected:
BTM_PmRegister(BTM_PM_DEREG, &pm_id_,
[](const RawAddress& /* p_bda */, tBTM_PM_STATUS /* status */,
uint16_t /* value */, tHCI_STATUS /* hci_status */) {}));
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
uint8_t pm_id_{0};
};
diff --git a/system/stack/test/btm/stack_btm_sec_test.cc b/system/stack/test/btm/stack_btm_sec_test.cc
index 58317afc29..62226e2750 100644
--- a/system/stack/test/btm/stack_btm_sec_test.cc
+++ b/system/stack/test/btm/stack_btm_sec_test.cc
@@ -69,7 +69,8 @@ protected:
down_thread_ =
new bluetooth::os::Thread("down_thread", bluetooth::os::Thread::Priority::NORMAL);
down_handler_ = new bluetooth::os::Handler(down_thread_);
- bluetooth::hci::testing::mock_hci_layer_ = &mock_hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
bluetooth::hci::testing::mock_gd_shim_handler_ = up_handler_;
}
void TearDown() override {
@@ -79,10 +80,10 @@ protected:
down_handler_->Clear();
delete down_handler_;
delete down_thread_;
+ bluetooth::hci::testing::mock_hci_layer_.reset();
StackBtmSecTest::TearDown();
}
bluetooth::common::BidiQueue<bluetooth::hci::ScoView, bluetooth::hci::ScoBuilder> sco_queue_{10};
- bluetooth::hci::testing::MockHciLayer mock_hci_;
bluetooth::os::Thread* up_thread_;
bluetooth::os::Handler* up_handler_;
bluetooth::os::Thread* down_thread_;
diff --git a/system/stack/test/btm/stack_btm_test.cc b/system/stack/test/btm/stack_btm_test.cc
index 7471d4faca..2341b21677 100644
--- a/system/stack/test/btm/stack_btm_test.cc
+++ b/system/stack/test/btm/stack_btm_test.cc
@@ -63,13 +63,13 @@ public:
protected:
void SetUp() override {
BtmWithMocksTest::SetUp();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
void TearDown() override {
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
BtmWithMocksTest::TearDown();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class StackBtmWithQueuesTest : public StackBtmTest {
@@ -82,11 +82,12 @@ protected:
down_thread_ =
new bluetooth::os::Thread("down_thread", bluetooth::os::Thread::Priority::NORMAL);
down_handler_ = new bluetooth::os::Handler(down_thread_);
- bluetooth::hci::testing::mock_hci_layer_ = &mock_hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
bluetooth::hci::testing::mock_gd_shim_handler_ = up_handler_;
bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);
- EXPECT_CALL(mock_hci_, RegisterForScoConnectionRequests(_));
- EXPECT_CALL(mock_hci_, RegisterForDisconnects(_));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, RegisterForScoConnectionRequests(_));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, RegisterForDisconnects(_));
}
void TearDown() override {
up_handler_->Clear();
@@ -95,10 +96,10 @@ protected:
down_handler_->Clear();
delete down_handler_;
delete down_thread_;
+ bluetooth::hci::testing::mock_hci_layer_.release();
StackBtmTest::TearDown();
}
bluetooth::common::BidiQueue<bluetooth::hci::ScoView, bluetooth::hci::ScoBuilder> sco_queue_{10};
- bluetooth::hci::testing::MockHciLayer mock_hci_;
bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
bluetooth::os::Thread* up_thread_;
bluetooth::os::Handler* up_handler_;
@@ -111,7 +112,8 @@ public:
protected:
void SetUp() override {
StackBtmWithQueuesTest::SetUp();
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
btm_cb.Init();
btm_sec_cb.Init(BTM_SEC_MODE_SC);
}
@@ -123,7 +125,8 @@ protected:
};
TEST_F(StackBtmWithQueuesTest, GlobalLifecycle) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
get_btm_client_interface().lifecycle.btm_free();
}
@@ -134,20 +137,23 @@ TEST_F(StackBtmTest, DynamicLifecycle) {
}
TEST_F(StackBtmWithQueuesTest, InitFree) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
btm_cb.Init();
btm_cb.Free();
}
TEST_F(StackBtmWithQueuesTest, tSCO_CB) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
tSCO_CB* p_sco = &btm_cb.sco_cb;
p_sco->Init();
p_sco->Free();
}
TEST_F(StackBtmWithQueuesTest, InformClientOnConnectionSuccess) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
@@ -159,7 +165,8 @@ TEST_F(StackBtmWithQueuesTest, InformClientOnConnectionSuccess) {
}
TEST_F(StackBtmWithQueuesTest, NoInformClientOnConnectionFail) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
@@ -171,7 +178,8 @@ TEST_F(StackBtmWithQueuesTest, NoInformClientOnConnectionFail) {
}
TEST_F(StackBtmWithQueuesTest, default_packet_type) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
btm_cb.acl_cb_.SetDefaultPacketTypeMask(0x4321);
@@ -181,7 +189,8 @@ TEST_F(StackBtmWithQueuesTest, default_packet_type) {
}
TEST_F(StackBtmWithQueuesTest, change_packet_type) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
uint16_t handle = 0x123;
diff --git a/system/stack/test/btm_iso_test.cc b/system/stack/test/btm_iso_test.cc
index 40453f703d..b44f6fe094 100644
--- a/system/stack/test/btm_iso_test.cc
+++ b/system/stack/test/btm_iso_test.cc
@@ -134,7 +134,8 @@ protected:
bluetooth::shim::SetMockIsoInterface(&iso_interface_);
hcic::SetMockHcicInterface(&hcic_interface_);
bluetooth::shim::testing::hci_layer_set_interface(&bluetooth::shim::interface);
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
big_callbacks_.reset(new MockBigCallbacks());
cig_callbacks_.reset(new MockCigCallbacks());
@@ -142,7 +143,8 @@ protected:
iso_sizes_.total_num_le_packets_ = 6;
iso_sizes_.le_data_packet_length_ = 1024;
- ON_CALL(controller_, GetControllerIsoBufferSize()).WillByDefault(Return(iso_sizes_));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetControllerIsoBufferSize())
+ .WillByDefault(Return(iso_sizes_));
InitIsoManager();
}
@@ -156,7 +158,7 @@ protected:
bluetooth::shim::SetMockIsoInterface(nullptr);
hcic::SetMockHcicInterface(nullptr);
bluetooth::shim::testing::hci_layer_set_interface(nullptr);
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
virtual void InitIsoManager() {
@@ -312,7 +314,6 @@ protected:
IsoManager* manager_instance_;
bluetooth::shim::MockIsoInterface iso_interface_;
hcic::MockHcicInterface hcic_interface_;
- bluetooth::hci::testing::MockControllerInterface controller_;
bluetooth::hci::LeBufferSize iso_sizes_;
std::unique_ptr<MockBigCallbacks> big_callbacks_;
@@ -2207,7 +2208,8 @@ TEST_F(IsoManagerTest, SendIsoDataBigValid) {
}
TEST_F(IsoManagerTest, SendIsoDataNoCredits) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2254,7 +2256,8 @@ TEST_F(IsoManagerTest, SendIsoDataNoCredits) {
}
TEST_F(IsoManagerTest, SendIsoDataCreditsReturned) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2323,7 +2326,8 @@ TEST_F(IsoManagerTest, SendIsoDataCreditsReturned) {
}
TEST_F(IsoManagerTest, SendIsoDataCreditsReturnedByDisconnection) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2542,7 +2546,8 @@ TEST_F(IsoManagerDeathTestNoCleanup, HandleLateArivingEventHandleDisconnect) {
* is already stopped.
*/
TEST_F(IsoManagerDeathTestNoCleanup, HandleLateArivingEventHandleNumComplDataPkts) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
IsoManager::GetInstance()->CreateCig(volatile_test_cig_create_cmpl_evt_.cig_id,
kDefaultCigParams);
diff --git a/system/stack/test/connection_manager_test.cc b/system/stack/test/connection_manager_test.cc
index 1a06158ca0..db2908c76b 100644
--- a/system/stack/test/connection_manager_test.cc
+++ b/system/stack/test/connection_manager_test.cc
@@ -70,9 +70,10 @@ namespace connection_manager {
class BleConnectionManager : public testing::Test {
void SetUp() override {
localConnTimeoutMock = std::make_unique<MockConnTimeout>();
- /* extern */ test::mock_acl_manager_ = new bluetooth::hci::testing::MockAclManager();
+ /* extern */ test::mock_acl_manager_ =
+ std::make_unique<bluetooth::hci::testing::MockAclManager>();
/* extern */ test::mock_controller_ =
- new testing::NiceMock<bluetooth::hci::testing::MockControllerInterface>();
+ std::make_unique<testing::NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
ON_CALL(*test::mock_controller_, GetLeFilterAcceptListSize()).WillByDefault(Return(16));
auto alarm_mock = AlarmMock::Get();
@@ -92,8 +93,8 @@ class BleConnectionManager : public testing::Test {
void TearDown() override {
connection_manager::reset(true);
AlarmMock::Reset();
- delete test::mock_controller_;
- delete test::mock_acl_manager_;
+ test::mock_controller_.reset();
+ test::mock_acl_manager_.reset();
localConnTimeoutMock.reset();
}
};
@@ -106,7 +107,7 @@ TEST_F(BleConnectionManager, test_background_connection_add_remove) {
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
std::set<tAPP_ID> apps = get_apps_connecting_to(address1);
EXPECT_EQ(apps.size(), 1UL);
@@ -119,7 +120,7 @@ TEST_F(BleConnectionManager, test_background_connection_add_remove) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 0UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that multiple clients adding same device multiple times, result in
@@ -136,7 +137,7 @@ TEST_F(BleConnectionManager, test_background_connection_multiple_clients) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 3UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(_, _)).Times(0);
@@ -153,7 +154,7 @@ TEST_F(BleConnectionManager, test_background_connection_multiple_clients) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 0UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify adding/removing device to direct connection. */
@@ -173,7 +174,7 @@ TEST_F(BleConnectionManager, test_direct_connection_client) {
// Client that don't do direct connection should fail attempt to stop it
EXPECT_FALSE(direct_connect_remove(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
@@ -183,7 +184,7 @@ TEST_F(BleConnectionManager, test_direct_connection_client) {
// acceptlist is in use, i.e. next connection attempt
EXPECT_TRUE(direct_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify direct connection timeout does remove device from acceptlist, and
@@ -201,7 +202,7 @@ TEST_F(BleConnectionManager, test_direct_connect_timeout) {
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_CALL(*localConnTimeoutMock, OnConnectionTimedOut(CLIENT1, address1)).Times(1);
@@ -210,7 +211,7 @@ TEST_F(BleConnectionManager, test_direct_connect_timeout) {
// simulate timeout seconds passed, alarm executing
alarm_callback(alarm_data);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that we properly handle successfull direct connection */
@@ -222,7 +223,7 @@ TEST_F(BleConnectionManager, test_direct_connection_success) {
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address1_hci)).Times(1);
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
@@ -230,7 +231,7 @@ TEST_F(BleConnectionManager, test_direct_connection_success) {
// successfully.
on_connection_complete(address1);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that we properly handle application unregistration */
@@ -244,23 +245,23 @@ TEST_F(BleConnectionManager, test_app_unregister) {
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address1_hci, true)).Times(1);
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address2_hci, false)).Times(1);
EXPECT_TRUE(background_connect_add(CLIENT1, address2));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address2_hci, true)).Times(1);
EXPECT_TRUE(direct_connect_add(CLIENT2, address2));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address1_hci)).Times(1);
on_app_deregistered(CLIENT1);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address2_hci)).Times(1);
on_app_deregistered(CLIENT2);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify adding device to both direct connection and background connection. */
@@ -273,7 +274,7 @@ TEST_F(BleConnectionManager, test_direct_and_background_connect) {
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
// not removing from acceptlist yet, as the background connection is still
@@ -284,7 +285,7 @@ TEST_F(BleConnectionManager, test_direct_and_background_connect) {
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_target_announement_connect) {
@@ -302,7 +303,7 @@ TEST_F(BleConnectionManager, test_add_targeted_announement_when_allow_list_used)
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_add_background_connect_when_targeted_announcement_are_enabled) {
@@ -315,7 +316,7 @@ TEST_F(BleConnectionManager, test_add_background_connect_when_targeted_announcem
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
@@ -325,7 +326,7 @@ TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
/* Now remove app using targeted announcement and expect device
* to be added to white list
@@ -335,11 +336,11 @@ TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address1_hci, false)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multiple_clients) {
@@ -352,7 +353,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*AlarmMock::Get(), AlarmSetOnMloop(_, _, _, _))
.Times(1)
@@ -360,7 +361,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
// simulate timeout seconds passed, alarm executing
EXPECT_CALL(*localConnTimeoutMock, OnConnectionTimedOut(CLIENT2, address1)).Times(1);
@@ -369,7 +370,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
alarm_callback(alarm_data);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
} // namespace connection_manager
diff --git a/system/stack/test/eatt/eatt_test.cc b/system/stack/test/eatt/eatt_test.cc
index 130893a0a5..5d7a2eeea8 100644
--- a/system/stack/test/eatt/eatt_test.cc
+++ b/system/stack/test/eatt/eatt_test.cc
@@ -219,11 +219,13 @@ protected:
le_buffer_size_.le_data_packet_length_ = 128;
le_buffer_size_.total_num_le_packets_ = 24;
- EXPECT_CALL(controller_, GetLeBufferSize).WillRepeatedly(Return(le_buffer_size_));
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ EXPECT_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillRepeatedly(Return(le_buffer_size_));
bluetooth::l2cap::SetMockInterface(&l2cap_interface_);
bluetooth::manager::SetMockBtmApiInterface(&btm_api_interface_);
bluetooth::gatt::SetMockGattInterface(&gatt_interface_);
- bluetooth::hci::testing::mock_controller_ = &controller_;
// Clear the static memory for each test case
memset(&test_tcb, 0, sizeof(test_tcb));
@@ -258,7 +260,7 @@ protected:
bluetooth::l2cap::SetMockInterface(nullptr);
bluetooth::testing::stack::l2cap::reset_interface();
bluetooth::manager::SetMockBtmApiInterface(nullptr);
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
Test::TearDown();
}
@@ -269,7 +271,6 @@ protected:
bluetooth::l2cap::MockL2capInterface l2cap_interface_;
bluetooth::testing::stack::l2cap::Mock mock_stack_l2cap_interface_;
bluetooth::gatt::MockGattInterface gatt_interface_;
- bluetooth::hci::testing::MockControllerInterface controller_;
bluetooth::hci::LeBufferSize le_buffer_size_;
tL2CAP_APPL_INFO l2cap_app_info_;
diff --git a/system/stack/test/stack_acl_test.cc b/system/stack/test/stack_acl_test.cc
index b08a45cb80..bd0b153b9f 100644
--- a/system/stack/test/stack_acl_test.cc
+++ b/system/stack/test/stack_acl_test.cc
@@ -48,12 +48,12 @@ class StackAclTest : public testing::Test {
protected:
void SetUp() override {
reset_mock_function_count_map();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
- void TearDown() override { bluetooth::hci::testing::mock_controller_ = nullptr; }
+ void TearDown() override { bluetooth::hci::testing::mock_controller_.reset(); }
tBTM_SEC_DEV_REC device_record_;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
TEST_F(StackAclTest, nop) {}
diff --git a/system/stack/test/stack_l2cap_test.cc b/system/stack/test/stack_l2cap_test.cc
index ffe78055bc..204900b462 100644
--- a/system/stack/test/stack_l2cap_test.cc
+++ b/system/stack/test/stack_l2cap_test.cc
@@ -49,23 +49,23 @@ constexpr uint16_t kAclBufferSizeBle = 45;
class StackL2capTest : public ::testing::Test {
protected:
void SetUp() override {
- bluetooth::hci::testing::mock_controller_ = &controller_interface_;
- ON_CALL(controller_interface_, GetNumAclPacketBuffers)
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetNumAclPacketBuffers)
.WillByDefault(Return(kAclBufferCountClassic));
bluetooth::hci::LeBufferSize le_sizes;
le_sizes.total_num_le_packets_ = kAclBufferCountBle;
le_sizes.le_data_packet_length_ = kAclBufferSizeBle;
- ON_CALL(controller_interface_, GetLeBufferSize).WillByDefault(Return(le_sizes));
- ON_CALL(controller_interface_, SupportsBle).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillByDefault(Return(le_sizes));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBle).WillByDefault(Return(true));
l2c_init();
}
void TearDown() override {
l2c_free();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
-
- bluetooth::hci::testing::MockControllerInterface controller_interface_;
};
TEST_F(StackL2capTest, l2cble_process_data_length_change_event) {
diff --git a/system/test/mock/mock_main_shim_entry.cc b/system/test/mock/mock_main_shim_entry.cc
index 5d68f11b9d..3cdc714eaf 100644
--- a/system/test/mock/mock_main_shim_entry.cc
+++ b/system/test/mock/mock_main_shim_entry.cc
@@ -38,9 +38,9 @@ namespace bluetooth {
namespace hci {
namespace testing {
-MockAclManager* mock_acl_manager_{nullptr};
-MockControllerInterface* mock_controller_{nullptr};
-HciInterface* mock_hci_layer_{nullptr};
+std::unique_ptr<MockAclManager> mock_acl_manager_;
+std::unique_ptr<MockControllerInterface> mock_controller_;
+std::unique_ptr<MockHciLayer> mock_hci_layer_;
os::Handler* mock_gd_shim_handler_{nullptr};
MockLeAdvertisingManager* mock_le_advertising_manager_{nullptr};
MockLeScanningManager* mock_le_scanning_manager_{nullptr};
@@ -58,9 +58,9 @@ class Dumpsys;
namespace shim {
-hci::AclManager* GetAclManager() { return hci::testing::mock_acl_manager_; }
-hci::ControllerInterface* GetController() { return hci::testing::mock_controller_; }
-hci::HciInterface* GetHciLayer() { return hci::testing::mock_hci_layer_; }
+hci::AclManager* GetAclManager() { return hci::testing::mock_acl_manager_.get(); }
+hci::ControllerInterface* GetController() { return hci::testing::mock_controller_.get(); }
+hci::HciInterface* GetHciLayer() { return hci::testing::mock_hci_layer_.get(); }
hci::LeAdvertisingManager* GetAdvertising() { return hci::testing::mock_le_advertising_manager_; }
hci::LeScanningManager* GetScanning() { return hci::testing::mock_le_scanning_manager_; }
hci::DistanceMeasurementManager* GetDistanceMeasurementManager() {
diff --git a/system/test/mock/mock_main_shim_entry.h b/system/test/mock/mock_main_shim_entry.h
index ca84a27193..5d427fd963 100644
--- a/system/test/mock/mock_main_shim_entry.h
+++ b/system/test/mock/mock_main_shim_entry.h
@@ -15,11 +15,12 @@
*/
#include <functional>
+#include <memory>
#include "hci/acl_manager_mock.h"
#include "hci/controller_interface_mock.h"
#include "hci/distance_measurement_manager_mock.h"
-#include "hci/hci_interface.h"
+#include "hci/hci_layer_mock.h"
#include "hci/le_advertising_manager_mock.h"
#include "hci/le_scanning_manager_mock.h"
#include "storage/storage_module.h"
@@ -28,9 +29,9 @@ namespace bluetooth {
namespace hci {
namespace testing {
-extern MockAclManager* mock_acl_manager_;
-extern MockControllerInterface* mock_controller_;
-extern HciInterface* mock_hci_layer_;
+extern std::unique_ptr<MockAclManager> mock_acl_manager_;
+extern std::unique_ptr<MockControllerInterface> mock_controller_;
+extern std::unique_ptr<MockHciLayer> mock_hci_layer_;
extern os::Handler* mock_gd_shim_handler_;
extern MockLeAdvertisingManager* mock_le_advertising_manager_;
extern MockLeScanningManager* mock_le_scanning_manager_;