summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Henri Chataing <henrichataing@google.com> 2024-12-21 01:36:53 +0000
committer Henri Chataing <henrichataing@google.com> 2025-01-06 09:17:57 +0000
commitfa6e84621d4a08414abbecf177d3d7eb5c5af114 (patch)
tree3ede197922917e85ed733e864fc27478579207dd
parent77321e97285d844a9cf27c4ff3628654bd281b7d (diff)
btif_dm_test: Start only the StorageModule
Bug: 333555245 Flage: EXEMPT, test change Test: atest --host net_test_btif:BtifDmWithStackTest Change-Id: I4b2351c8a599fa42e74ee6c6f402b9b05514df6e
-rw-r--r--system/btif/test/btif_dm_test.cc41
-rw-r--r--system/gd/module.h3
-rw-r--r--system/gd/storage/storage_module.cc22
-rw-r--r--system/gd/storage/storage_module.h12
-rw-r--r--system/gd/storage/storage_module_test.cc4
-rw-r--r--system/main/shim/entry.cc3
-rw-r--r--system/main/shim/shim.cc4
-rw-r--r--system/test/Android.bp9
-rw-r--r--system/test/mock/mock_main_shim.cc35
-rw-r--r--system/test/mock/mock_main_shim_entry.cc10
10 files changed, 73 insertions, 70 deletions
diff --git a/system/btif/test/btif_dm_test.cc b/system/btif/test/btif_dm_test.cc
index 5d7595b1c5..068740472f 100644
--- a/system/btif/test/btif_dm_test.cc
+++ b/system/btif/test/btif_dm_test.cc
@@ -23,8 +23,9 @@
#include <memory>
#include "bta/include/bta_api_data_types.h"
-#include "btif/include/btif_dm.h"
#include "btif/include/mock_core_callbacks.h"
+#include "main/shim/entry.h"
+#include "main/shim/shim.h"
#include "main/shim/stack.h"
#include "module.h"
#include "stack/include/bt_dev_class.h"
@@ -116,21 +117,47 @@ TEST_F(BtifDmWithUidTest, bta_energy_info_cb__with_uid) {
ASSERT_TRUE(invoke_energy_info_cb_entered);
}
+// Mock implementation for GetStorage()
+static bluetooth::storage::StorageModule* s_StorageModule = nullptr;
+bluetooth::storage::StorageModule* bluetooth::shim::GetStorage() { return s_StorageModule; }
+
+bluetooth::os::Handler* bluetooth::shim::GetGdShimHandler() { return nullptr; }
+bluetooth::hci::LeAdvertisingManager* bluetooth::shim::GetAdvertising() { return nullptr; }
+bluetooth::hci::ControllerInterface* bluetooth::shim::GetController() { return nullptr; }
+bluetooth::hci::HciInterface* bluetooth::shim::GetHciLayer() { return nullptr; }
+bluetooth::hci::RemoteNameRequestModule* bluetooth::shim::GetRemoteNameRequest() { return nullptr; }
+bluetooth::hci::LeScanningManager* bluetooth::shim::GetScanning() { return nullptr; }
+bluetooth::hci::DistanceMeasurementManager* bluetooth::shim::GetDistanceMeasurementManager() {
+ return nullptr;
+}
+bluetooth::hal::SnoopLogger* bluetooth::shim::GetSnoopLogger() { return nullptr; }
+bluetooth::lpp::LppOffloadInterface* bluetooth::shim::GetLppOffloadManager() { return nullptr; }
+bluetooth::hci::AclManager* bluetooth::shim::GetAclManager() { return nullptr; }
+bluetooth::metrics::CounterMetrics* bluetooth::shim::GetCounterMetrics() { return nullptr; }
+bluetooth::hci::MsftExtensionManager* bluetooth::shim::GetMsftExtensionManager() { return nullptr; }
+
+bool bluetooth::shim::is_gd_stack_started_up() { return s_StorageModule != nullptr; }
+
class BtifDmWithStackTest : public BtifDmTest {
protected:
void SetUp() override {
BtifDmTest::SetUp();
- modules_.add<bluetooth::storage::StorageModule>();
- bluetooth::shim::Stack::GetInstance()->StartModuleStack(
- &modules_,
- new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL));
+ thread_ = new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL);
+ storage_module_ = new bluetooth::storage::StorageModule(new bluetooth::os::Handler(thread_));
+ storage_module_->Start();
+ s_StorageModule = storage_module_;
}
void TearDown() override {
- bluetooth::shim::Stack::GetInstance()->Stop();
+ storage_module_->Stop();
+ s_StorageModule = nullptr;
+ delete storage_module_;
+ delete thread_;
BtifDmTest::TearDown();
}
- bluetooth::ModuleList modules_;
+
+ bluetooth::os::Thread* thread_;
+ bluetooth::storage::StorageModule* storage_module_;
};
TEST_F_WITH_FLAGS(BtifDmWithStackTest, btif_dm_search_services_evt__BTA_DM_NAME_READ_EVT) {
diff --git a/system/gd/module.h b/system/gd/module.h
index e708035a77..858d4cd070 100644
--- a/system/gd/module.h
+++ b/system/gd/module.h
@@ -81,9 +81,12 @@ class Module {
friend TestModuleRegistry;
public:
+ Module() = default;
virtual ~Module() = default;
protected:
+ Module(os::Handler* handler) : handler_(handler) {}
+
// Populate the provided list with modules that must start before yours
virtual void ListDependencies(ModuleList* list) const = 0;
diff --git a/system/gd/storage/storage_module.cc b/system/gd/storage/storage_module.cc
index ce5a89c6f7..0a7c9a7ef1 100644
--- a/system/gd/storage/storage_module.cc
+++ b/system/gd/storage/storage_module.cc
@@ -63,11 +63,20 @@ const std::string StorageModule::kTimeCreatedFormat = "%Y-%m-%d %H:%M:%S";
const std::string StorageModule::kAdapterSection = BTIF_STORAGE_SECTION_ADAPTER;
-StorageModule::StorageModule(std::string config_file_path,
+StorageModule::StorageModule()
+ : StorageModule(nullptr, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay,
+ kDefaultTempDeviceCapacity, false, false) {}
+
+StorageModule::StorageModule(os::Handler* handler)
+ : StorageModule(handler, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay,
+ kDefaultTempDeviceCapacity, false, false) {}
+
+StorageModule::StorageModule(os::Handler* handler, std::string config_file_path,
std::chrono::milliseconds config_save_delay,
size_t temp_devices_capacity, bool is_restricted_mode,
bool is_single_user_mode)
- : config_file_path_(std::move(config_file_path)),
+ : Module(handler),
+ config_file_path_(std::move(config_file_path)),
config_save_delay_(config_save_delay),
temp_devices_capacity_(temp_devices_capacity),
is_restricted_mode_(is_restricted_mode),
@@ -84,10 +93,7 @@ StorageModule::~StorageModule() {
pimpl_.reset();
}
-const ModuleFactory StorageModule::Factory = ModuleFactory([]() {
- return new StorageModule(os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay,
- kDefaultTempDeviceCapacity, false, false);
-});
+const ModuleFactory StorageModule::Factory = ModuleFactory([]() { return new StorageModule(); });
struct StorageModule::impl {
explicit impl(Handler* handler, ConfigCache cache, size_t in_memory_cache_size_limit)
@@ -144,9 +150,7 @@ void StorageModule::Clear() {
pimpl_->cache_.Clear();
}
-void StorageModule::ListDependencies(ModuleList* list) const {
- list->add<metrics::CounterMetrics>();
-}
+void StorageModule::ListDependencies(ModuleList* /*list*/) const {}
void StorageModule::Start() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
diff --git a/system/gd/storage/storage_module.h b/system/gd/storage/storage_module.h
index 12f5750196..b94251a0dc 100644
--- a/system/gd/storage/storage_module.h
+++ b/system/gd/storage/storage_module.h
@@ -55,12 +55,17 @@ public:
static const std::string kAdapterSection;
+ StorageModule();
+ StorageModule(os::Handler*);
StorageModule(const StorageModule&) = delete;
StorageModule& operator=(const StorageModule&) = delete;
~StorageModule();
static const ModuleFactory Factory;
+ void Start() override;
+ void Stop() override;
+
// Methods to access the storage layer via Device abstraction
// - Devices will be lazily created when methods below are called. Hence, no std::optional<> nor
// nullptr is used in
@@ -121,8 +126,6 @@ public:
protected:
void ListDependencies(ModuleList* list) const override;
- void Start() override;
- void Stop() override;
std::string ToString() const override;
friend shim::BtifConfigInterface;
@@ -147,8 +150,9 @@ protected:
// - temp_devices_capacity is the number of temporary, typically unpaired devices to hold in a
// memory based LRU
// - is_restricted_mode and is_single_user_mode are flags from upper layer
- StorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay,
- size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode);
+ StorageModule(os::Handler* handler, std::string config_file_path,
+ std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity,
+ bool is_restricted_mode, bool is_single_user_mode);
bool HasSection(const std::string& section) const;
bool HasProperty(const std::string& section, const std::string& property) const;
diff --git a/system/gd/storage/storage_module_test.cc b/system/gd/storage/storage_module_test.cc
index 2f600944ae..e58c210609 100644
--- a/system/gd/storage/storage_module_test.cc
+++ b/system/gd/storage/storage_module_test.cc
@@ -53,8 +53,8 @@ class TestStorageModule : public StorageModule {
public:
TestStorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay,
bool is_restricted_mode, bool is_single_user_mode)
- : StorageModule(std::move(config_file_path), config_save_delay, kTestTempDevicesCapacity,
- is_restricted_mode, is_single_user_mode) {}
+ : StorageModule(nullptr, std::move(config_file_path), config_save_delay,
+ kTestTempDevicesCapacity, is_restricted_mode, is_single_user_mode) {}
ConfigCache* GetMemoryOnlyConfigCachePublic() {
return StorageModule::GetMemoryOnlyConfigCache();
diff --git a/system/main/shim/entry.cc b/system/main/shim/entry.cc
index ff0014b481..9fe8e8bd55 100644
--- a/system/main/shim/entry.cc
+++ b/system/main/shim/entry.cc
@@ -27,6 +27,7 @@
#include "hci/msft.h"
#include "hci/remote_name_request.h"
#include "lpp/lpp_offload_manager.h"
+#include "main/shim/shim.h"
#include "main/shim/stack.h"
#include "metrics/counter_metrics.h"
#include "os/handler.h"
@@ -79,5 +80,7 @@ hci::MsftExtensionManager* GetMsftExtensionManager() {
return Stack::GetInstance()->GetInstance<hci::MsftExtensionManager>();
}
+bool is_gd_stack_started_up() { return Stack::GetInstance()->IsRunning(); }
+
} // namespace shim
} // namespace bluetooth
diff --git a/system/main/shim/shim.cc b/system/main/shim/shim.cc
index 69c70cd9ba..81bd0b6bf3 100644
--- a/system/main/shim/shim.cc
+++ b/system/main/shim/shim.cc
@@ -54,7 +54,3 @@ EXPORT_SYMBOL extern const module_t gd_shim_module = {.name = GD_SHIM_MODULE,
.shut_down = GeneralShutDown,
.clean_up = kUnusedModuleApi,
.dependencies = {kUnusedModuleDependencies}};
-
-bool bluetooth::shim::is_gd_stack_started_up() {
- return bluetooth::shim::Stack::GetInstance()->IsRunning();
-}
diff --git a/system/test/Android.bp b/system/test/Android.bp
index c5a3b0c2d6..595f148754 100644
--- a/system/test/Android.bp
+++ b/system/test/Android.bp
@@ -205,7 +205,6 @@ filegroup {
filegroup {
name: "TestMockMainShim",
srcs: [
- "mock/mock_main_shim.cc",
"mock/mock_main_shim_BtifConfigInterface.cc",
"mock/mock_main_shim_acl.cc",
"mock/mock_main_shim_acl_api.cc",
@@ -363,19 +362,11 @@ filegroup {
filegroup {
name: "TestMockMainShimLeScanning",
srcs: [
- "mock/mock_main_shim.cc",
"mock/mock_main_shim_le_scanning_manager.cc",
],
}
filegroup {
- name: "TestMockMainShimFlags",
- srcs: [
- "mock/mock_main_shim.cc",
- ],
-}
-
-filegroup {
name: "TestMockBtif",
srcs: [
":TestCommonCoreInterface",
diff --git a/system/test/mock/mock_main_shim.cc b/system/test/mock/mock_main_shim.cc
deleted file mode 100644
index 8e26aaeecd..0000000000
--- a/system/test/mock/mock_main_shim.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * Generated mock file from original source file
- * Functions generated:14
- */
-
-#define LOG_TAG "bt_shim"
-
-#include "main/shim/shim.h"
-#include "test/common/mock_functions.h"
-
-namespace test {
-namespace mock {
-bool bluetooth_shim_is_gd_stack_started_up = false;
-}
-} // namespace test
-bool bluetooth::shim::is_gd_stack_started_up() {
- inc_func_call_count(__func__);
- return test::mock::bluetooth_shim_is_gd_stack_started_up;
-}
diff --git a/system/test/mock/mock_main_shim_entry.cc b/system/test/mock/mock_main_shim_entry.cc
index 291cb0c0fd..a78ff5bdf5 100644
--- a/system/test/mock/mock_main_shim_entry.cc
+++ b/system/test/mock/mock_main_shim_entry.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "test/mock/mock_main_shim_entry.h"
+
#include "hci/acl_manager_mock.h"
#include "hci/controller_interface_mock.h"
#include "hci/distance_measurement_manager_mock.h"
@@ -22,9 +24,16 @@
#include "hci/le_scanning_manager_mock.h"
#include "lpp/lpp_offload_interface_mock.h"
#include "main/shim/entry.h"
+#include "main/shim/shim.h"
#include "os/handler.h"
#include "storage/storage_module.h"
+namespace test {
+namespace mock {
+bool bluetooth_shim_is_gd_stack_started_up = false;
+} // namespace mock
+} // namespace test
+
namespace bluetooth {
namespace hci {
namespace testing {
@@ -65,6 +74,7 @@ hci::RemoteNameRequestModule* GetRemoteNameRequest() { return nullptr; }
lpp::LppOffloadInterface* GetLppOffloadManager() {
return lpp::testing::mock_lpp_offload_interface_;
}
+bool is_gd_stack_started_up() { return test::mock::bluetooth_shim_is_gd_stack_started_up; }
} // namespace shim
} // namespace bluetooth