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

Commit 090f333d authored by Chienyuan's avatar Chienyuan
Browse files

gd: Fix flaky tests of LeAdvertisingManager

Bug: 174541433
Tag: #gd-refactor
Test: atest bluetooth_test_gd
Change-Id: Id056390a28e5b60d47a43ab0eaeacf44edb451fd
parent 9c4aacae
Loading
Loading
Loading
Loading
+81 −87
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ class TestHciLayer : public HciLayer {
                      common::ContextualOnceCallback<void(CommandStatusView)> on_status) override {
    auto packet_view = CommandPacketView::Create(GetPacketView(std::move(command)));
    ASSERT_TRUE(packet_view.IsValid());
    std::lock_guard<std::mutex> lock(mutex_);
    command_queue_.push_back(packet_view);
    command_status_callbacks.push_back(std::move(on_status));
    if (command_promise_ != nullptr &&
@@ -99,6 +100,7 @@ class TestHciLayer : public HciLayer {
                      common::ContextualOnceCallback<void(CommandCompleteView)> on_complete) override {
    auto packet_view = CommandPacketView::Create(GetPacketView(std::move(command)));
    ASSERT_TRUE(packet_view.IsValid());
    std::lock_guard<std::mutex> lock(mutex_);
    command_queue_.push_back(packet_view);
    command_complete_callbacks.push_back(std::move(on_complete));
    if (command_promise_ != nullptr &&
@@ -115,11 +117,18 @@ class TestHciLayer : public HciLayer {
    }
  }

  std::future<size_t> GetCommandFuture(OpCode op_code = OpCode::NONE) {
    ASSERT_LOG(command_promise_ == nullptr, "Promises promises ... Only one at a time");
  void SetCommandFuture(OpCode op_code = OpCode::NONE) {
    ASSERT_LOG(command_promise_ == nullptr, "Promises, Promises, ... Only one at a time.");
    command_op_code_ = op_code;
    command_promise_ = std::make_unique<std::promise<size_t>>();
    return command_promise_->get_future();
    command_future_ = std::make_unique<std::future<size_t>>(command_promise_->get_future());
  }

  void ResetCommandFuture() {
    if (command_future_ != nullptr) {
      command_future_.reset();
      command_promise_.reset();
    }
  }

  std::future<size_t> GetSubCommandFuture(SubOcf sub_ocf) {
@@ -131,10 +140,19 @@ class TestHciLayer : public HciLayer {
  }

  ConnectionManagementCommandView GetCommandPacket(OpCode op_code) {
    if (command_queue_.empty()) {
      return ConnectionManagementCommandView::Create(AclCommandView::Create(
          CommandPacketView::Create(PacketView<kLittleEndian>(std::make_shared<std::vector<uint8_t>>()))));
    if (!command_queue_.empty()) {
      std::lock_guard<std::mutex> lock(mutex_);
      if (command_future_ != nullptr) {
        command_future_.reset();
        command_promise_.reset();
      }
    } else if (command_future_ != nullptr) {
      auto result = command_future_->wait_for(std::chrono::milliseconds(1000));
      EXPECT_NE(std::future_status::timeout, result);
    }
    ASSERT_LOG(
        !command_queue_.empty(), "Expecting command %s but command queue was empty", OpCodeText(op_code).c_str());
    std::lock_guard<std::mutex> lock(mutex_);
    CommandPacketView command_packet_view = CommandPacketView::Create(command_queue_.front());
    command_queue_.pop_front();
    auto command = ConnectionManagementCommandView::Create(AclCommandView::Create(command_packet_view));
@@ -205,6 +223,7 @@ class TestHciLayer : public HciLayer {
  std::list<CommandPacketView> command_queue_;
  mutable std::mutex mutex_;
  std::unique_ptr<std::promise<size_t>> command_promise_{};
  std::unique_ptr<std::future<size_t>> command_future_{};
  OpCode command_op_code_;
  SubOcf command_sub_ocf_;
};
@@ -374,7 +393,7 @@ class LeAdvertisingAPITest : public LeAdvertisingManagerTest {
    advertising_config.advertisement = gap_data;
    advertising_config.scan_response = gap_data;

    auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
    test_hci_layer_->SetCommandFuture();
    advertiser_id_ = le_advertising_manager_->ExtendedCreateAdvertiser(
        0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
    ASSERT_NE(LeAdvertisingManager::kInvalidId, advertiser_id_);
@@ -387,17 +406,16 @@ class LeAdvertisingAPITest : public LeAdvertisingManagerTest {
        OpCode::LE_SET_ADVERTISING_DATA,
        OpCode::LE_SET_ADVERTISING_ENABLE,
    };
    auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
    std::vector<uint8_t> success_vector{static_cast<uint8_t>(ErrorCode::SUCCESS)};
    ASSERT_EQ(std::future_status::ready, result);
    for (size_t i = 0; i < adv_opcodes.size(); i++) {
      auto packet_view = test_hci_layer_->GetCommandPacket(adv_opcodes[i]);
      CommandPacketView command_packet_view = CommandPacketView::Create(packet_view);
      auto command = ConnectionManagementCommandView::Create(AclCommandView::Create(command_packet_view));
      test_hci_layer_->IncomingEvent(
          CommandCompleteBuilder::Create(uint8_t{1}, adv_opcodes[i], std::make_unique<RawBuilder>(success_vector)));
      test_hci_layer_->SetCommandFuture();
    }
    sync_client_handler();
    test_hci_layer_->ResetCommandFuture();
  }

  AdvertiserId advertiser_id_;
@@ -443,7 +461,7 @@ class LeExtendedAdvertisingAPITest : public LeExtendedAdvertisingManagerTest {
    advertising_config.channel_map = 1;
    advertising_config.sid = 0x01;

    auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
    test_hci_layer_->SetCommandFuture();
    advertiser_id_ = le_advertising_manager_->ExtendedCreateAdvertiser(
        0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
    ASSERT_NE(LeAdvertisingManager::kInvalidId, advertiser_id_);
@@ -456,9 +474,7 @@ class LeExtendedAdvertisingAPITest : public LeExtendedAdvertisingManagerTest {
        OpCode::LE_SET_EXTENDED_ADVERTISING_DATA,
        OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE,
    };
    auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
    std::vector<uint8_t> success_vector{static_cast<uint8_t>(ErrorCode::SUCCESS)};
    ASSERT_EQ(std::future_status::ready, result);
    for (size_t i = 0; i < adv_opcodes.size(); i++) {
      auto packet_view = test_hci_layer_->GetCommandPacket(adv_opcodes[i]);
      CommandPacketView command_packet_view = CommandPacketView::Create(packet_view);
@@ -470,8 +486,10 @@ class LeExtendedAdvertisingAPITest : public LeExtendedAdvertisingManagerTest {
        test_hci_layer_->IncomingEvent(
            CommandCompleteBuilder::Create(uint8_t{1}, adv_opcodes[i], std::make_unique<RawBuilder>(success_vector)));
      }
      test_hci_layer_->SetCommandFuture();
    }
    sync_client_handler();
    test_hci_layer_->ResetCommandFuture();
  }

  AdvertiserId advertiser_id_;
@@ -498,7 +516,7 @@ TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
  advertising_config.advertisement = gap_data;
  advertising_config.scan_response = gap_data;

  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
  test_hci_layer_->SetCommandFuture();
  auto id = le_advertising_manager_->ExtendedCreateAdvertiser(
      0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
  ASSERT_NE(LeAdvertisingManager::kInvalidId, id);
@@ -511,24 +529,20 @@ TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingSetStarted(0x00, id, 0x00, AdvertisingCallback::AdvertisingStatus::SUCCESS));

  std::vector<uint8_t> success_vector{static_cast<uint8_t>(ErrorCode::SUCCESS)};
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  for (size_t i = 0; i < adv_opcodes.size(); i++) {
    auto packet_view = test_hci_layer_->GetCommandPacket(adv_opcodes[i]);
    CommandPacketView command_packet_view = CommandPacketView::Create(packet_view);
    auto command = ConnectionManagementCommandView::Create(AclCommandView::Create(command_packet_view));
    test_hci_layer_->IncomingEvent(
        CommandCompleteBuilder::Create(uint8_t{1}, adv_opcodes[i], std::make_unique<RawBuilder>(success_vector)));
    test_hci_layer_->SetCommandFuture();
  }
  sync_client_handler();

  // Disable the advertiser
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
  le_advertising_manager_->RemoveAdvertiser(id);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_ADVERTISING_ENABLE);
  sync_client_handler();
}

@@ -590,7 +604,7 @@ TEST_F(LeExtendedAdvertisingManagerTest, create_advertiser_test) {
  advertising_config.channel_map = 1;
  advertising_config.sid = 0x01;

  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  test_hci_layer_->SetCommandFuture();
  auto id = le_advertising_manager_->ExtendedCreateAdvertiser(
      0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
  ASSERT_NE(LeAdvertisingManager::kInvalidId, id);
@@ -603,9 +617,7 @@ TEST_F(LeExtendedAdvertisingManagerTest, create_advertiser_test) {
      OpCode::LE_SET_EXTENDED_ADVERTISING_DATA,
      OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE,
  };
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  std::vector<uint8_t> success_vector{static_cast<uint8_t>(ErrorCode::SUCCESS)};
  ASSERT_EQ(std::future_status::ready, result);
  for (size_t i = 0; i < adv_opcodes.size(); i++) {
    auto packet_view = test_hci_layer_->GetCommandPacket(adv_opcodes[i]);
    CommandPacketView command_packet_view = CommandPacketView::Create(packet_view);
@@ -617,14 +629,17 @@ TEST_F(LeExtendedAdvertisingManagerTest, create_advertiser_test) {
      test_hci_layer_->IncomingEvent(
          CommandCompleteBuilder::Create(uint8_t{1}, adv_opcodes[i], std::make_unique<RawBuilder>(success_vector)));
    }
    test_hci_layer_->SetCommandFuture();
  }
  sync_client_handler();

  // Remove the advertiser
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_REMOVE_ADVERTISING_SET);
  le_advertising_manager_->RemoveAdvertiser(id);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_REMOVE_ADVERTISING_SET);
  sync_client_handler();
}

@@ -643,10 +658,9 @@ TEST_F(LeAdvertisingAPITest, set_parameter) {
  gap_data.push_back(data_item);
  advertising_config.advertisement = gap_data;
  advertising_config.channel_map = 1;
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetParameters(advertiser_id_, advertising_config);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_PARAMETERS);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_ADVERTISING_PARAMETERS);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingParametersUpdated(advertiser_id_, 0x00, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -667,10 +681,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_parameter) {
  advertising_config.channel_map = 1;
  advertising_config.sid = 0x01;
  advertising_config.tx_power = 0x08;
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetParameters(advertiser_id_, advertising_config);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingParametersUpdated(advertiser_id_, 0x08, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -686,10 +699,9 @@ TEST_F(LeAdvertisingAPITest, set_data_test) {
  data_item.data_type_ = GapDataType::TX_POWER_LEVEL;
  data_item.data_ = {0x00};
  advertising_data.push_back(data_item);
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetData(advertiser_id_, false, advertising_data);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_DATA);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_ADVERTISING_DATA);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingDataSet(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -702,10 +714,9 @@ TEST_F(LeAdvertisingAPITest, set_data_test) {
  data_item2.data_type_ = GapDataType::COMPLETE_LOCAL_NAME;
  data_item2.data_ = {'t', 'e', 's', 't', ' ', 'd', 'e', 'v', 'i', 'c', 'e'};
  response_data.push_back(data_item2);
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetData(advertiser_id_, true, response_data);
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_SCAN_RESPONSE_DATA);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_SCAN_RESPONSE_DATA);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnScanResponseDataSet(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -720,10 +731,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_data_test) {
  data_item.data_type_ = GapDataType::TX_POWER_LEVEL;
  data_item.data_ = {0x00};
  advertising_data.push_back(data_item);
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetData(advertiser_id_, false, advertising_data);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingDataSet(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -736,10 +746,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_data_test) {
  data_item2.data_type_ = GapDataType::COMPLETE_LOCAL_NAME;
  data_item2.data_ = {'t', 'e', 's', 't', ' ', 'd', 'e', 'v', 'i', 'c', 'e'};
  response_data.push_back(data_item2);
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetData(advertiser_id_, true, response_data);
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnScanResponseDataSet(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -764,19 +773,16 @@ TEST_F(LeExtendedAdvertisingAPITest, set_data_fragments_test) {
  le_advertising_manager_->SetData(advertiser_id_, false, advertising_data);

  // First fragment
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);

  // Intermediate fragment
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);

  // Last fragment
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA);

  EXPECT_CALL(
      mock_advertising_callback_,
@@ -804,19 +810,16 @@ TEST_F(LeExtendedAdvertisingAPITest, set_scan_response_fragments_test) {
  le_advertising_manager_->SetData(advertiser_id_, true, advertising_data);

  // First fragment
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);

  // Intermediate fragment
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);

  // Last fragment
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE);

  EXPECT_CALL(
      mock_advertising_callback_,
@@ -886,10 +889,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_data_with_invalid_length) {

TEST_F(LeAdvertisingAPITest, disable_enable_advertiser_test) {
  // disable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnableAdvertiser(advertiser_id_, false, 0x00, 0x00);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingEnabled(advertiser_id_, false, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -897,10 +899,9 @@ TEST_F(LeAdvertisingAPITest, disable_enable_advertiser_test) {
  sync_client_handler();

  // enable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnableAdvertiser(advertiser_id_, true, 0x00, 0x00);
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingEnabled(advertiser_id_, true, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -910,10 +911,9 @@ TEST_F(LeAdvertisingAPITest, disable_enable_advertiser_test) {

TEST_F(LeExtendedAdvertisingAPITest, disable_enable_advertiser_test) {
  // disable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnableAdvertiser(advertiser_id_, false, 0x00, 0x00);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingEnabled(advertiser_id_, false, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -921,10 +921,9 @@ TEST_F(LeExtendedAdvertisingAPITest, disable_enable_advertiser_test) {
  sync_client_handler();

  // enable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnableAdvertiser(advertiser_id_, true, 0x00, 0x00);
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingEnabled(advertiser_id_, true, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -936,11 +935,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_periodic_parameter) {
  PeriodicAdvertisingParameters advertising_config{};
  advertising_config.max_interval = 0x1000;
  advertising_config.min_interval = 0x0006;
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetPeriodicParameters(advertiser_id_, advertising_config);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_PERIODIC_ADVERTISING_PARAM);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);

  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_PERIODIC_ADVERTISING_PARAM);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnPeriodicAdvertisingParametersUpdated(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -955,10 +952,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_periodic_data_test) {
  data_item.data_type_ = GapDataType::TX_POWER_LEVEL;
  data_item.data_ = {0x00};
  advertising_data.push_back(data_item);
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->SetPeriodicData(advertiser_id_, advertising_data);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_PERIODIC_ADVERTISING_DATA);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_PERIODIC_ADVERTISING_DATA);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnPeriodicAdvertisingDataSet(advertiser_id_, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -968,10 +964,9 @@ TEST_F(LeExtendedAdvertisingAPITest, set_periodic_data_test) {

TEST_F(LeExtendedAdvertisingAPITest, disable_enable_periodic_advertiser_test) {
  // disable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnablePeriodicAdvertising(advertiser_id_, false);
  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE);
  auto result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnPeriodicAdvertisingEnabled(advertiser_id_, false, AdvertisingCallback::AdvertisingStatus::SUCCESS));
@@ -979,10 +974,9 @@ TEST_F(LeExtendedAdvertisingAPITest, disable_enable_periodic_advertiser_test) {
  sync_client_handler();

  // enable advertiser
  test_hci_layer_->SetCommandFuture();
  le_advertising_manager_->EnablePeriodicAdvertising(advertiser_id_, true);
  last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE);
  result = last_command_future.wait_for(std::chrono::duration(std::chrono::milliseconds(100)));
  ASSERT_EQ(std::future_status::ready, result);
  test_hci_layer_->GetCommandPacket(OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE);
  EXPECT_CALL(
      mock_advertising_callback_,
      OnPeriodicAdvertisingEnabled(advertiser_id_, true, AdvertisingCallback::AdvertisingStatus::SUCCESS));