Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa4d70f1 authored by Myles Watson's avatar Myles Watson
Browse files

Move ConfigureDataPath out of ACL

Remove from ACL, since it has to do with SCO and ISO.

Use Gmock for the interface.

Update tests.

Bug: 304830775
Test: mma -j32
Change-Id: I1111fac4e90aa2137112a312ac524a74873a4ee8
parent dad41504
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -831,12 +831,12 @@ cc_test {
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockBtaLeAudioHalVerifier",
        ":TestMockLegacyHciInterface",
        ":TestStubOsi",
        "le_audio/codec_manager.cc",
        "le_audio/codec_manager_test.cc",
        "le_audio/le_audio_set_configuration_provider_json.cc",
        "le_audio/le_audio_types.cc",
        "test/common/btm_api_mock.cc",
        "test/common/mock_controller.cc",
    ],
    data: [
+10 −10
Original line number Diff line number Diff line
@@ -22,13 +22,13 @@
#include "le_audio_set_configuration_provider.h"
#include "osi/include/log.h"
#include "osi/include/properties.h"
#include "stack/acl/acl.h"
#include "stack/include/acl_api.h"
#include "stack/include/hcimsgs.h"

namespace {

using bluetooth::hci::iso_manager::kIsoDataPathHci;
using bluetooth::hci::iso_manager::kIsoDataPathPlatformDefault;
using bluetooth::legacy::hci::GetInterface;
using le_audio::CodecManager;
using le_audio::types::CodecLocation;

@@ -105,9 +105,9 @@ struct codec_manager_impl {
    }

    LOG_INFO("LeAudioCodecManagerImpl: configure_data_path for encode");
    btm_configure_data_path(btm_data_direction::HOST_TO_CONTROLLER,
    GetInterface().ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                     kIsoDataPathPlatformDefault, {});
    btm_configure_data_path(btm_data_direction::CONTROLLER_TO_HOST,
    GetInterface().ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                     kIsoDataPathPlatformDefault, {});
    SetCodecLocation(CodecLocation::ADSP);
  }
@@ -118,9 +118,9 @@ struct codec_manager_impl {
  }
  ~codec_manager_impl() {
    if (GetCodecLocation() != CodecLocation::HOST) {
      btm_configure_data_path(btm_data_direction::HOST_TO_CONTROLLER,
      GetInterface().ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                       kIsoDataPathHci, {});
      btm_configure_data_path(btm_data_direction::CONTROLLER_TO_HOST,
      GetInterface().ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                       kIsoDataPathHci, {});
    }
    le_audio::AudioSetConfigurationProvider::Cleanup();
+29 −36
Original line number Diff line number Diff line
@@ -19,11 +19,9 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "btm_api_mock.h"
#include "gd/common/init_flags.h"
#include "mock_controller.h"
#include "osi/include/properties.h"
#include "stack/acl/acl.h"
#include "test/mock/mock_legacy_hci_interface.h"

using ::testing::_;
using ::testing::Mock;
@@ -82,7 +80,6 @@ class CodecManagerTestBase : public Test {
        .WillByDefault(Return(true));

    controller::SetMockControllerInterface(&controller_interface);
    bluetooth::manager::SetMockBtmInterface(&btm_interface);

    codec_manager = CodecManager::GetInstance();
  }
@@ -90,11 +87,9 @@ class CodecManagerTestBase : public Test {
  virtual void TearDown() override {
    codec_manager->Stop();

    bluetooth::manager::SetMockBtmInterface(nullptr);
    controller::SetMockControllerInterface(nullptr);
  }

  NiceMock<bluetooth::manager::MockBtmInterface> btm_interface;
  NiceMock<controller::MockControllerInterface> controller_interface;
  CodecManager* codec_manager;
};
@@ -116,31 +111,30 @@ TEST_F(CodecManagerTestAdsp, test_init) {
}

TEST_F(CodecManagerTestAdsp, test_start) {
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::HOST_TO_CONTROLLER,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathPlatformDefault, _))
      .Times(1);
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::CONTROLLER_TO_HOST,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathPlatformDefault, _))
      .Times(1);

  const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
      offloading_preference(0);
  codec_manager->Start(offloading_preference);
  Mock::VerifyAndClearExpectations(&btm_interface);

  ASSERT_EQ(codec_manager->GetCodecLocation(), CodecLocation::ADSP);

  // Verify data path is reset on Stop()
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::HOST_TO_CONTROLLER,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathHci, _))
      .Times(1);
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::CONTROLLER_TO_HOST,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathHci, _))
      .Times(1);

  const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
      offloading_preference(0);
  codec_manager->Start(offloading_preference);

  ASSERT_EQ(codec_manager->GetCodecLocation(), CodecLocation::ADSP);
}

