summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-03-10 14:02:53 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-10 14:02:53 -0700
commitd3ab34b581bae9eb2553685186d85e03419a5f52 (patch)
tree435aeca6859e8c46c363ad0ff28b20541caa7a23
parent18edfffeccc1235fe35e007178d9b7a0b1ce3088 (diff)
parent77803348720f0708a6e3743641b5e8f36d350be0 (diff)
Merge "add UT base for DistanceMeasurementManager" into main
-rw-r--r--system/gd/Android.bp1
-rw-r--r--system/gd/hal/ranging_hal_mock.h67
-rw-r--r--system/gd/hci/distance_measurement_manager_test.cc99
3 files changed, 167 insertions, 0 deletions
diff --git a/system/gd/Android.bp b/system/gd/Android.bp
index 35cbe8d217..26f31f0b8e 100644
--- a/system/gd/Android.bp
+++ b/system/gd/Android.bp
@@ -389,6 +389,7 @@ cc_test {
"hci/class_of_device_unittest.cc",
"hci/controller_test.cc",
"hci/controller_unittest.cc",
+ "hci/distance_measurement_manager_test.cc",
"hci/hci_layer_fake.cc",
"hci/hci_layer_test.cc",
"hci/hci_layer_unittest.cc",
diff --git a/system/gd/hal/ranging_hal_mock.h b/system/gd/hal/ranging_hal_mock.h
new file mode 100644
index 0000000000..328411353f
--- /dev/null
+++ b/system/gd/hal/ranging_hal_mock.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2025 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.
+ */
+
+#pragma once
+
+#include <gmock/gmock.h>
+#include <string>
+
+#include "hal/ranging_hal.h"
+
+namespace bluetooth {
+namespace hal {
+namespace testing {
+class MockRangingHal : public RangingHal {
+public:
+ MOCK_METHOD(bool, IsBound, ());
+ MOCK_METHOD(RangingHalVersion, GetRangingHalVersion, ());
+ MOCK_METHOD(std::vector<VendorSpecificCharacteristic>, GetVendorSpecificCharacteristics, ());
+ MOCK_METHOD(void, OpenSession,
+ (uint16_t connection_handle, uint16_t att_handle,
+ const std::vector<hal::VendorSpecificCharacteristic>& vendor_specific_data));
+ MOCK_METHOD(void, HandleVendorSpecificReply,
+ (uint16_t connection_handle,
+ const std::vector<hal::VendorSpecificCharacteristic>& vendor_specific_reply));
+ MOCK_METHOD(void, WriteRawData,
+ (uint16_t connection_handle, const ChannelSoundingRawData& raw_data));
+ MOCK_METHOD(void, UpdateChannelSoundingConfig,
+ (uint16_t connection_handle,
+ const hci::LeCsConfigCompleteView& leCsConfigCompleteView,
+ uint8_t local_supported_sw_time, uint8_t remote_supported_sw_time,
+ uint16_t conn_interval));
+ MOCK_METHOD(void, UpdateConnInterval, (uint16_t connection_handle, uint16_t conn_interval));
+ MOCK_METHOD(void, UpdateProcedureEnableConfig,
+ (uint16_t connection_handle,
+ const hci::LeCsProcedureEnableCompleteView& leCsProcedureEnableCompleteView));
+ MOCK_METHOD(void, WriteProcedureData,
+ (uint16_t connection_handle, hci::CsRole local_cs_role,
+ const ProcedureDataV2& procedure_data, uint16_t procedure_counter));
+ MOCK_METHOD(bool, IsAbortedProcedureRequired, (uint16_t connection_handle));
+
+ void RegisterCallback(RangingHalCallback* callback) override { ranging_hal_callback_ = callback; }
+ RangingHalCallback* GetRangingHalCallback() { return ranging_hal_callback_; }
+
+ void Start() override {}
+ void Stop() override {}
+ void ListDependencies(ModuleList* /*list*/) const override {}
+ std::string ToString() const override { return std::string("mock ranging hal"); }
+
+private:
+ RangingHalCallback* ranging_hal_callback_ = nullptr;
+};
+} // namespace testing
+} // namespace hal
+} // namespace bluetooth
diff --git a/system/gd/hci/distance_measurement_manager_test.cc b/system/gd/hci/distance_measurement_manager_test.cc
new file mode 100644
index 0000000000..b7f2abe8b3
--- /dev/null
+++ b/system/gd/hci/distance_measurement_manager_test.cc
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2025 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 "hci/distance_measurement_manager.h"
+
+#include <bluetooth/log.h>
+#include <flag_macros.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "hal/ranging_hal.h"
+#include "hal/ranging_hal_mock.h"
+#include "hci/acl_manager_mock.h"
+#include "hci/controller.h"
+#include "hci/controller_mock.h"
+#include "hci/hci_layer.h"
+#include "hci/hci_layer_fake.h"
+#include "module.h"
+
+using testing::Return;
+
+namespace bluetooth {
+namespace hci {
+namespace {
+class TestController : public testing::MockController {
+protected:
+ void Start() override {}
+ void Stop() override {}
+ void ListDependencies(ModuleList* /* list */) const override {}
+};
+
+class TestAclManager : public testing::MockAclManager {
+protected:
+ void Start() override {}
+ void Stop() override {}
+ void ListDependencies(ModuleList* /* list */) const override {}
+};
+
+class DistanceMeasurementManagerTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ test_hci_layer_ = new HciLayerFake; // Ownership is transferred to registry
+ mock_controller_ = new TestController; // Ownership is transferred to registry
+ mock_ranging_hal_ = new hal::testing::MockRangingHal; // Ownership is transferred to registry
+ mock_acl_manager_ = new TestAclManager; // Ownership is transferred to registry
+ fake_registry_.InjectTestModule(&hal::RangingHal::Factory, mock_ranging_hal_);
+ fake_registry_.InjectTestModule(&Controller::Factory, mock_controller_);
+ fake_registry_.InjectTestModule(&HciLayer::Factory, test_hci_layer_);
+ fake_registry_.InjectTestModule(&AclManager::Factory, mock_acl_manager_);
+
+ client_handler_ = fake_registry_.GetTestModuleHandler(&HciLayer::Factory);
+ ASSERT_NE(client_handler_, nullptr);
+
+ EXPECT_CALL(*mock_controller_, SupportsBleChannelSounding()).WillOnce(Return(true));
+ EXPECT_CALL(*mock_ranging_hal_, IsBound()).WillOnce(Return(true));
+
+ handler_ = fake_registry_.GetTestHandler();
+ dm_manager_ = fake_registry_.Start<DistanceMeasurementManager>(&thread_, handler_);
+ }
+
+ void TearDown() override {
+ fake_registry_.SynchronizeModuleHandler(&DistanceMeasurementManager::Factory,
+ std::chrono::milliseconds(20));
+ fake_registry_.StopAll();
+ }
+
+protected:
+ TestModuleRegistry fake_registry_;
+ HciLayerFake* test_hci_layer_ = nullptr;
+ TestController* mock_controller_ = nullptr;
+ TestAclManager* mock_acl_manager_ = nullptr;
+ hal::testing::MockRangingHal* mock_ranging_hal_ = nullptr;
+ os::Thread& thread_ = fake_registry_.GetTestThread();
+ os::Handler* client_handler_ = nullptr;
+ os::Handler* handler_ = nullptr;
+
+ DistanceMeasurementManager* dm_manager_ = nullptr;
+};
+
+TEST_F(DistanceMeasurementManagerTest, setup_teardown) {
+ EXPECT_NE(mock_ranging_hal_->GetRangingHalCallback(), nullptr);
+}
+
+} // namespace
+} // namespace hci
+} // namespace bluetooth