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

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

Merge "Handle root inflammation event properly."

parents 446fa3ab ef5180b3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -391,9 +391,9 @@ struct HciLayer::impl {
      auto view = VendorSpecificEventView::Create(event);
      ASSERT(view.IsValid());
      if (view.GetSubeventCode() == VseSubeventCode::BQR_EVENT) {
        auto bqr_quality_view = BqrLinkQualityEventView::Create(BqrEventView::Create(view));
        auto inflammation = BqrRootInflammationEventView::Create(bqr_quality_view);
        if (bqr_quality_view.IsValid() && inflammation.IsValid()) {
        auto bqr_event = BqrEventView::Create(view);
        auto inflammation = BqrRootInflammationEventView::Create(bqr_event);
        if (bqr_event.IsValid() && inflammation.IsValid()) {
          handle_root_inflammation(inflammation.GetVendorSpecificErrorCode());
          return;
        }
+35 −0
Original line number Diff line number Diff line
@@ -49,6 +49,20 @@ using packet::PacketView;
using packet::RawBuilder;
using testing::LogCapture;

std::vector<uint8_t> GetPacketBytes(std::unique_ptr<packet::BasePacketBuilder> packet) {
  std::vector<uint8_t> bytes;
  BitInserter i(bytes);
  bytes.reserve(packet->size());
  packet->Serialize(i);
  return bytes;
}

std::unique_ptr<packet::BasePacketBuilder> CreatePayload(std::vector<uint8_t> payload) {
  auto raw_builder = std::make_unique<packet::RawBuilder>();
  raw_builder->AddOctets(payload);
  return raw_builder;
}

class TestHciHal : public hal::HciHal {
 public:
  TestHciHal() : hal::HciHal() {}
@@ -97,6 +111,10 @@ class TestHciHal : public hal::HciHal {
    return outgoing_commands_.size();
  }

  void InjectEvent(std::unique_ptr<packet::BasePacketBuilder> packet) {
    callbacks->hciEventReceived(GetPacketBytes(std::move(packet)));
  }

  std::string ToString() const override {
    return std::string("TestHciHal");
  }
@@ -184,5 +202,22 @@ TEST_F(HciLayerTest, abort_after_hci_restart_timeout) {
      "");
}

TEST_F(HciLayerTest, abort_on_root_inflammation_event) {
  FailIfResetNotSent();

  auto payload = CreatePayload({'0'});
  auto root_inflammation_event = BqrRootInflammationEventBuilder::Create(0x01, 0x01, std::move(payload));
  hal_->InjectEvent(std::move(root_inflammation_event));
  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise, "Received a Root Inflammation Event");
  ASSERT_DEATH(
      {
        FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count());
        std::promise<void> promise;
        log_capture_->WaitUntilLogContains(&promise, "Root inflammation with reason");
      },
      "");
}

}  // namespace hci
}  // namespace bluetooth