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

Commit ae759ab1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "HCI: Make timeout configurable" into main am: 844a25ea am: aa4b237b

parents 1328bc75 aa4b237b
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "os/alarm.h"
#include "os/metrics.h"
#include "os/queue.h"
#include "os/system_properties.h"
#include "osi/include/stack_power_telemetry.h"
#include "packet/raw_builder.h"
#include "storage/storage_module.h"
@@ -57,6 +58,19 @@ using os::Alarm;
using os::Handler;
using std::unique_ptr;

static std::chrono::milliseconds getHciTimeoutMs() {
  static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base(
      "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count()));
  return sHciTimeoutMs;
}

static std::chrono::milliseconds getHciTimeoutRestartMs() {
  static auto sRestartHciTimeoutMs =
      std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base(
          "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count()));
  return sRestartHciTimeoutMs;
}

static void fail_if_reset_complete_not_success(CommandCompleteView complete) {
  auto reset_complete = ResetCompleteView::Create(complete);
  log::assert_that(reset_complete.IsValid(), "assert failed: reset_complete.IsValid()");
@@ -67,7 +81,10 @@ static void fail_if_reset_complete_not_success(CommandCompleteView complete) {
}

static void abort_after_time_out(OpCode op_code) {
  log::fatal("Done waiting for debug information after HCI timeout ({})", OpCodeText(op_code));
  log::fatal(
      "Done waiting for debug information after HCI timeout ({}) for {}ms",
      OpCodeText(op_code),
      getHciTimeoutRestartMs().count());
}

class CommandQueueEntry {
@@ -267,7 +284,7 @@ struct HciLayer::impl {

  void on_hci_timeout(OpCode op_code) {
    common::StopWatch::DumpStopWatchLog();
    log::error("Timed out waiting for {}", OpCodeText(op_code));
    log::error("Timed out waiting for {} for {}ms", OpCodeText(op_code), getHciTimeoutMs().count());

    bluetooth::os::LogMetricHciTimeoutEvent(static_cast<uint32_t>(op_code));

@@ -286,7 +303,8 @@ struct HciLayer::impl {
    }
    if (hci_abort_alarm_ == nullptr) {
      hci_abort_alarm_ = new Alarm(module_.GetHandler());
      hci_abort_alarm_->Schedule(BindOnce(&abort_after_time_out, op_code), kHciTimeoutRestartMs);
      hci_abort_alarm_->Schedule(
          BindOnce(&abort_after_time_out, op_code), getHciTimeoutRestartMs());
    } else {
      log::warn("Unable to schedul abort timer");
    }
@@ -317,7 +335,8 @@ struct HciLayer::impl {
    waiting_command_ = op_code;
    command_credits_ = 0;  // Only allow one outstanding command
    if (hci_timeout_alarm_ != nullptr) {
      hci_timeout_alarm_->Schedule(BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), kHciTimeoutMs);
      hci_timeout_alarm_->Schedule(
          BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), getHciTimeoutMs());
    } else {
      log::warn("{} sent without an hci-timeout timer", OpCodeText(op_code));
    }
@@ -386,7 +405,8 @@ struct HciLayer::impl {
    }
    if (hci_abort_alarm_ == nullptr) {
      hci_abort_alarm_ = new Alarm(module_.GetHandler());
      hci_abort_alarm_->Schedule(BindOnce(&abort_after_root_inflammation, vse_error_reason), kHciTimeoutRestartMs);
      hci_abort_alarm_->Schedule(
          BindOnce(&abort_after_root_inflammation, vse_error_reason), getHciTimeoutRestartMs());
    } else {
      log::warn("Abort timer already scheduled");
    }
+20 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "module.h"
#include "os/fake_timer/fake_timerfd.h"
#include "os/handler.h"
#include "os/system_properties.h"
#include "os/thread.h"
#include "packet/raw_builder.h"

@@ -75,6 +76,19 @@ std::vector<uint8_t> GetPacketBytes(std::unique_ptr<packet::BasePacketBuilder> p
  return bytes;
}

static std::chrono::milliseconds getHciTimeoutMs() {
  static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base(
      "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count()));
  return sHciTimeoutMs;
}

static std::chrono::milliseconds getHciTimeoutRestartMs() {
  static auto sRestartHciTimeoutMs =
      std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base(
          "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count()));
  return sRestartHciTimeoutMs;
}

class HciLayerTest : public ::testing::Test {
 protected:
  void SetUp() override {
@@ -132,7 +146,7 @@ TEST_F(HciLayerTest, reset_command_sent_on_start) {

TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) {
  FailIfResetNotSent();
  FakeTimerAdvance(HciLayer::kHciTimeoutMs.count());
  FakeTimerAdvance(getHciTimeoutMs().count());

  sync_handler();

@@ -144,7 +158,7 @@ TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) {

TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) {
  FailIfResetNotSent();
  FakeTimerAdvance(HciLayer::kHciTimeoutMs.count());
  FakeTimerAdvance(getHciTimeoutMs().count());

  auto sent_command = hal_->GetSentCommand();
  ASSERT_TRUE(sent_command.has_value());
@@ -154,7 +168,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) {
  ASSERT_DEATH(
      {
        sync_handler();
        FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count());
        FakeTimerAdvance(getHciTimeoutRestartMs().count());
        sync_handler();
      },
      "");
@@ -162,7 +176,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) {

TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) {
  FailIfResetNotSent();
  FakeTimerAdvance(HciLayer::kHciTimeoutMs.count());
  FakeTimerAdvance(getHciTimeoutMs().count());

  auto sent_command = hal_->GetSentCommand();
  ASSERT_TRUE(sent_command.has_value());
@@ -175,7 +189,7 @@ TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) {

  ASSERT_DEATH(
      {
        FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count());
        FakeTimerAdvance(getHciTimeoutRestartMs().count());
        sync_handler();
      },
      "");
@@ -189,7 +203,7 @@ TEST_F(HciLayerDeathTest, abort_on_root_inflammation_event) {
        sync_handler();
        hal_->InjectEvent(BqrRootInflammationEventBuilder::Create(
            0x01, 0x01, std::make_unique<packet::RawBuilder>()));
        FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count());
        FakeTimerAdvance(getHciTimeoutRestartMs().count());
        sync_handler();
      },
      "");