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

Commit 69c41d84 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge changes I77b854c0,I0b30c06b

* changes:
  bta/test: Add controller mocks
  bt/test: Extend BTM mocks
parents f2289db8 44da55c0
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -44,7 +44,34 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
                                      p_ref_data, sec_act);
}

bool BTM_IsPhy2mSupported(const RawAddress& remote_bda,
                          tBT_TRANSPORT transport) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->IsPhy2mSupported(remote_bda, transport);
}

uint8_t BTM_GetPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->GetPeerSCA(remote_bda, transport);
}

void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
                   uint16_t phy_options) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  btm_interface->BleSetPhy(bd_addr, tx_phys, rx_phys, phy_options);
}

bool BTM_SecIsSecurityPending(const RawAddress& bd_addr) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->SecIsSecurityPending(bd_addr);
}

tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->FindDevice(bd_addr);
}

void BTM_RequestPeerSCA(RawAddress const& bd_addr, tBT_TRANSPORT transport) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  btm_interface->RequestPeerSCA(bd_addr, transport);
}
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
@@ -37,6 +37,15 @@ class BtmInterface {
                                    void* p_ref_data,
                                    tBTM_BLE_SEC_ACT sec_act) = 0;
  virtual tBTM_SEC_DEV_REC* FindDevice(const RawAddress& bd_addr) = 0;
  virtual bool IsPhy2mSupported(const RawAddress& remote_bda,
                                tBT_TRANSPORT transport) = 0;
  virtual uint8_t GetPeerSCA(const RawAddress& remote_bda,
                             tBT_TRANSPORT transport) = 0;
  virtual void BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys,
                         uint8_t rx_phys, uint16_t phy_options) = 0;
  virtual bool SecIsSecurityPending(const RawAddress& bd_addr) = 0;
  virtual void RequestPeerSCA(RawAddress const& bd_addr,
                              tBT_TRANSPORT transport) = 0;
  virtual ~BtmInterface() = default;
};

@@ -55,6 +64,20 @@ class MockBtmInterface : public BtmInterface {
              (override));
  MOCK_METHOD((tBTM_SEC_DEV_REC*), FindDevice, (const RawAddress& bd_addr),
              (override));
  MOCK_METHOD((bool), IsPhy2mSupported,
              (const RawAddress& remote_bda, tBT_TRANSPORT transport),
              (override));
  MOCK_METHOD((uint8_t), GetPeerSCA,
              (const RawAddress& remote_bda, tBT_TRANSPORT transport),
              (override));
  MOCK_METHOD((void), BleSetPhy,
              (const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
               uint16_t phy_options),
              (override));
  MOCK_METHOD((bool), SecIsSecurityPending, (const RawAddress& bd_addr),
              (override));
  MOCK_METHOD((void), RequestPeerSCA,
              (RawAddress const& bd_addr, tBT_TRANSPORT transport), (override));
};

/**
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.dk.
 * Represented by EHIMA - www.ehima.com
 *
 * 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 "mock_controller.h"

#include "device/include/controller.h"

static controller::MockControllerInterface* controller_interface = nullptr;

void controller::SetMockControllerInterface(
    MockControllerInterface* interface) {
  controller_interface = interface;
}

uint16_t get_iso_data_size(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->GetIsoDataSize();
}

uint8_t get_iso_buffer_count(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->GetIsoBufferCount();
}

bool supports_ble_isochronous_broadcaster(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBleIsochronousBroadcaster();
}

bool supports_ble_2m_phy(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBle2mPhy();
}

bool supports_ble_connected_isochronous_stream_central(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBleConnectedIsochronousStreamCentral();
}

bool supports_ble_connected_isochronous_stream_peripheral(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface
      ->SupportsBleConnectedIsochronousStreamPeripheral();
}

const controller_t* controller_get_interface() {
  static controller_t* controller_instance = new controller_t();

  controller_instance->get_iso_data_size = &get_iso_data_size;
  controller_instance->get_iso_buffer_count = &get_iso_buffer_count;
  controller_instance->supports_ble_isochronous_broadcaster =
      &supports_ble_isochronous_broadcaster;
  controller_instance->supports_ble_2m_phy = &supports_ble_2m_phy;
  controller_instance->supports_ble_connected_isochronous_stream_central =
      &supports_ble_connected_isochronous_stream_central;
  controller_instance->supports_ble_connected_isochronous_stream_peripheral =
      &supports_ble_connected_isochronous_stream_peripheral;

  return controller_instance;
}
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.dk.
 * Represented by EHIMA - www.ehima.com
 *
 * 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 <base/callback.h>
#include <gmock/gmock.h>

#include "hcimsgs.h"

namespace controller {
class ControllerInterface {
 public:
  virtual uint8_t GetIsoBufferCount(void) = 0;
  virtual uint16_t GetIsoDataSize(void) = 0;
  virtual bool SupportsBleConnectedIsochronousStreamCentral(void) = 0;
  virtual bool SupportsBleConnectedIsochronousStreamPeripheral(void) = 0;
  virtual bool SupportsBleIsochronousBroadcaster(void) = 0;
  virtual bool SupportsBle2mPhy(void) = 0;

  virtual ~ControllerInterface() = default;
};

class MockControllerInterface : public ControllerInterface {
 public:
  MOCK_METHOD((uint8_t), GetIsoBufferCount, (), (override));
  MOCK_METHOD((uint16_t), GetIsoDataSize, (), (override));
  MOCK_METHOD((bool), SupportsBleConnectedIsochronousStreamCentral, (),
              (override));
  MOCK_METHOD((bool), SupportsBleConnectedIsochronousStreamPeripheral, (),
              (override));
  MOCK_METHOD((bool), SupportsBleIsochronousBroadcaster, (), (override));
  MOCK_METHOD((bool), SupportsBle2mPhy, (), (override));
};

void SetMockControllerInterface(
    MockControllerInterface* mock_controller_interface);
}  // namespace controller
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback) {
  return BTM_SUCCESS;
}
void BTM_BleBackgroundObserve(bool enable, tBTM_INQ_RESULTS_CB* p_results_cb) {}
void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback) {}
uint8_t BTM_GetAcceptlistSize() { return 0; }