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

Commit 211f6489 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "system/stack/test: Migrate to libbluetooth_log" into main

parents 7de74ab2 c8f733af
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "stack/include/a2dp_aac.h"

#include <base/logging.h>
#include <bluetooth/log.h>
#include <gtest/gtest.h>
#include <stdio.h>

@@ -177,7 +178,7 @@ TEST_F(A2dpAacTest, a2dp_enqueue_cb_is_invoked) {
    return len;
  };
  auto enqueue_cb = +[](BT_HDR* p_buf, size_t frames_n, uint32_t len) -> bool {
    LOG_INFO("%s", kEnqueueCallbackIsInvoked);
    log::info("{}", kEnqueueCallbackIsInvoked);
    osi_free(p_buf);
    return false;
  };
@@ -202,7 +203,7 @@ TEST_F(A2dpAacTest, decoded_data_cb_not_invoked_when_empty_packet) {
TEST_F(A2dpAacTest, decoded_data_cb_invoked) {
  log_capture_ = std::make_unique<LogCapture>();
  auto data_cb = +[](uint8_t* p_buf, uint32_t len) {
    LOG_INFO("%s", kDecodedDataCallbackIsInvoked);
    log::info("{}", kDecodedDataCallbackIsInvoked);
  };
  InitializeDecoder(data_cb);

@@ -214,7 +215,7 @@ TEST_F(A2dpAacTest, decoded_data_cb_invoked) {
  };
  auto enqueue_cb = +[](BT_HDR* p_buf, size_t frames_n, uint32_t len) -> bool {
    packet = p_buf;
    LOG_INFO("%s", kEnqueueCallbackIsInvoked);
    log::info("{}", kEnqueueCallbackIsInvoked);
    return false;
  };
  InitializeEncoder(true, read_cb, enqueue_cb);
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "mock_l2cap_layer.h"

#include <base/logging.h>
#include <bluetooth/log.h>

#include "stack/include/bt_hdr.h"
#include "stack/l2cap/l2c_int.h"
@@ -38,7 +39,7 @@ uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                       bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
                       uint16_t my_mtu, uint16_t required_remote_mtu,
                       uint16_t sec_level) {
  VLOG(1) << __func__ << ": psm=" << psm << ", enable_snoop=" << enable_snoop;
  bluetooth::log::verbose("psm={}, enable_snoop={}", psm, enable_snoop);
  return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info);
}

+3 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 * limitations under the License.
 */

#include <bluetooth/log.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>

@@ -44,6 +45,7 @@ using testing::StrictMock;

using bluetooth::eatt::EattChannel;
using bluetooth::eatt::EattChannelState;
using namespace bluetooth;

#define BLE_GATT_SVR_SUP_FEAT_EATT_BITMASK 0x01

@@ -54,7 +56,7 @@ void gatt_consolidate(const RawAddress& identity_addr, const RawAddress& rpa) {}
void gatt_data_process(tGATT_TCB& tcb, uint16_t cid, BT_HDR* p_buf) { return; }
tGATT_TCB* gatt_find_tcb_by_addr(const RawAddress& bda,
                                 tBT_TRANSPORT transport) {
  LOG(INFO) << __func__;
  log::info("");
  return &test_tcb;
}

+39 −36
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
 ******************************************************************************/

#include <base/logging.h>
#include <bluetooth/log.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>

@@ -33,6 +34,8 @@
#include "stack_test_packet_utils.h"
#include "types/raw_address.h"

using namespace bluetooth;

