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

Commit 8fd01539 authored by Myles Watson's avatar Myles Watson
Browse files

Add SetMock for legacy hci mock injection

If the mock isn't destroyed, the expectations are not verified.

Bug: 301661850
Test: atest net_test_stack_btm
Flag: Exempt, test infrastructure change
Change-Id: I9db7d0490a0a3b66e454628711d98cf115b3c7b9
parent 42cf9beb
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ class CodecManagerTestBase : public Test {
        .WillByDefault(Return(true));

    controller::SetMockControllerInterface(&controller_interface);
    Mock::VerifyAndClearExpectations(&bluetooth::legacy::hci::testing::GetMock());
    bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);

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

    Mock::VerifyAndClearExpectations(&bluetooth::legacy::hci::testing::GetMock());
    controller::SetMockControllerInterface(nullptr);
  }

  NiceMock<controller::MockControllerInterface> controller_interface;
  CodecManager* codec_manager;
  bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
};

/*----------------- ADSP codec manager tests ------------------*/
@@ -121,21 +121,21 @@ TEST_F(CodecManagerTestAdsp, test_init) {
}

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

  // Verify data path is reset on Stop()
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
  EXPECT_CALL(legacy_hci_mock_,
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathHci, _))
      .Times(1);
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
  EXPECT_CALL(legacy_hci_mock_,
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathHci, _))
      .Times(1);
@@ -343,21 +343,21 @@ TEST_F(CodecManagerTestHost, test_init) {
}

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

  // Verify data path is NOT reset on Stop() for the Host encoding session
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
  EXPECT_CALL(legacy_hci_mock_,
              ConfigureDataPath(hci_data_direction_t::HOST_TO_CONTROLLER,
                                kIsoDataPathHci, _))
      .Times(0);
  EXPECT_CALL(bluetooth::legacy::hci::testing::GetMock(),
  EXPECT_CALL(legacy_hci_mock_,
              ConfigureDataPath(hci_data_direction_t::CONTROLLER_TO_HOST,
                                kIsoDataPathHci, _))
      .Times(0);
+8 −11
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ class StackBtmWithQueuesTest : public StackBtmTest {
    down_handler_ = new bluetooth::os::Handler(down_thread_);
    bluetooth::hci::testing::mock_hci_layer_ = &mock_hci_;
    bluetooth::hci::testing::mock_gd_shim_handler_ = up_handler_;
    bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);
  }
  void TearDown() override {
    up_handler_->Clear();
@@ -93,6 +94,7 @@ class StackBtmWithQueuesTest : public StackBtmTest {
                               bluetooth::hci::ScoBuilder>
      sco_queue_{10};
  bluetooth::hci::testing::MockHciLayer mock_hci_;
  bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
  bluetooth::os::Thread* up_thread_;
  bluetooth::os::Handler* up_handler_;
  bluetooth::os::Thread* down_thread_;
@@ -199,20 +201,15 @@ TEST_F(StackBtmWithQueuesTest, change_packet_type) {
  uint64_t features = 0xffffffffffffffff;
  acl_process_supported_features(0x123, features);

  EXPECT_CALL(
      bluetooth::legacy::hci::testing::GetMock(),
      ChangeConnectionPacketType(handle, 0x4400 | HCI_PKT_TYPES_MASK_DM1));
  EXPECT_CALL(
      bluetooth::legacy::hci::testing::GetMock(),
      ChangeConnectionPacketType(
          handle, (0xcc00 | HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1)));
  EXPECT_CALL(
      bluetooth::legacy::hci::testing::GetMock(),
      ChangeConnectionPacketType(
          handle, (0xcc00 | HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1)));
  EXPECT_CALL(legacy_hci_mock_, ChangeConnectionPacketType(
                                    handle, 0x4400 | HCI_PKT_TYPES_MASK_DM1));
  EXPECT_CALL(legacy_hci_mock_, ChangeConnectionPacketType(
                                    handle, (0xcc00 | HCI_PKT_TYPES_MASK_DM1 |
                                             HCI_PKT_TYPES_MASK_DH1)));

  btm_set_packet_types_from_address(bda, 0x55aa);
  btm_set_packet_types_from_address(bda, 0xffff);
  // Illegal mask, won't be sent.
  btm_set_packet_types_from_address(bda, 0x0);

  get_btm_client_interface().lifecycle.btm_free();
+3 −3
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@

namespace bluetooth::legacy::hci {
namespace testing {
MockInterface interface_;
MockInterface& GetMock() { return interface_; }
const MockInterface* interface_;
void SetMock(const MockInterface& mock) { interface_ = &mock; }
}  // namespace testing
const Interface& GetInterface() { return testing::interface_; }
const Interface& GetInterface() { return *testing::interface_; }
}  // namespace bluetooth::legacy::hci
+3 −5
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@

#include "stack/include/hcimsgs.h"

namespace bluetooth::legacy::hci {
namespace bluetooth::legacy::hci::testing {
class MockInterface : public Interface {
 public:
  MOCK_METHOD(void, StartInquiry,
@@ -37,7 +37,5 @@ class MockInterface : public Interface {
               std::vector<uint8_t> vendor_config),
              (const));
};
namespace testing {
bluetooth::legacy::hci::MockInterface& GetMock();
}
}  // namespace bluetooth::legacy::hci
 No newline at end of file
void SetMock(const MockInterface& interface);
}  // namespace bluetooth::legacy::hci::testing