TEST_F(CodecManagerTestAdsp, testStreamConfigurationAdspDownMix) {
@@ -297,31 +291,30 @@ TEST_F(CodecManagerTestHost, test_init) {
}

TEST_F(CodecManagerTestHost, test_start) {
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::HOST_TO_CONTROLLER,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathPlatformDefault, _))
      .Times(0);
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::CONTROLLER_TO_HOST,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathPlatformDefault, _))
      .Times(0);

  const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
      offloading_preference(0);
  codec_manager->Start(offloading_preference);
  Mock::VerifyAndClearExpectations(&btm_interface);

  ASSERT_EQ(codec_manager->GetCodecLocation(), CodecLocation::HOST);

  // Verify data path is NOT reset on Stop() for the Host encoding session
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::HOST_TO_CONTROLLER,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathHci, _))
      .Times(0);
  EXPECT_CALL(btm_interface,
              ConfigureDataPath(btm_data_direction::CONTROLLER_TO_HOST,
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathHci, _))
      .Times(0);

  const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
      offloading_preference(0);
  codec_manager->Start(offloading_preference);

  ASSERT_EQ(codec_manager->GetCodecLocation(), CodecLocation::HOST);
}

}  // namespace
+0 −6
Original line number Diff line number Diff line
@@ -95,12 +95,6 @@ void acl_disconnect_from_handle(uint16_t handle, tHCI_STATUS reason,
  return btm_interface->AclDisconnectFromHandle(handle, reason);
}

void btm_configure_data_path(uint8_t direction, uint8_t path_id,
                             std::vector<uint8_t> vendor_config) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->ConfigureDataPath(direction, path_id, vendor_config);
}

tBTM_INQ_INFO* BTM_InqDbFirst(void) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->BTM_InqDbFirst();
+0 −6
Original line number Diff line number Diff line
@@ -52,8 +52,6 @@ class BtmInterface {
  virtual uint16_t GetHCIConnHandle(RawAddress const& bd_addr,
                                    tBT_TRANSPORT transport) = 0;
  virtual void AclDisconnectFromHandle(uint16_t handle, tHCI_STATUS reason) = 0;
  virtual void ConfigureDataPath(uint8_t direction, uint8_t path_id,
                                 std::vector<uint8_t> vendor_config) = 0;
  virtual tBTM_INQ_INFO* BTM_InqDbFirst() = 0;
  virtual tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) = 0;
  virtual ~BtmInterface() = default;
@@ -94,10 +92,6 @@ class MockBtmInterface : public BtmInterface {
              (RawAddress const& bd_addr, tBT_TRANSPORT transport), (override));
  MOCK_METHOD((void), AclDisconnectFromHandle,
              (uint16_t handle, tHCI_STATUS reason), (override));
  MOCK_METHOD((void), ConfigureDataPath,
              (uint8_t direction, uint8_t path_id,
               std::vector<uint8_t> vendor_config),
              (override));
  MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbFirst, (), (override));
  MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbNext, (tBTM_INQ_INFO * p_cur),
              (override));
Loading