std::string DumpByteBufferToString(uint8_t* p_data, size_t len) {
  std::stringstream str;
  str.setf(std::ios_base::hex, std::ios::basefield);
@@ -133,7 +136,7 @@ class StackRfcommTest : public Test {
                       tPORT_CALLBACK* management_callback,
                       tPORT_CALLBACK* event_callback,
                       uint16_t* server_handle) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    ASSERT_EQ(RFCOMM_CreateConnectionWithSecurity(
                  uuid, scn, true, mtu, RawAddress::kAny, server_handle,
                  management_callback, 0),
@@ -145,7 +148,7 @@ class StackRfcommTest : public Test {

  void ConnectServerL2cap(const RawAddress& peer_addr, uint16_t acl_handle,
                          uint16_t lcid) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    // Remote device connect to this channel, we shall accept
    static const uint8_t cmd_id = 0x07;
    EXPECT_CALL(l2cap_interface_,
@@ -157,19 +160,19 @@ class StackRfcommTest : public Test {
    l2cap_appl_info_.pL2CA_ConnectInd_Cb(peer_addr, lcid, BT_PSM_RFCOMM,
                                         cmd_id);

    VLOG(1) << "Step 2";
    log::verbose("Step 2");
    // MTU configuration is done
    cfg_req.mtu_present = false;
    l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, L2CAP_CFG_OK, {});

    VLOG(1) << "Step 3";
    log::verbose("Step 3");
    // Remote device also ask to configure MTU size
    EXPECT_CALL(l2cap_interface_,
                ConfigResponse(lcid, PointerMemoryEqual(&cfg_req)))
        .WillOnce(Return(true));
    l2cap_appl_info_.pL2CA_ConfigInd_Cb(lcid, &cfg_req);

    VLOG(1) << "Step 4";
    log::verbose("Step 4");
    // Remote device connect to server channel 0
    BT_HDR* sabm_channel_0 = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickSabmPacket(RFCOMM_MX_DLCI, lcid, acl_handle));
@@ -185,7 +188,7 @@ class StackRfcommTest : public Test {
  void ConnectServerPort(const RawAddress& peer_addr, uint16_t port_handle,
                         uint8_t scn, uint16_t mtu, uint16_t acl_handle,
                         uint16_t lcid, int port_callback_index) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    // Negotiate parameters on scn
    BT_HDR* uih_pn_cmd_from_peer = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickPnPacket(true, GetDlci(false, scn), true, mtu,
@@ -202,7 +205,7 @@ class StackRfcommTest : public Test {
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, uih_pn_cmd_from_peer);
    osi_free(uih_pn_rsp_to_peer);

    VLOG(1) << "Step 2";
    log::verbose("Step 2");
    // Remote device connect to scn
    tBTM_SEC_CALLBACK* security_callback = nullptr;
    void* p_port = nullptr;
@@ -217,7 +220,7 @@ class StackRfcommTest : public Test {
    // sabm_channel_dlci should be freed by this method
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, sabm_channel_dlci);

    VLOG(1) << "Step 3";
    log::verbose("Step 3");
    // Confirm security check should trigger port as connected
    EXPECT_CALL(
        rfcomm_callback_,
@@ -230,7 +233,7 @@ class StackRfcommTest : public Test {
    security_callback(&peer_addr, BT_TRANSPORT_BR_EDR, p_port, BTM_SUCCESS);
    osi_free(ua_channel_dlci);

    VLOG(1) << "Step 4";
    log::verbose("Step 4");
    // Remote also need to configure its modem signal before we can send data
    BT_HDR* uih_msc_cmd_from_peer = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickMscPacket(true, GetDlci(false, scn), lcid, acl_handle, true,
@@ -252,7 +255,7 @@ class StackRfcommTest : public Test {
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, uih_msc_cmd_from_peer);
    osi_free(uih_msc_response_to_peer);

    VLOG(1) << "Step 5";
    log::verbose("Step 5");
    // modem configuration is done
    BT_HDR* uih_msc_response_from_peer = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickMscPacket(true, GetDlci(false, scn), lcid, acl_handle, false,
@@ -267,7 +270,7 @@ class StackRfcommTest : public Test {
                       tPORT_CALLBACK* event_callback, uint16_t lcid,
                       uint16_t acl_handle, uint16_t* client_handle,
                       bool is_first_connection) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    BT_HDR* uih_pn_channel_3 =
        AllocateWrappedOutgoingL2capAclPacket(CreateQuickPnPacket(
            true, GetDlci(false, scn), true, mtu, RFCOMM_PN_CONV_LAYER_TYPE_1,
@@ -291,7 +294,7 @@ class StackRfcommTest : public Test {
  }

  void TestConnectClientPortL2cap(uint16_t acl_handle, uint16_t lcid) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    // Send configuration request when L2CAP connect is succsseful
    tL2CAP_CFG_INFO cfg_req = {.mtu_present = true, .mtu = L2CAP_MTU_SIZE};
    EXPECT_CALL(l2cap_interface_,
@@ -299,12 +302,12 @@ class StackRfcommTest : public Test {
        .WillOnce(Return(true));
    l2cap_appl_info_.pL2CA_ConnectCfm_Cb(lcid, L2CAP_CONN_OK);

    VLOG(1) << "Step 2";
    log::verbose("Step 2");
    // Remote device confirms our configuration request
    cfg_req.mtu_present = false;
    l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, L2CAP_CFG_OK, {});

    VLOG(1) << "Step 3";
    log::verbose("Step 3");
    // Remote device also asks to configure MTU
    // Once configuration is done, we connect to multiplexer control channel 0
    EXPECT_CALL(l2cap_interface_,
@@ -323,9 +326,9 @@ class StackRfcommTest : public Test {
                         uint8_t scn, uint16_t mtu, uint16_t acl_handle,
                         uint16_t lcid, int port_callback_index,
                         bool is_first_connection) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    if (is_first_connection) {
      VLOG(1) << "Step 1.5";
      log::verbose("Step 1.5");
      // Once remote accept multiplexer control channel 0
      // We change to desired channel on non-initiating device (remote device)
      BT_HDR* ua_channel_0 = AllocateWrappedIncomingL2capAclPacket(
@@ -342,7 +345,7 @@ class StackRfcommTest : public Test {
      osi_free(uih_pn_channel_3);
    }

    VLOG(1) << "Step 2";
    log::verbose("Step 2");
    // Once remote accept service channel change, we start security procedure
    BT_HDR* uih_pn_channel_3_accept =
        AllocateWrappedIncomingL2capAclPacket(CreateQuickPnPacket(
@@ -359,7 +362,7 @@ class StackRfcommTest : public Test {
                        Return(BTM_SUCCESS)));
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, uih_pn_channel_3_accept);

    VLOG(1) << "Step 3";
    log::verbose("Step 3");
    // Once security procedure is done, we officially connect to target scn
    BT_HDR* sabm_channel_3 = AllocateWrappedOutgoingL2capAclPacket(
        CreateQuickSabmPacket(GetDlci(false, scn), lcid, acl_handle));
@@ -369,7 +372,7 @@ class StackRfcommTest : public Test {
    security_callback(&peer_addr, BT_TRANSPORT_BR_EDR, p_port, BTM_SUCCESS);
    osi_free(sabm_channel_3);

    VLOG(1) << "Step 4";
    log::verbose("Step 4");
    // When target scn is accepted by remote, we need to configure modem signal
    // state beofre using the port
    EXPECT_CALL(
@@ -385,14 +388,14 @@ class StackRfcommTest : public Test {
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, ua_channel_3);
    osi_free(uih_msc_cmd);

    VLOG(1) << "Step 5";
    log::verbose("Step 5");
    // modem configuration is done
    BT_HDR* uih_msc_response = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickMscPacket(false, GetDlci(false, scn), lcid, acl_handle,
                             false, false, true, true, false, true));
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, uih_msc_response);

    VLOG(1) << "Step 6";
    log::verbose("Step 6");
    // Remote also need to configure its modem signal before we can send data
    BT_HDR* uih_msc_cmd_from_peer = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickMscPacket(false, GetDlci(false, scn), lcid, acl_handle, true,
@@ -412,7 +415,7 @@ class StackRfcommTest : public Test {
                                         bool cr, const std::string& message,
                                         int credits, uint16_t acl_handle,
                                         uint16_t lcid) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    BT_HDR* data_packet = AllocateWrappedOutgoingL2capAclPacket(
        CreateQuickDataPacket(GetDlci(is_initiator, scn), cr, lcid, acl_handle,
                              credits, message));
@@ -431,7 +434,7 @@ class StackRfcommTest : public Test {
                                            int credits, uint16_t acl_handle,
                                            uint16_t lcid,
                                            int port_callback_index) {
    VLOG(1) << "Step 1";
    log::verbose("Step 1");
    BT_HDR* data_packet = AllocateWrappedIncomingL2capAclPacket(
        CreateQuickDataPacket(GetDlci(is_initiator, scn), cr, lcid, acl_handle,
                              credits, message));
@@ -439,7 +442,7 @@ class StackRfcommTest : public Test {
                PortEventCallback(_, port_handle, port_callback_index));
    l2cap_appl_info_.pL2CA_DataInd_Cb(lcid, data_packet);

    VLOG(1) << "Step 2";
    log::verbose("Step 2");
    char buffer[L2CAP_MTU_SIZE] = {};
    uint16_t length = 0;
    int status = PORT_ReadData(port_handle, buffer, L2CAP_MTU_SIZE, &length);
@@ -722,7 +725,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  static const uint16_t test_mtu = 1000;
  static const RawAddress test_address = GetTestAddress(0);
  uint16_t server_handle = 0;
  VLOG(1) << "Step 1";
  log::verbose("Step 1");
  // Prepare a server port
  int status = RFCOMM_CreateConnectionWithSecurity(
      test_uuid, test_server_scn, true, test_mtu, RawAddress::kAny,
@@ -733,7 +736,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  status = PORT_SetEventCallback(server_handle, port_event_cback_0);
  ASSERT_EQ(status, PORT_SUCCESS);

  VLOG(1) << "Step 2";
  log::verbose("Step 2");
  // Try to connect to a client port
  uint16_t client_handle_1 = 0;
  EXPECT_CALL(l2cap_interface_, ConnectRequest(BT_PSM_RFCOMM, test_address))
@@ -748,7 +751,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  status = PORT_SetEventCallback(client_handle_1, port_event_cback_1);
  ASSERT_EQ(status, PORT_SUCCESS);

  VLOG(1) << "Step 3";
  log::verbose("Step 3");
  // While our connection is pending, remote device tries to connect to
  // new_lcid, with L2CAP command id: pending_cmd_id
  static const uint8_t pending_cmd_id = 0x05;
@@ -756,7 +759,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  l2cap_appl_info_.pL2CA_ConnectInd_Cb(test_address, new_lcid, BT_PSM_RFCOMM,
                                       pending_cmd_id);

  VLOG(1) << "Step 4";
  log::verbose("Step 4");
  // Remote reject our connection request saying PSM not allowed
  // This should trigger RFCOMM to accept remote L2CAP connection at new_lcid
  EXPECT_CALL(l2cap_interface_, ConnectResponse(test_address, pending_cmd_id,
@@ -769,7 +772,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
      .WillOnce(Return(true));
  l2cap_appl_info_.pL2CA_ConnectCfm_Cb(old_lcid, L2CAP_CONN_NO_PSM);

  VLOG(1) << "Step 5";
  log::verbose("Step 5");
  // Remote device also ask to configure MTU size as well
  tL2CAP_CFG_INFO peer_cfg_req = {.mtu_present = true, .mtu = test_mtu};
  // We responded by saying OK
@@ -780,13 +783,13 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
      .WillOnce(Return(true));
  l2cap_appl_info_.pL2CA_ConfigInd_Cb(new_lcid, &peer_cfg_req);

  VLOG(1) << "Step 6";
  log::verbose("Step 6");
  // Remote device accepted our MTU size
  l2cap_appl_info_.pL2CA_ConfigCfm_Cb(new_lcid, L2CAP_CFG_OK, {});

  // L2CAP collision and connection setup done

  VLOG(1) << "Step 7";
  log::verbose("Step 7");
  // Remote device connect multiplexer channel
  BT_HDR* sabm_channel_0 = AllocateWrappedIncomingL2capAclPacket(
      CreateQuickSabmPacket(RFCOMM_MX_DLCI, new_lcid, acl_handle));
@@ -808,7 +811,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  osi_free(ua_channel_0);
  osi_free(uih_pn_cmd_to_peer);

  VLOG(1) << "Step 8";
  log::verbose("Step 8");
  // Peer tries to configure test_server_scn
  BT_HDR* uih_pn_cmd_from_peer = AllocateWrappedIncomingL2capAclPacket(
      CreateQuickPnPacket(true, GetDlci(false, test_server_scn), true, test_mtu,
@@ -826,7 +829,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  l2cap_appl_info_.pL2CA_DataInd_Cb(new_lcid, uih_pn_cmd_from_peer);
  osi_free(uih_pn_rsp_to_peer);

  VLOG(1) << "Step 9";
  log::verbose("Step 9");
  // Remote never replies our configuration request for test_peer_scn
  // But instead connect to test_server_scn directly
  BT_HDR* sabm_server_scn =
@@ -843,7 +846,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
                      Return(BTM_SUCCESS)));
  l2cap_appl_info_.pL2CA_DataInd_Cb(new_lcid, sabm_server_scn);

  VLOG(1) << "Step 10";
  log::verbose("Step 10");
  // After security check, we accept the connection
  ASSERT_TRUE(security_callback);
  BT_HDR* ua_server_scn =
@@ -858,7 +861,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  security_callback(&test_address, BT_TRANSPORT_BR_EDR, p_port, BTM_SUCCESS);
  osi_free(ua_server_scn);

  VLOG(1) << "Step 11";
  log::verbose("Step 11");
  // MPX_CTRL Modem Status Command (MSC)
  BT_HDR* uih_msc_cmd_from_peer = AllocateWrappedIncomingL2capAclPacket(
      CreateQuickMscPacket(true, GetDlci(false, test_server_scn), new_lcid,
@@ -880,7 +883,7 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) {
  osi_free(uih_msc_rsp_to_peer);
  osi_free(uih_msc_cmd_to_peer);

  VLOG(1) << "Step 12";
  log::verbose("Step 12");
  BT_HDR* uih_msc_rsp_from_peer = AllocateWrappedIncomingL2capAclPacket(
      CreateQuickMscPacket(true, GetDlci(false, test_server_scn), new_lcid,
                           acl_handle, false, false, true, true, false, true));
+7 −4
Original line number Diff line number Diff line
@@ -20,15 +20,18 @@
#include <base/logging.h>
#include <base/strings/string_piece.h>
#include <base/strings/string_util.h>
#include <bluetooth/log.h>
#include <gtest/gtest.h>

#include <string>

using namespace bluetooth;

int main(int argc, char** argv) {
  ::testing::InitGoogleTest(&argc, argv);

  if (base::CommandLine::InitializedForCurrentProcess()) {
    LOG(FATAL) << "base::CommandLine::Init should not be called twice";
    log::fatal("base::CommandLine::Init should not be called twice");
    return 1;
  }

@@ -45,14 +48,14 @@ int main(int argc, char** argv) {
  const char* logging_argv[] = {"bt_stack", log_level_arg};
  // Init command line object with logging switches
  if (!base::CommandLine::Init(2, logging_argv)) {
    LOG(FATAL) << "base::CommandLine::Init failed, arg0=" << logging_argv[0]
               << ", arg1=" << logging_argv[1];
    log::fatal("base::CommandLine::Init failed, arg0={}, arg1={}",
               logging_argv[0], logging_argv[1]);
    return 1;
  }

  logging::LoggingSettings log_settings;
  if (!logging::InitLogging(log_settings)) {
    LOG(ERROR) << "Failed to set up logging";
    log::error("Failed to set up logging");
  }

  // Android already logs thread_id, proc_id, timestamp, so disable those.