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

Commit 54cb514c authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

le_audio: Fix flaky audio hal client test

Sometimes the test takes a bit longer than usually and the periodic
audio data reading function runs twice. This fixes the following error
caused by improper mocking of periodically called function:

GMOCK WARNING:
packages/modules/Bluetooth/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc:465:
Actions ran out in EXPECT_CALL(mock_hal_interface_audio_sink_, Read(_,
_))...
Called 2 times, but only 1 WillOnce() is specified - returning default
value.
Stack trace:
packages/modules/Bluetooth/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc:486:
Failure
Mock function called more times than expected - returning directly.
    Function call: OnAudioDataReady(@0x7ba4429c66a0 { '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', ... })
             Expected: to be called once
	                Actual: called twice - over-saturated and active

Bug: 264033479
Tag: #feature
Test: atest --host LeAudioClientAudioTest#testAudioHalClientResumeStartSourceTask --no-bazel-mode --rerun-until-failure 10000
Change-Id: If489eebeb4a5f97c86715aa068508dd32e05c266
Merged-In: If489eebeb4a5f97c86715aa068508dd32e05c266
(cherry picked from commit 77e3ec27)
parent 54bac4f2
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ using ::testing::_;
using ::testing::Assign;
using ::testing::Assign;
using ::testing::AtLeast;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::DoAll;
using ::testing::DoDefault;
using ::testing::Invoke;
using ::testing::Invoke;
using ::testing::Mock;
using ::testing::Mock;
using ::testing::Return;
using ::testing::Return;
@@ -476,6 +477,13 @@ TEST_F(LeAudioClientAudioTest, testAudioHalClientResumeStartSourceTask) {
        // Return exactly as much data as requested
        // Return exactly as much data as requested
        promise.set_value();
        promise.set_value();
        return len;
        return len;
      }))
      .WillRepeatedly(Invoke([](uint8_t* p_buf, uint32_t len) -> uint32_t {
        // fake some data from audio framework
        for (uint32_t i = 0u; i < len; ++i) {
          p_buf[i] = i;
        }
        return len;
      }));
      }));


  std::promise<void> data_promise;
  std::promise<void> data_promise;
@@ -484,10 +492,12 @@ TEST_F(LeAudioClientAudioTest, testAudioHalClientResumeStartSourceTask) {
  /* Expect this callback to be called to Client by the HAL glue layer */
  /* Expect this callback to be called to Client by the HAL glue layer */
  std::vector<uint8_t> media_data_to_send;
  std::vector<uint8_t> media_data_to_send;
  EXPECT_CALL(mock_hal_sink_event_receiver_, OnAudioDataReady(_))
  EXPECT_CALL(mock_hal_sink_event_receiver_, OnAudioDataReady(_))
      .Times(AtLeast(1))
      .WillOnce(Invoke([&](const std::vector<uint8_t>& data) -> void {
      .WillOnce(Invoke([&](const std::vector<uint8_t>& data) -> void {
        media_data_to_send = std::move(data);
        media_data_to_send = std::move(data);
        data_promise.set_value();
        data_promise.set_value();
      }));
      }))
      .WillRepeatedly(DoDefault());


  /* Expect LeAudio registered event listener to get called when HAL calls the
  /* Expect LeAudio registered event listener to get called when HAL calls the
   * audio_hal_client's internal resume callback.
   * audio_hal_client's internal resume callback.