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

Commit 7692e154 authored by Dylan Tian's avatar Dylan Tian Committed by Automerger Merge Worker
Browse files

Add Qualcomm 3804 debug logging with base 64 format to btsnooz log when...

Add Qualcomm 3804 debug logging with base 64 format to btsnooz log when filtered is enabled. am: f9127f65 am: d589d4ea

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/18404728



Change-Id: I1a329a129ed2e31bcf06707a39dc6662da00130c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d4c69028 d589d4ea
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -120,12 +120,16 @@ void delete_old_btsnooz_files(const std::string& log_path, const std::chrono::mi
  }
}

size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::PacketType type) {
size_t get_btsnooz_packet_length_to_write(
    const HciPacket& packet, SnoopLogger::PacketType type, bool qualcomm_debug_log_enabled) {
  static const size_t kAclHeaderSize = 4;
  static const size_t kL2capHeaderSize = 4;
  static const size_t kL2capCidOffset = (kAclHeaderSize + 2);
  static const uint16_t kL2capSignalingCid = 0x0001;

  static const size_t kHciAclHandleOffset = 0;
  static const uint16_t kQualcommDebugLogHandle = 0xedc;

  // Maximum amount of ACL data to log.
  // Enough for an RFCOMM frame up to the frame check;
  // not enough for a HID report or audio data.
@@ -147,11 +151,18 @@ size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::
        uint16_t l2cap_cid =
            static_cast<uint16_t>(packet[kL2capCidOffset]) |
            static_cast<uint16_t>((static_cast<uint16_t>(packet[kL2capCidOffset + 1]) << static_cast<uint16_t>(8)));
        uint16_t hci_acl_packet_handle =
            static_cast<uint16_t>(packet[kHciAclHandleOffset]) |
            static_cast<uint16_t>((static_cast<uint16_t>(packet[kHciAclHandleOffset + 1]) << static_cast<uint16_t>(8)));
        hci_acl_packet_handle &= 0x0fff;

        if (l2cap_cid == kL2capSignalingCid) {
          // For the signaling CID, take the full packet.
          // That way, the PSM setup is captured, allowing decoding of PSMs down
          // the road.
          return packet.size();
        } else if (qualcomm_debug_log_enabled && hci_acl_packet_handle == kQualcommDebugLogHandle) {
          return packet.size();
        } else {
          // Otherwise, return as much as we reasonably can
          len_hci_acl = kMaxBtsnoozAclSize;
@@ -175,11 +186,13 @@ size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::
const std::string SnoopLogger::kBtSnoopLogModeDisabled = "disabled";
const std::string SnoopLogger::kBtSnoopLogModeFiltered = "filtered";
const std::string SnoopLogger::kBtSnoopLogModeFull = "full";
const std::string SnoopLogger::kSoCManufacturerQualcomm = "Qualcomm";

const std::string SnoopLogger::kBtSnoopMaxPacketsPerFileProperty = "persist.bluetooth.btsnoopsize";
const std::string SnoopLogger::kIsDebuggableProperty = "ro.debuggable";
const std::string SnoopLogger::kBtSnoopLogModeProperty = "persist.bluetooth.btsnooplogmode";
const std::string SnoopLogger::kBtSnoopDefaultLogModeProperty = "persist.bluetooth.btsnoopdefaultmode";
const std::string SnoopLogger::kSoCManufacturerProperty = "ro.soc.manufacturer";

SnoopLogger::SnoopLogger(
    std::string snoop_log_path,
@@ -187,12 +200,14 @@ SnoopLogger::SnoopLogger(
    size_t max_packets_per_file,
    size_t max_packets_per_buffer,
    const std::string& btsnoop_mode,
    bool qualcomm_debug_log_enabled,
    const std::chrono::milliseconds snooz_log_life_time,
    const std::chrono::milliseconds snooz_log_delete_alarm_interval)
    : snoop_log_path_(std::move(snoop_log_path)),
      snooz_log_path_(std::move(snooz_log_path)),
      max_packets_per_file_(max_packets_per_file),
      btsnooz_buffer_(max_packets_per_buffer),
      qualcomm_debug_log_enabled_(qualcomm_debug_log_enabled),
      snooz_log_life_time_(snooz_log_life_time),
      snooz_log_delete_alarm_interval_(snooz_log_delete_alarm_interval) {
  if (false && btsnoop_mode == kBtSnoopLogModeFiltered) {
@@ -298,7 +313,7 @@ void SnoopLogger::Capture(const HciPacket& packet, Direction direction, PacketTy
    if (!is_enabled_) {
      // btsnoop disabled, log in-memory btsnooz log only
      std::stringstream ss;
      size_t included_length = get_btsnooz_packet_length_to_write(packet, type);
      size_t included_length = get_btsnooz_packet_length_to_write(packet, type, qualcomm_debug_log_enabled_);
      header.length_captured = htonl(included_length + /* type byte */ 1);
      if (!ss.write(reinterpret_cast<const char*>(&header), sizeof(PacketHeaderType))) {
        LOG_ERROR("Failed to write packet header for btsnooz, error: \"%s\"", strerror(errno));
@@ -450,6 +465,17 @@ std::string SnoopLogger::GetBtSnoopMode() {
  return btsnoop_mode;
}

bool SnoopLogger::IsQualcommDebugLogEnabled() {
  // Check system prop if the soc manufacturer is Qualcomm
  bool qualcomm_debug_log_enabled = false;
  {
    auto soc_manufacturer_prop = os::GetSystemProperty(kSoCManufacturerProperty);
    qualcomm_debug_log_enabled = soc_manufacturer_prop.has_value() &&
                                 common::StringTrim(soc_manufacturer_prop.value()) == kSoCManufacturerQualcomm;
  }
  return qualcomm_debug_log_enabled;
}

const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() {
  return new SnoopLogger(
      os::ParameterProvider::SnoopLogFilePath(),
@@ -457,6 +483,7 @@ const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() {
      GetMaxPacketsPerFile(),
      GetMaxPacketsPerBuffer(),
      GetBtSnoopMode(),
      IsQualcommDebugLogEnabled(),
      kBtSnoozLogLifeTime,
      kBtSnoozLogDeleteRepeatingAlarmInterval);
});
+8 −0
Original line number Diff line number Diff line
@@ -36,11 +36,13 @@ class SnoopLogger : public ::bluetooth::Module {
  static const std::string kBtSnoopLogModeDisabled;
  static const std::string kBtSnoopLogModeFiltered;
  static const std::string kBtSnoopLogModeFull;
  static const std::string kSoCManufacturerQualcomm;

  static const std::string kBtSnoopMaxPacketsPerFileProperty;
  static const std::string kIsDebuggableProperty;
  static const std::string kBtSnoopLogModeProperty;
  static const std::string kBtSnoopDefaultLogModeProperty;
  static const std::string kSoCManufacturerProperty;

  // Put in header for test
  struct PacketHeaderType {
@@ -69,6 +71,10 @@ class SnoopLogger : public ::bluetooth::Module {
  // Changes to this values is only effective after restarting Bluetooth
  static std::string GetBtSnoopMode();

  // Returns whether the soc manufacturer is Qualcomm
  // Changes to this value is only effective after restarting Bluetooth
  static bool IsQualcommDebugLogEnabled();

  // Has to be defined from 1 to 4 per btsnoop format
  enum PacketType {
    CMD = 1,
@@ -101,6 +107,7 @@ class SnoopLogger : public ::bluetooth::Module {
      size_t max_packets_per_file,
      size_t max_packets_per_buffer,
      const std::string& btsnoop_mode,
      bool qualcomm_debug_log_enabled,
      const std::chrono::milliseconds snooz_log_life_time,
      const std::chrono::milliseconds snooz_log_delete_alarm_interval);
  void CloseCurrentSnoopLogFile();
@@ -115,6 +122,7 @@ class SnoopLogger : public ::bluetooth::Module {
  bool is_filtered_ = false;
  size_t max_packets_per_file_;
  common::CircularBuffer<std::string> btsnooz_buffer_;
  bool qualcomm_debug_log_enabled_ = false;
  size_t packet_counter_ = 0;
  mutable std::recursive_mutex file_mutex_;
  std::unique_ptr<os::RepeatingAlarm> alarm_;
+115 −47
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ std::vector<uint8_t> kAvdtpSuspend = {0x02, 0x02, 0x00, 0x07, 0x00, 0x03, 0x00,
std::vector<uint8_t> kHfpAtNrec0 = {0x02, 0x02, 0x20, 0x13, 0x00, 0x0f, 0x00, 0x41, 0x00, 0x09, 0xff, 0x15,
                                    0x01, 0x41, 0x54, 0x2b, 0x4e, 0x52, 0x45, 0x43, 0x3d, 0x30, 0x0d, 0x5c};

std::vector<uint8_t> kQualcommConnectionRequest = {0xdc, 0x2e, 0x54, 0x00, 0x50, 0x00, 0xff, 0x00, 0x00, 0x0a,
                                                   0x0f, 0x09, 0x01, 0x00, 0x5c, 0x93, 0x01, 0x00, 0x42, 0x00};

}  // namespace

using bluetooth::TestModuleRegistry;
@@ -60,13 +63,15 @@ class TestSnoopLoggerModule : public SnoopLogger {
      std::string snoop_log_path,
      std::string snooz_log_path,
      size_t max_packets_per_file,
      const std::string& btsnoop_mode)
      const std::string& btsnoop_mode,
      bool qualcomm_debug_log_enabled)
      : SnoopLogger(
            std::move(snoop_log_path),
            std::move(snooz_log_path),
            max_packets_per_file,
            SnoopLogger::GetMaxPacketsPerBuffer(),
            btsnoop_mode,
            qualcomm_debug_log_enabled,
            20ms,
            5ms) {}

@@ -128,10 +133,10 @@ class SnoopLoggerModuleTest : public Test {

TEST_F(SnoopLoggerModuleTest, empty_snoop_log_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  test_registry.StopAll();

  // Verify states after test
@@ -142,10 +147,10 @@ TEST_F(SnoopLoggerModuleTest, empty_snoop_log_test) {

TEST_F(SnoopLoggerModuleTest, disable_snoop_log_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  test_registry.StopAll();

  // Verify states after test
@@ -156,12 +161,12 @@ TEST_F(SnoopLoggerModuleTest, disable_snoop_log_test) {

TEST_F(SnoopLoggerModuleTest, capture_one_packet_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);

  test_registry.StopAll();

@@ -175,13 +180,13 @@ TEST_F(SnoopLoggerModuleTest, capture_one_packet_test) {

TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_looger->CallGetDumpsysData(builder_);
  snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
@@ -198,13 +203,13 @@ TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {

TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  snoop_looger->Capture(kSdpConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_looger->CallGetDumpsysData(builder_);
  snoop_logger->Capture(kSdpConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
@@ -221,13 +226,13 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {

TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  snoop_looger->Capture(kAvdtpSuspend, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_looger->CallGetDumpsysData(builder_);
  snoop_logger->Capture(kAvdtpSuspend, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
@@ -244,13 +249,13 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {

TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  snoop_looger->Capture(kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_looger->CallGetDumpsysData(builder_);
  snoop_logger->Capture(kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
@@ -267,10 +272,10 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {

TEST_F(SnoopLoggerModuleTest, delete_old_snooz_log_files) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  std::filesystem::create_directories(temp_snooz_log_);

@@ -285,11 +290,11 @@ TEST_F(SnoopLoggerModuleTest, delete_old_snooz_log_files) {
TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {
  // Start once
  {
    auto* snoop_looger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull, false);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.StopAll();
  }

@@ -302,12 +307,12 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {

  // Start again
  {
    auto* snoop_looger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull, false);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.StopAll();
  }

@@ -324,13 +329,13 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {

TEST_F(SnoopLoggerModuleTest, rotate_file_after_full_test) {
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull, false);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);

  for (int i = 0; i < 11; i++) {
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  }

  test_registry.StopAll();
@@ -346,4 +351,67 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_after_full_test) {
      sizeof(SnoopLogger::FileHeaderType) + (sizeof(SnoopLogger::PacketHeaderType) + kInformationRequest.size()) * 10);
}

TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_test) {
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, true);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  snoop_logger->Capture(kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
      std::filesystem::file_size(temp_snooz_log_),
      sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) + kQualcommConnectionRequest.size());

  test_registry.StopAll();

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));
}

TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_regression_test) {
  {
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, true);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
        std::filesystem::file_size(temp_snooz_log_),
        sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) + 14);
    test_registry.StopAll();
  }

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));

  {
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled, false);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
        std::filesystem::file_size(temp_snooz_log_),
        sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) + 14);
    test_registry.StopAll();
  }

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));
}

}  // namespace testing