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

Commit 48207b0f authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

hci_layer_fake: Add debug logs for testing

Bug: 356594223
Flag: TEST_ONLY
Test: atest bluetooth_gd_unit_test

Change-Id: Idf41311d14d07f69a6b24c35848b6e05d1b6de36
parent 1cc4b175
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <bluetooth/log.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <log/log.h>

#include <chrono>
#include <future>
@@ -237,6 +238,7 @@ public:
class LeImplTest : public ::testing::Test {
protected:
  void SetUp() override {
    __android_log_set_minimum_priority(ANDROID_LOG_VERBOSE);
    thread_ = new Thread("thread", Thread::Priority::NORMAL);
    handler_ = new Handler(thread_);
    controller_ = new TestController();
+17 −0
Original line number Diff line number Diff line
@@ -57,11 +57,26 @@ static std::unique_ptr<AclBuilder> NextAclPacket(uint16_t handle) {
  return AclBuilder::Create(handle, packet_boundary_flag, broadcast_flag, NextPayload(handle));
}

static void DebugPrintCommandOpcode(std::string prefix,
                                    const std::unique_ptr<CommandBuilder>& command) {
  std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();
  BitInserter it(*packet_bytes);
  command->Serialize(it);
  PacketView<kLittleEndian> packet_bytes_view(packet_bytes);
  auto temp_cmd_view = CommandView::Create(packet_bytes_view);
  temp_cmd_view.IsValid();
  auto op_code = temp_cmd_view.GetOpCode();

  log::info("{} op_code: {}", prefix, OpCodeText(op_code));
}

void HciLayerFake::EnqueueCommand(
        std::unique_ptr<CommandBuilder> command,
        common::ContextualOnceCallback<void(CommandStatusView)> on_status) {
  std::lock_guard<std::mutex> lock(mutex_);

  DebugPrintCommandOpcode(std::string("Sending with command status, "), command);

  command_queue_.push(std::move(command));
  command_status_callbacks.push_back(std::move(on_status));

@@ -76,6 +91,8 @@ void HciLayerFake::EnqueueCommand(
        common::ContextualOnceCallback<void(CommandCompleteView)> on_complete) {
  std::lock_guard<std::mutex> lock(mutex_);

  DebugPrintCommandOpcode(std::string("Sending with command complete, "), command);

  command_queue_.push(std::move(command));
  command_complete_callbacks.push_back(std::move(on_complete));