Loading system/stack/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -1527,6 +1527,7 @@ cc_test { "test/btm/peer_packet_types_test.cc", "test/btm/sco_hci_test.cc", "test/btm/sco_pkt_status_test.cc", "test/btm/stack_btm_dev_test.cc", "test/btm/stack_btm_power_mode_test.cc", "test/btm/stack_btm_regression_tests.cc", "test/btm/stack_btm_sec_test.cc", Loading system/stack/btm/btm_dev.cc +6 −0 Original line number Diff line number Diff line Loading @@ -638,6 +638,12 @@ static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec(void) { tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) { tBTM_SEC_DEV_REC* p_dev_rec = NULL; if (btm_sec_cb.sec_dev_rec == nullptr) { LOG_WARN( "Unable to allocate device record with destructed device record list"); return nullptr; } if (list_length(btm_sec_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) { p_dev_rec = btm_find_oldest_dev_rec(); wipe_secrets_and_remove(p_dev_rec); Loading system/stack/test/btm/stack_btm_dev_test.cc 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright 2024 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 <gmock/gmock.h> #include <gtest/gtest.h> #include "stack/btm/btm_dev.h" #include "stack/btm/btm_sec_cb.h" #include "test/common/mock_functions.h" #include "test/mock/mock_main_shim_entry.h" class StackBtmTest : public testing::Test { public: protected: void SetUp() override { reset_mock_function_count_map(); } void TearDown() override {} }; class StackBtmDevTest : public StackBtmTest { protected: void SetUp() override { StackBtmTest::SetUp(); } void TearDown() override { StackBtmTest::TearDown(); } }; TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__no_list) { ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec()); ::btm_sec_cb.Init(BTM_SEC_MODE_SC); ::btm_sec_cb.Free(); ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec()); } TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__with_list) { ::btm_sec_cb.Init(BTM_SEC_MODE_SC); ASSERT_NE(nullptr, btm_sec_allocate_dev_rec()); ::btm_sec_cb.Free(); } Loading
system/stack/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -1527,6 +1527,7 @@ cc_test { "test/btm/peer_packet_types_test.cc", "test/btm/sco_hci_test.cc", "test/btm/sco_pkt_status_test.cc", "test/btm/stack_btm_dev_test.cc", "test/btm/stack_btm_power_mode_test.cc", "test/btm/stack_btm_regression_tests.cc", "test/btm/stack_btm_sec_test.cc", Loading
system/stack/btm/btm_dev.cc +6 −0 Original line number Diff line number Diff line Loading @@ -638,6 +638,12 @@ static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec(void) { tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) { tBTM_SEC_DEV_REC* p_dev_rec = NULL; if (btm_sec_cb.sec_dev_rec == nullptr) { LOG_WARN( "Unable to allocate device record with destructed device record list"); return nullptr; } if (list_length(btm_sec_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) { p_dev_rec = btm_find_oldest_dev_rec(); wipe_secrets_and_remove(p_dev_rec); Loading
system/stack/test/btm/stack_btm_dev_test.cc 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright 2024 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 <gmock/gmock.h> #include <gtest/gtest.h> #include "stack/btm/btm_dev.h" #include "stack/btm/btm_sec_cb.h" #include "test/common/mock_functions.h" #include "test/mock/mock_main_shim_entry.h" class StackBtmTest : public testing::Test { public: protected: void SetUp() override { reset_mock_function_count_map(); } void TearDown() override {} }; class StackBtmDevTest : public StackBtmTest { protected: void SetUp() override { StackBtmTest::SetUp(); } void TearDown() override { StackBtmTest::TearDown(); } }; TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__no_list) { ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec()); ::btm_sec_cb.Init(BTM_SEC_MODE_SC); ::btm_sec_cb.Free(); ASSERT_EQ(nullptr, btm_sec_allocate_dev_rec()); } TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__with_list) { ::btm_sec_cb.Init(BTM_SEC_MODE_SC); ASSERT_NE(nullptr, btm_sec_allocate_dev_rec()); ::btm_sec_cb.Free(); }