summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
author Jakub Pawlowski <jpawlowski@google.com> 2025-03-06 10:46:57 +0100
committer Jakub Pawlowski <jpawlowski@google.com> 2025-03-12 12:27:39 +0100
commiteb06188da9843a034ee8915beffd092581cc7279 (patch)
tree0a14c0a1d67efecce49963240729d4337a0355c0 /system
parent271e582f3a2d75849f7746c42f4cf5f39a7e0f72 (diff)
Test: make mock_controller_ into unique_ptr
Getting rid of memory leaks, dangling pointers in tests. Bug: None Test: updated Flag: exempt, test only change Change-Id: I4d5ab702da62364a41bf1d822482396456dc8656
Diffstat (limited to 'system')
-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.cc9
-rw-r--r--system/main/test/main_shim_test.cc7
-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_test.cc6
-rw-r--r--system/stack/test/btm_iso_test.cc21
-rw-r--r--system/stack/test/connection_manager_test.cc4
-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.cc4
-rw-r--r--system/test/mock/mock_main_shim_entry.h2
22 files changed, 110 insertions, 91 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 b8f79a609b..7b4c44f2e5 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..21723e3674 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(); }
diff --git a/system/main/test/main_shim_test.cc b/system/main/test/main_shim_test.cc
index 5e11dd248b..c66024cabb 100644
--- a/system/main/test/main_shim_test.cc
+++ b/system/main/test/main_shim_test.cc
@@ -332,7 +332,8 @@ 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_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_ =
@@ -343,8 +344,7 @@ protected:
new bluetooth::hci::testing::MockDistanceMeasurementManager();
}
void TearDown() override {
- delete test::mock_controller_;
- test::mock_controller_ = nullptr;
+ test::mock_controller_.reset();
test::mock_acl_manager_.release();
delete test::mock_le_advertising_manager_;
test::mock_le_advertising_manager_ = nullptr;
@@ -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_test.cc b/system/stack/test/btm/stack_btm_test.cc
index 7471d4faca..b053049e82 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 {
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 9b07b841de..db2908c76b 100644
--- a/system/stack/test/connection_manager_test.cc
+++ b/system/stack/test/connection_manager_test.cc
@@ -73,7 +73,7 @@ class BleConnectionManager : public testing::Test {
/* 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();
@@ -93,7 +93,7 @@ class BleConnectionManager : public testing::Test {
void TearDown() override {
connection_manager::reset(true);
AlarmMock::Reset();
- delete test::mock_controller_;
+ test::mock_controller_.reset();
test::mock_acl_manager_.reset();
localConnTimeoutMock.reset();
}
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 e8c649b6cf..cb599b02a1 100644
--- a/system/test/mock/mock_main_shim_entry.cc
+++ b/system/test/mock/mock_main_shim_entry.cc
@@ -39,7 +39,7 @@ namespace hci {
namespace testing {
std::unique_ptr<MockAclManager> mock_acl_manager_;
-MockControllerInterface* mock_controller_{nullptr};
+std::unique_ptr<MockControllerInterface> mock_controller_;
HciInterface* mock_hci_layer_{nullptr};
os::Handler* mock_gd_shim_handler_{nullptr};
MockLeAdvertisingManager* mock_le_advertising_manager_{nullptr};
@@ -59,7 +59,7 @@ class Dumpsys;
namespace shim {
hci::AclManager* GetAclManager() { return hci::testing::mock_acl_manager_.get(); }
-hci::ControllerInterface* GetController() { return hci::testing::mock_controller_; }
+hci::ControllerInterface* GetController() { return hci::testing::mock_controller_.get(); }
hci::HciInterface* GetHciLayer() { return hci::testing::mock_hci_layer_; }
hci::LeAdvertisingManager* GetAdvertising() { return hci::testing::mock_le_advertising_manager_; }
hci::LeScanningManager* GetScanning() { return hci::testing::mock_le_scanning_manager_; }
diff --git a/system/test/mock/mock_main_shim_entry.h b/system/test/mock/mock_main_shim_entry.h
index b82b6b8122..8666648d69 100644
--- a/system/test/mock/mock_main_shim_entry.h
+++ b/system/test/mock/mock_main_shim_entry.h
@@ -30,7 +30,7 @@ namespace hci {
namespace testing {
extern std::unique_ptr<MockAclManager> mock_acl_manager_;
-extern MockControllerInterface* mock_controller_;
+extern std::unique_ptr<MockControllerInterface> mock_controller_;
extern HciInterface* mock_hci_layer_;
extern os::Handler* mock_gd_shim_handler_;
extern MockLeAdvertisingManager* mock_le_advertising_manager_;