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

Commit 4142d089 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Gerrit Code Review
Browse files

Merge "LeAudio: Fix flaky unit tests" into main

parents 46dabbd1 eeafe9a5
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -108,12 +108,16 @@ extern "C" const char* __asan_default_options() {
}

std::atomic<int> num_async_tasks;
static base::MessageLoop* message_loop_;
bluetooth::common::MessageLoopThread message_loop_thread("test message loop");
bluetooth::common::MessageLoopThread* get_main_thread() {
  return &message_loop_thread;
}

bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task) {
  if (!message_loop_) return BT_STATUS_FAIL;

  // Wrap the task with task counter so we could later know if there are
  // any callbacks scheduled and we should wait before performing some actions
  if (!message_loop_thread.DoInThread(
@@ -138,7 +142,6 @@ bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
  return do_in_main_thread(from_here, std::move(task));
}

static base::MessageLoop* message_loop_;
base::MessageLoop* get_main_message_loop() { return message_loop_; }

static void init_message_loop_thread() {
@@ -527,6 +530,7 @@ class UnicastTestNoInit : public Test {
                                   AudioContexts source_ctxs) {
    /* 0x0077 pacs->supp_contexts_char + 1 */
    InjectContextTypes(test_address, conn_id, 0x0077, sink_ctxs, source_ctxs);
    SyncOnMainLoop();
  }

  void InjectAvailableContextTypes(const RawAddress& test_address,
@@ -534,6 +538,7 @@ class UnicastTestNoInit : public Test {
                                   AudioContexts source_ctxs) {
    /* 0x0074 is pacs->avail_contexts_char + 1 */
    InjectContextTypes(test_address, conn_id, 0x0074, sink_ctxs, source_ctxs);
    SyncOnMainLoop();
  }

  void SetUpMockGatt() {
@@ -3956,7 +3961,6 @@ TEST_F(UnicastTest, HandleResumeWithoutMetadataUpdateOnLocalSink) {
  auto source_available_context = types::kLeAudioContextAllRemoteSource;
  InjectAvailableContextTypes(test_address0, 1, sink_available_context,
                              source_available_context);
  SyncOnMainLoop();

  StopStreaming(group_id, true);
  SyncOnMainLoop();
@@ -5715,7 +5719,6 @@ TEST_F(UnicastTest, TwoEarbuds2ndReleaseAseRemoveAvailableContextAndBack) {
  /* Simulate available context type being cleared */
  InjectAvailableContextTypes(device->address_, device->conn_id_,
                              types::AudioContexts(0), types::AudioContexts(0));
  SyncOnMainLoop();

  /* Simulate ASE releasing and CIS Disconnection */
  for (auto& ase : device->ases_) {
@@ -5742,7 +5745,6 @@ TEST_F(UnicastTest, TwoEarbuds2ndReleaseAseRemoveAvailableContextAndBack) {
  InjectAvailableContextTypes(device->address_, device->conn_id_,
                              types::kLeAudioContextAllTypes,
                              types::kLeAudioContextAllTypes);
  SyncOnMainLoop();

  /* Check both devices are streaming */
  cis_count_out = 2;
@@ -5810,10 +5812,8 @@ TEST_F(UnicastTest, StartStream_AvailableContextTypeNotifiedLater) {
      .Times(1);

  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);

  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_le_audio_source_hal_client_);
  SyncOnMainLoop();

  // Expect two iso channel to be fed with data
  uint8_t cis_count_out = 2;
@@ -5906,7 +5906,6 @@ TEST_F(UnicastTest, ModifyContextTypeOnDeviceA_WhileDeviceB_IsDisconnected) {
                              source_supported_context);
  InjectAvailableContextTypes(test_address0, 1, sink_supported_context,
                              source_supported_context);
  SyncOnMainLoop();

  /* Android starts stream. */
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(0);
@@ -6190,8 +6189,6 @@ TEST_F(UnicastTest, StartStreamToSupportedContextTypeThenMixUnavailable) {
  InjectAvailableContextTypes(test_address1, 2, sink_supported_context,
                              source_supported_context);

  SyncOnMainLoop();

  // Verify cache has been removed due to available context change
  ASSERT_FALSE(group
                   ->GetCachedCodecConfigurationByDirection(