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

Commit b667ce84 authored by Chris Manton's avatar Chris Manton
Browse files

Prefer fake OSI over libosi

Bug: 283886636
Test: bt_host_test_bta
Test: atest net_test_bta

Change-Id: I08f96532a9662b1f853533fb2d87e8d3b7fafa6d
parent 80b40ddf
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ cc_test {
        ":LegacyStackSdp",
        ":TestCommonLogMsg",
        ":TestCommonMockFunctions",
        ":TestFakeOsi",
        ":TestMockBtif",
        ":TestMockMainShim",
        ":TestMockStackBtm",
@@ -237,7 +238,6 @@ cc_test {
        "libchrome",
        "libcom.android.sysprop.bluetooth",
        "libgmock",
        "libosi",
    ],
    data: [
        ":audio_set_configurations_bfbs",
@@ -302,16 +302,31 @@ cc_test {
        "BluetoothGeneratedPackets_h",
    ],
    srcs: [
        ":LegacyStackSdp",
        ":OsiCompatSources",
        ":TestCommonLogMsg",
        ":TestCommonMainHandler",
        ":TestCommonMockFunctions",
        ":TestFakeOsi",
        ":TestMockBtaSdp",
        ":TestMockBtif",
        ":TestMockDevice",
        ":TestMockMainShim",
        ":TestMockOsi",
        ":TestMockStack",
        ":TestMockSrvcDis",
        ":TestMockStackA2dp",
        ":TestMockStackAcl",
        ":TestMockStackAvct",
        ":TestMockStackAvdt",
        ":TestMockStackAvrc",
        ":TestMockStackBtm",
        ":TestMockStackCryptotoolbox",
        ":TestMockStackGap",
        ":TestMockStackGatt",
        ":TestMockStackHid",
        ":TestMockStackL2cap",
        ":TestMockStackMetrics",
        ":TestMockStackPan",
        ":TestMockStackRfcomm",
        "ar/bta_ar.cc",
        "av/bta_av_aact.cc",
        "av/bta_av_act.cc",
+8 −1
Original line number Diff line number Diff line
@@ -18,15 +18,22 @@

#include <gtest/gtest.h>

#include <memory>

#include "bta/dm/bta_dm_int.h"
#include "stack/include/bt_hdr.h"
#include "test/fake/fake_osi.h"
#include "types/bluetooth/uuid.h"

using bluetooth::Uuid;

class BtaCustUuid : public testing::Test {
 protected:
  void SetUp() override { bta_dm_cb = {}; }
  void SetUp() override {
    fake_osi_ = std::make_unique<test::fake::FakeOsi>();
    bta_dm_cb = {};
  }
  std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};

namespace {
+5 −29
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <gtest/gtest.h>

#include <chrono>
#include <memory>

#include "bta/dm/bta_dm_int.h"
#include "bta/hf_client/bta_hf_client_int.h"
@@ -31,6 +32,7 @@
#include "stack/include/btm_status.h"
#include "test/common/main_handler.h"
#include "test/common/mock_functions.h"
#include "test/fake/fake_osi.h"
#include "test/mock/mock_osi_alarm.h"
#include "test/mock/mock_osi_allocator.h"
#include "test/mock/mock_stack_acl.h"
@@ -63,33 +65,12 @@ const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute,

}  // namespace

struct alarm_t {
  alarm_t(const char* name){};
  int any_value;
};

class BtaDmTest : public testing::Test {
 protected:
  void SetUp() override {
    reset_mock_function_count_map();
    bluetooth::common::InitFlags::Load(test_flags);
    test::mock::osi_alarm::alarm_new.body = [](const char* name) -> alarm_t* {
      return new alarm_t(name);
    };
    test::mock::osi_alarm::alarm_free.body = [](alarm_t* alarm) {
      delete alarm;
    };
    test::mock::osi_allocator::osi_malloc.body = [](size_t size) {
      return malloc(size);
    };
    test::mock::osi_allocator::osi_calloc.body = [](size_t size) {
      return calloc(1UL, size);
    };
    test::mock::osi_allocator::osi_free.body = [](void* ptr) { free(ptr); };
    test::mock::osi_allocator::osi_free_and_reset.body = [](void** ptr) {
      free(*ptr);
      *ptr = nullptr;
    };
    fake_osi_ = std::make_unique<test::fake::FakeOsi>();

    main_thread_start_up();
    post_on_bt_main([]() { LOG_INFO("Main thread started up"); });
@@ -108,14 +89,9 @@ class BtaDmTest : public testing::Test {
    bta_dm_deinit_cb();
    post_on_bt_main([]() { LOG_INFO("Main thread shutting down"); });
    main_thread_shut_down();

    test::mock::osi_alarm::alarm_new = {};
    test::mock::osi_alarm::alarm_free = {};
    test::mock::osi_allocator::osi_malloc = {};
    test::mock::osi_allocator::osi_calloc = {};
    test::mock::osi_allocator::osi_free = {};
    test::mock::osi_allocator::osi_free_and_reset = {};
  }

  std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};

TEST_F(BtaDmTest, nop) {
+5 −6
Original line number Diff line number Diff line
@@ -19,19 +19,18 @@
#include <base/logging.h>
#include <gtest/gtest.h>

#include <memory>

#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_hf_client_api.h"
#include "types/bluetooth/uuid.h"

static uint16_t gVersion;
#include "test/fake/fake_osi.h"

class BtaHfClientAddRecordTest : public ::testing::Test {
 protected:
  void SetUp() override {
    gVersion = 0;
  }
  void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); }

  void TearDown() override {}
  std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};

TEST_F(BtaHfClientAddRecordTest, test_hf_client_add_record) {
+5 −0
Original line number Diff line number Diff line
@@ -18,9 +18,12 @@

#include <gtest/gtest.h>

#include <memory>

#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_hf_client_api.h"
#include "common/message_loop_thread.h"
#include "test/fake/fake_osi.h"
#include "types/raw_address.h"

namespace base {
@@ -37,10 +40,12 @@ const RawAddress bdaddr2({0x66, 0x55, 0x44, 0x33, 0x22, 0x11});
class BtaHfClientTest : public testing::Test {
 protected:
  void SetUp() override {
    fake_osi_ = std::make_unique<test::fake::FakeOsi>();
    // Reset the memory block, this is the state on which the allocate handle
    // would start operating
    bta_hf_client_cb_arr_init();
  }
  std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};

// Test that when we can allocate a device on the block and then check
Loading