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

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

Introduce stack_btu_test

Towards testable code

Bug: 163134718
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines
No-Typo-Check: Legacy code mocks

Change-Id: I35fefd23efe47af881ae22765157c7e723973c10
parent 80d4ce85
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "bta/include/bta_ag_api.h"  // tBTA_AG_RES_DATA::kEmpty
#include "hci/include/hci_layer.h"   // hci_t
#include "test/mock/mock_hci_layer.h"

std::map<std::string, int> mock_function_count_map;

@@ -166,7 +167,6 @@ hci_t mock_hci = {
    .transmit_command_futured = transmit_command_futured,
    .transmit_downward = transmit_downward,
};
const hci_t* hci_layer_get_interface() { return &mock_hci; }

bool is_bluetooth_uid() { return false; }
const tBTA_AG_RES_DATA tBTA_AG_RES_DATA::kEmpty = {};
@@ -181,7 +181,10 @@ class BluetoothMetricsLogger {};

class StackCycleTest : public ::testing::Test {
 protected:
  void SetUp() override { stack_manager_ = stack_manager_get_interface(); }
  void SetUp() override {
    test::mock::hci_layer::hci_layer_get_interface.hci = &mock_hci;
    stack_manager_ = stack_manager_get_interface();
  }

  void TearDown() override { stack_manager_ = nullptr; }
  const stack_manager_t* stack_manager_{nullptr};
+58 −0
Original line number Diff line number Diff line
@@ -853,3 +853,61 @@ cc_test {
        },
    },
}

cc_test {
    name: "net_test_stack_btu",
    test_suites: ["device-tests"],
    host_supported: true,
    defaults: ["fluoride_defaults"],
    local_include_dirs: [
        "include",
        "test/common",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
    ],
    generated_headers: [
        "BluetoothGeneratedBundlerSchema_h_bfbs",
        "BluetoothGeneratedDumpsysDataSchema_h",
        "BluetoothGeneratedPackets_h",
    ],
    srcs: [
        ":TestMockBta",
        ":TestMockBtif",
        ":TestMockHci",
        ":TestMockLegacyHciCommands",
        ":TestMockMainShim",
        ":TestMockStackAcl",
        ":TestMockStackSmp",
        ":TestStackBtm",
        ":TestStackL2cap",
        ":TestMockStackMetrics",
        "btu/btu_hcif.cc",
        "btu/btu_task.cc",
        "test/stack_btu_test.cc",
    ],
    static_libs: [
        "libbt-common",
        "libbt-protos-lite",
        "libbtdevice",
        "libgmock",
        "liblog",
        "libosi",
    ],
    shared_libs: [
        "libcrypto",
        "libprotobuf-cpp-lite",
        "libflatbuffers-cpp",
    ],
    sanitize: {
        address: true,
        all_undefined: true,
        cfi: true,
        integer_overflow: true,
        scs: true,
        diag: {
            undefined : true
        },
    },
}
+3 −2
Original line number Diff line number Diff line
@@ -110,8 +110,9 @@ bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
static void do_post_on_bt_main(BtMainClosure closure) { closure(); }

void post_on_bt_main(BtMainClosure closure) {
  ASSERT(do_in_main_thread(FROM_HERE,
                           base::Bind(do_post_on_bt_main, std::move(closure))));
  ASSERT(do_in_main_thread(
             FROM_HERE, base::Bind(do_post_on_bt_main, std::move(closure))) ==
         BT_STATUS_SUCCESS);
}

void main_thread_start_up() {
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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 <gtest/gtest.h>
#include <cstdint>
#include <map>
#include <string>

#include "stack/include/btu.h"

std::map<std::string, int> mock_function_count_map;

void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {}

class StackBtuTest : public ::testing::Test {};

TEST_F(StackBtuTest, post_on_main) {}
+14 −0
Original line number Diff line number Diff line
@@ -151,3 +151,17 @@ filegroup {
      "mock/mock_stack_acl*.cc",
  ],
}

filegroup {
  name: "TestMockStackSmp",
  srcs: [
      "mock/mock_stack_smp*.cc",
  ],
}

filegroup {
  name: "TestMockStackMetrics",
  srcs: [
      "mock/mock_stack_metrics*.cc",
  ],
}
Loading