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

Commit d8717fce authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Ib334609b,Ic94f70fc

* changes:
  [GD ACL] Add btsnooz support in GD
  GD-Common: Add CircularBuffer::Drain() method
parents 08be8de5 1e35fd75
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
                        "--grpc-port=$(grpc_port)",
                        "--root-server-port=$(grpc_root_server_port)",
                        "--btsnoop=/data/misc/bluetooth/logs/btsnoop_hci.log",
                        "--btsnooz=/data/misc/bluetooth/logs/btsnooz_hci.log",
                        "--btconfig=/data/misc/bluedroid/bt_config.conf",
                        "--signal-port=$(signal_port)"
                    ]
@@ -44,6 +45,7 @@
                        "--grpc-port=$(grpc_port)",
                        "--root-server-port=$(grpc_root_server_port)",
                        "--btsnoop=/data/misc/bluetooth/logs/btsnoop_hci.log",
                        "--btsnooz=/data/misc/bluetooth/logs/btsnooz_hci.log",
                        "--btconfig=/data/misc/bluedroid/bt_config.conf",
                        "--signal-port=$(signal_port)"
                    ]
+9 −2
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ class GdDeviceBase(ABC):
                                                     '%s_%s_backing_logs.txt' % (self.type_identifier, self.label))
        if "--btsnoop=" not in " ".join(cmd):
            cmd.append("--btsnoop=%s" % os.path.join(self.log_path_base, '%s_btsnoop_hci.log' % self.label))
        if "--btsnooz=" not in " ".join(cmd):
            cmd.append("--btsnooz=%s" % os.path.join(self.log_path_base, '%s_btsnooz_hci.log' % self.label))
        if "--btconfig=" not in " ".join(cmd):
            cmd.append("--btconfig=%s" % os.path.join(self.log_path_base, '%s_bt_config.conf' % self.label))
        self.cmd = cmd
@@ -424,15 +426,20 @@ class GdAndroidDevice(GdDeviceBase):
        except AdbCommandError as error:
            logging.error("Error during setup: " + str(error))

        try:
            self.adb.shell("rm /data/misc/bluetooth/logs/btsnooz_hci.log")
        except AdbCommandError as error:
            logging.error("Error during setup: " + str(error))

        try:
            self.adb.shell("rm /data/misc/bluedroid/bt_config.conf")
        except AdbCommandError as error:
            logging.error("Error during cleanup: " + str(error))
            logging.error("Error during setup: " + str(error))

        try:
            self.adb.shell("rm /data/misc/bluedroid/bt_config.bak")
        except AdbCommandError as error:
            logging.error("Error during cleanup: " + str(error))
            logging.error("Error during setup: " + str(error))

        self.ensure_no_output(self.adb.shell("svc bluetooth disable"))

+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ filegroup {
        "blocking_queue_unittest.cc",
        "bidi_queue_unittest.cc",
        "byte_array_test.cc",
        "circular_buffer_test.cc",
        "observer_registry_test.cc",
        "init_flags_test.cc",
        "list_map_test.cc",
+20 −6
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

#pragma once

#include <stddef.h>

#include <cstddef>
#include <iterator>
#include <mutex>
#include <queue>

@@ -29,8 +29,12 @@ class CircularBuffer {
 public:
  explicit CircularBuffer(size_t size);

  // Push one item to the circular buffer
  void Push(T item);
  // Take a snapshot of the circular buffer and return it as a vector
  std::vector<T> Pull() const;
  // Drain everything from the circular buffer and return them as a vector
  std::vector<T> Drain();

 private:
  const size_t size_;
@@ -67,6 +71,7 @@ class TimestampedCircularBuffer : public CircularBuffer<TimestampedEntry<T>> {

  void Push(T item);
  std::vector<TimestampedEntry<T>> Pull() const;
  std::vector<TimestampedEntry<T>> Drain();

 private:
  std::unique_ptr<Timestamper> timestamper_{std::make_unique<TimestamperInMilliseconds>()};
@@ -90,10 +95,14 @@ void bluetooth::common::CircularBuffer<T>::Push(const T item) {
template <typename T>
std::vector<T> bluetooth::common::CircularBuffer<T>::Pull() const {
  std::unique_lock<std::mutex> lock(mutex_);
  std::vector<T> items;
  for (auto it = queue_.cbegin(); it != queue_.cend(); ++it) {
    items.push_back(*it);
  return std::vector<T>(queue_.cbegin(), queue_.cend());
}

template <typename T>
std::vector<T> bluetooth::common::CircularBuffer<T>::Drain() {
  std::unique_lock<std::mutex> lock(mutex_);
  std::vector<T> items(std::make_move_iterator(queue_.begin()), std::make_move_iterator(queue_.end()));
  queue_.clear();
  return items;
}

@@ -113,3 +122,8 @@ std::vector<struct bluetooth::common::TimestampedEntry<T>> bluetooth::common::Ti
    const {
  return bluetooth::common::CircularBuffer<TimestampedEntry<T>>::Pull();
}

template <typename T>
std::vector<struct bluetooth::common::TimestampedEntry<T>> bluetooth::common::TimestampedCircularBuffer<T>::Drain() {
  return bluetooth::common::CircularBuffer<TimestampedEntry<T>>::Drain();
}
+22 −0
Original line number Diff line number Diff line
@@ -43,6 +43,28 @@ TEST(CircularBufferTest, simple) {
  ASSERT_STREQ("One", vec[0].entry.c_str());
  ASSERT_STREQ("Two", vec[1].entry.c_str());
  ASSERT_STREQ("Three", vec[2].entry.c_str());

  auto vec2 = buffer.Pull();

  ASSERT_FALSE(vec2.empty());
}

TEST(CircularBufferTest, simple_drain) {
  bluetooth::common::TimestampedCircularBuffer<std::string> buffer(10);

  buffer.Push(std::string("One"));
  buffer.Push(std::string("Two"));
  buffer.Push(std::string("Three"));

  auto vec = buffer.Drain();

  ASSERT_STREQ("One", vec[0].entry.c_str());
  ASSERT_STREQ("Two", vec[1].entry.c_str());
  ASSERT_STREQ("Three", vec[2].entry.c_str());

  auto vec2 = buffer.Pull();

  ASSERT_TRUE(vec2.empty());
}

TEST(CircularBufferTest, test_timestamps) {
Loading