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

Commit 65fda17a authored by Ryan Prichard's avatar Ryan Prichard Committed by Automerger Merge Worker
Browse files

Merge "Remove LogCapture::WaitUntilLogContains async usage" into main am:...

Merge "Remove LogCapture::WaitUntilLogContains async usage" into main am: ad8d4ac9 am: 55cb032a am: ac8f5724 am: 5953e078

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



Change-Id: I1b37cd22c3ba197bda4731aca38029383daca0c1
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 07e7d851 5953e078
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ LogCapture* LogCapture::Rewind() {
  return this;
}

bool LogCapture::Find(std::string to_find) {
bool LogCapture::Find(const std::string& to_find) {
  // For |atest| assume all log captures succeed
  return true;
}
@@ -63,10 +63,7 @@ size_t LogCapture::Size() const {
  return size;
}

void LogCapture::WaitUntilLogContains(std::promise<void>* promise, std::string text) {
  std::async([promise, text]() { promise->set_value(); });
  promise->get_future().wait();
}
void LogCapture::WaitUntilLogContains(const std::string& text) {}

std::pair<int, int> LogCapture::create_backing_store() const {
  int dup_fd = -1;
+6 −10
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ LogCapture* LogCapture::Rewind() {
  return this;
}

bool LogCapture::Find(std::string to_find) {
bool LogCapture::Find(const std::string& to_find) {
  std::string str = this->Read();
  return str.find(to_find) != std::string::npos;
}
@@ -135,15 +135,11 @@ size_t LogCapture::Size() const {
  return size;
}

void LogCapture::WaitUntilLogContains(std::promise<void>* promise, std::string text) {
  std::async([this, promise, text]() {
void LogCapture::WaitUntilLogContains(const std::string& text) {
  bool found = false;
  do {
    found = this->Rewind()->Find(text);
  } while (!found);
    promise->set_value();
  });
  promise->get_future().wait();
}

std::pair<int, int> LogCapture::create_backing_store() const {
+1 −2
Original line number Diff line number Diff line
@@ -146,8 +146,7 @@ TEST_F(LogCaptureTest, DISABLED_wait_until_log_contains) {
  std::unique_ptr<LogCapture> log_capture = std::make_unique<LogCapture>();

  LOG_DEBUG("%s", kLogDebug);
  std::promise<void> promise;
  log_capture->WaitUntilLogContains(&promise, kLogDebug);
  log_capture->WaitUntilLogContains(kLogDebug);
  bluetooth::common::InitFlags::Load(nullptr);
}

+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class LogCapture {
  LogCapture* Rewind();
  // Searches from filepointer to end of file for |to_find| string
  // Returns true if found, false otherwise
  bool Find(std::string to_find);
  bool Find(const std::string& to_find);
  // Reads and returns the entirety of the backing store into a string
  std::string Read();
  // Flushes contents of log capture back to |stderr|
@@ -43,7 +43,7 @@ class LogCapture {
  // Truncates and resets the file pointer discarding all logs up to this point
  void Reset();
  // Wait until the provided string shows up in the logs
  void WaitUntilLogContains(std::promise<void>* promise, std::string text);
  void WaitUntilLogContains(const std::string& text);

 private:
  std::pair<int, int> create_backing_store() const;
+4 −11
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@

#include <cstdint>
#include <fstream>
#include <future>
#include <iomanip>
#include <map>
#include <string>
@@ -171,9 +170,7 @@ TEST_F(A2dpAacTest, a2dp_source_read_underflow) {
  usleep(kA2dpTickUs);
  timestamp_us = bluetooth::common::time_gettimeofday_us();
  encoder_iface_->send_frames(timestamp_us);
  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise,
                                     "a2dp_aac_encode_frames: underflow");
  log_capture_->WaitUntilLogContains("a2dp_aac_encode_frames: underflow");
}

TEST_F(A2dpAacTest, a2dp_enqueue_cb_is_invoked) {
@@ -193,8 +190,7 @@ TEST_F(A2dpAacTest, a2dp_enqueue_cb_is_invoked) {
  usleep(kA2dpTickUs);
  timestamp_us = bluetooth::common::time_gettimeofday_us();
  encoder_iface_->send_frames(timestamp_us);
  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise, kEnqueueCallbackIsInvoked);
  log_capture_->WaitUntilLogContains(kEnqueueCallbackIsInvoked);
}

TEST_F(A2dpAacTest, decoded_data_cb_not_invoked_when_empty_packet) {
@@ -232,8 +228,7 @@ TEST_F(A2dpAacTest, decoded_data_cb_invoked) {
  timestamp_us = bluetooth::common::time_gettimeofday_us();
  encoder_iface_->send_frames(timestamp_us);

  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise, kEnqueueCallbackIsInvoked);
  log_capture_->WaitUntilLogContains(kEnqueueCallbackIsInvoked);
  decoder_iface_->decode_packet(packet);
  osi_free(packet);
  ASSERT_TRUE(log_capture_->Find(kDecodedDataCallbackIsInvoked));
@@ -282,9 +277,7 @@ TEST_F(A2dpAacTest, effective_mtu_when_peer_does_not_support_3mbps) {
TEST_F(A2dpAacTest, debug_codec_dump) {
  log_capture_ = std::make_unique<LogCapture>();
  a2dp_codecs_->debug_codec_dump(2);
  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise,
                                     "Current Codec: AAC");
  log_capture_->WaitUntilLogContains("Current Codec: AAC");
}

TEST_F(A2dpAacTest, codec_info_string) {
Loading