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

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

Merge "leaudio: Add unit test to prove working scenario" into main am: 12dc5c43 am: 74adc155

parents 3a1f9491 74adc155
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
@@ -6793,6 +6793,82 @@ TEST_F(UnicastTest, UpdateMultipleBidirContextTypes) {
  SyncOnMainLoop();
}

TEST_F(UnicastTest, UpdateDisableLocalAudioSinkOnGame) {
  const RawAddress test_address0 = GetTestAddress(0);
  int group_id = bluetooth::groups::kGroupUnknown;

  available_snk_context_types_ =
      (types::LeAudioContextType::CONVERSATIONAL |
       types::LeAudioContextType::GAME | types::LeAudioContextType::LIVE)
          .value();
  supported_snk_context_types_ =
      available_snk_context_types_ |
      types::AudioContexts(types::LeAudioContextType::UNSPECIFIED).value();
  available_src_context_types_ = available_snk_context_types_;
  supported_src_context_types_ =
      available_src_context_types_ |
      types::AudioContexts(types::LeAudioContextType::UNSPECIFIED).value();

  SetSampleDatabaseEarbudsValid(
      1, test_address0, codec_spec_conf::kLeAudioLocationAnyLeft,
      codec_spec_conf::kLeAudioLocationStereo, default_channel_cnt,
      default_channel_cnt, 0x0024, false /*add_csis*/, true /*add_cas*/,
      true /*add_pacs*/, default_ase_cnt /*add_ascs_cnt*/, 1 /*set_size*/,
      0 /*rank*/);
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnConnectionState(ConnectionState::CONNECTED, test_address0))
      .Times(1);
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnGroupNodeStatus(test_address0, _, GroupNodeStatus::ADDED))
      .WillOnce(DoAll(SaveArg<1>(&group_id)));

  ConnectLeAudio(test_address0);
  ASSERT_NE(group_id, bluetooth::groups::kGroupUnknown);

  // Audio sessions are started only when device gets active
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_sink_hal_client_, Start(_, _)).Times(1);
  LeAudioClient::Get()->GroupSetActive(group_id);
  SyncOnMainLoop();

  // Start GAME stream
  types::BidirectionalPair<types::AudioContexts> contexts = {
      .sink = types::AudioContexts(types::LeAudioContextType::GAME),
      .source = types::AudioContexts(types::LeAudioContextType::GAME)};
  EXPECT_CALL(
      mock_state_machine_,
      StartStream(_, le_audio::types::LeAudioContextType::GAME, contexts, _))
      .Times(1);

  // 1) Start the recording. Sink resume will trigger the reconfiguration
  // ---------------------------------------------------------------------
  StartStreaming(AUDIO_USAGE_GAME, AUDIO_CONTENT_TYPE_MUSIC, group_id,
                 AUDIO_SOURCE_MIC);

  SyncOnMainLoop();

  Mock::VerifyAndClearExpectations(&mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(&mock_le_audio_sink_hal_client_);
  Mock::VerifyAndClearExpectations(&mock_state_machine_);

  // Verify Data transfer on one audio source and sink cis
  uint8_t cis_count_out = 1;
  uint8_t cis_count_in = 1;
  TestAudioDataTransfer(group_id, cis_count_out, cis_count_in, 1920, 40);

  SyncOnMainLoop();

  // 2) Now Lets suspend MIC and do not expect reconfiguration
  // -----------------------------------------------------------------

  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(0);
  LocalAudioSinkSuspend();
  // simulate suspend timeout passed, alarm executing
  fake_osi_alarm_set_on_mloop_.cb(fake_osi_alarm_set_on_mloop_.data);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
}

/* Start music when in a call, end the call, continue with music only */
TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  const RawAddress test_address0 = GetTestAddress(0);