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

Commit f4a2b8eb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "legacy: Update hci command mocks for testing"

parents 8d1fd5f4 3a349d01
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -223,6 +223,7 @@ cc_test {
        ":TestMockBta",
        ":TestMockBtif",
        ":TestMockLegacyHciCommands",
        ":TestMockLegacyHciInterface",
        ":TestMockMainShimEntry",
        ":TestMockStack",
        "shim/acl_api.cc",
+4 −2
Original line number Diff line number Diff line
@@ -365,10 +365,10 @@ cc_test {
        ":TestMockBtif",
        ":TestMockCommon",
        ":TestMockDevice",
        ":TestMockLegacyHciCommands",
        ":TestMockMainShim",
        ":TestMockStackAcl",
        ":TestMockStackBtm",
        ":TestMockStackHcic",
        ":TestMockStackL2cap",
        ":TestMockStackMetrics",
        "smp/p_256_curvepara.cc",
@@ -794,12 +794,13 @@ cc_test {
        ":TestMockBta",
        ":TestMockBtif",
        ":TestMockDevice",
        ":TestMockLegacyHciCommands",
        ":TestMockLegacyHciInterface",
        ":TestMockMainBte",
        ":TestMockMainShim",
        ":TestMockStackBtu",
        ":TestMockStackGap",
        ":TestMockStackGatt",
        ":TestMockStackHcic",
        ":TestMockStackL2cap",
        ":TestMockStackSmp",
        "acl/acl.cc",
@@ -976,6 +977,7 @@ cc_test {
        ":TestMockStackAcl",
        ":TestMockStackBtm",
        ":TestMockStackL2cap",
        ":TestMockStackHcic",
        ":TestMockStackMetrics",
        ":TestMockStackSmp",
        "btu/btu_hcif.cc",
+19 −15
Original line number Diff line number Diff line
@@ -37,10 +37,10 @@
#include "stack/include/btm_client_interface.h"
#include "stack/include/hcidefs.h"
#include "stack/l2cap/l2c_int.h"
#include "test/mock/mock_hcic_hcicmds.h"
#include "test/mock/mock_stack_hcic_hcicmds.h"
#include "types/raw_address.h"

namespace mock = test::mock::hcic_hcicmds;
namespace mock = test::mock::stack_hcic_hcicmds;

extern tBTM_CB btm_cb;

@@ -163,26 +163,30 @@ TEST_F(StackBtmTest, change_packet_type) {
  uint64_t features = 0xffffffffffffffff;
  acl_process_supported_features(0x123, features);

  mock::btsnd_hcic_change_conn_type = {};
  uint16_t pkt_types = 0x55aa;
  btm_set_packet_types_from_address(bda, pkt_types);
  uint16_t handle{0};
  uint16_t packet_types{0};

  mock::btsnd_hcic_change_conn_type.body = [&handle, &packet_types](
                                               uint16_t h, uint16_t p) {
    handle = h;
    packet_types = p;
  };
  btm_set_packet_types_from_address(bda, 0x55aa);
  ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]);
  ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle);
  ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1),
            Hex16(mock::btsnd_hcic_change_conn_type.packet_types));
  ASSERT_EQ(0x123, handle);
  ASSERT_EQ(Hex16(0x4400 | HCI_PKT_TYPES_MASK_DM1), Hex16(packet_types));

  mock::btsnd_hcic_change_conn_type = {};
  btm_set_packet_types_from_address(bda, 0xffff);
  ASSERT_EQ(++cnt, mock_function_count_map["btsnd_hcic_change_conn_type"]);
  ASSERT_EQ(0x123, mock::btsnd_hcic_change_conn_type.handle);
  ASSERT_EQ(0x123, handle);
  ASSERT_EQ(Hex16(0xcc00 | HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1),
            Hex16(mock::btsnd_hcic_change_conn_type.packet_types));
            Hex16(packet_types));

  mock::btsnd_hcic_change_conn_type = {};
  btm_set_packet_types_from_address(bda, 0x0);
  // NOTE: The call should not be executed with no bits set
  ASSERT_EQ(0x0, mock::btsnd_hcic_change_conn_type.handle);
  ASSERT_EQ(Hex16(0x0), Hex16(mock::btsnd_hcic_change_conn_type.packet_types));
  ASSERT_EQ(0x123, handle);
  ASSERT_EQ(Hex16(0xcc18), Hex16(packet_types));

  mock::btsnd_hcic_change_conn_type = {};
  get_btm_client_interface().lifecycle.btm_free();
}

+14 −0
Original line number Diff line number Diff line
@@ -406,3 +406,17 @@ filegroup {
      "mock/mock_bluetooth_interface.cc",
  ],
}

filegroup {
  name: "TestMockStackHcic",
  srcs: [
      "mock/mock_stack_hcic*.cc",
  ],
}

filegroup {
  name: "TestMockLegacyHciInterface",
  srcs: [
      "mock/mock_legacy_hci_iterface.cc"
  ],
}
+66 −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 <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;
#define UNUSED_ATTR

#include <base/callback.h>
#include <stddef.h>

#include "bt_target.h"
#include "btu.h"
#include "hcimsgs.h"
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/bt_octets.h"
#include "types/raw_address.h"

namespace test {
namespace mock {
namespace hcic_hcicmds {

struct btsnd_hcic_change_conn_type {
  uint16_t handle{0};
  uint16_t packet_types{0};
} btsnd_hcic_change_conn_type;

}  // namespace hcic_hcicmds
}  // namespace mock
}  // namespace test

namespace mock = test::mock::hcic_hcicmds;

namespace {
void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
  mock_function_count_map[__func__]++;
}
void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) {
  mock_function_count_map[__func__]++;
}
}  // namespace

bluetooth::legacy::hci::Interface interface_ = {
    .Disconnect = btsnd_hcic_disconnect,
    .StartRoleSwitch = btsnd_hcic_switch_role,
    .ChangeConnectionPacketType = btsnd_hcic_change_conn_type,
};

const bluetooth::legacy::hci::Interface&
bluetooth::legacy::hci::GetInterface() {
  return interface_;
}
Loading