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

Commit 7f7d2a39 authored by Myles Watson's avatar Myles Watson Committed by android-build-merger
Browse files

Merge changes I7f8b5cfd,I68d65028

am: 3337f902

Change-Id: I00f505eb8b71e21e6a2bc778e41ee9a0f8e35fc3
parents 37520cfc 3337f902
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -68,6 +68,17 @@ COVERAGE_TESTS = [
        "covered_files": [
            "packages/modules/Bluetooth/system/profile/sdp",
        ],
    }, {
        "test_name": "test-vendor_test_host",
        "covered_files": [
            "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/include",
            "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/src",
        ],
    }, {
        "test_name": "rootcanal-packets_test_host",
        "covered_files": [
            "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/packets",
        ],
    },
]

+12 −3
Original line number Diff line number Diff line
@@ -35,7 +35,10 @@ cc_library_static {
    local_include_dirs: [
        "include",
    ],
    export_include_dirs: ["include"],
    export_include_dirs: [
        "include",
        ".",
    ],
    header_libs: [
        "libbluetooth_headers",
    ],
@@ -52,14 +55,19 @@ cc_library_static {
    ],
    static_libs: [
        "libbluetooth-types",
    ]
        "libbt-rootcanal-packets",
    ],
}

// test-vendor unit tests for host
// ========================================================
cc_test_host {
    name: "test-vendor_test_host",
    defaults: ["libchrome_support_defaults"],
    defaults: [
        "libchrome_support_defaults",
        "clang_file_coverage",
        "clang_coverage_bin",
    ],
    srcs: [
        "src/async_manager.cc",
        "src/bt_address.cc",
@@ -94,6 +102,7 @@ cc_test_host {
    ],
    static_libs: [
        "libbluetooth-types",
        "libbt-rootcanal-packets",
    ],
    cflags: [
        "-fvisibility=hidden",
+65 −0
Original line number Diff line number Diff line
// packet library for libbt-rootcanal
// ========================================================
cc_library_static {
    name: "libbt-rootcanal-packets",
    defaults: [
        "libchrome_support_defaults",
        "clang_file_coverage",
    ],
    host_supported: true,
    proprietary: true,
    srcs: [
        "iterator.cc",
        "packet_view.cc",
        "view.cc",
    ],
    cflags: [
        "-fvisibility=hidden",
    ],
    local_include_dirs: [
        ".",
    ],
    export_include_dirs: ["."],
    include_dirs: [
        "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/include",
        "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/",
        "packages/modules/Bluetooth/system/",
    ],
    shared_libs: [
        "libbase",
        "liblog",
    ],
}

// Unit tests for the host
// ========================================================
cc_test_host {
    name: "rootcanal-packets_test_host",
    defaults: [
        "libchrome_support_defaults",
        "clang_file_coverage",
        "clang_coverage_bin",
    ],
    srcs: [
        "test/packet_view_test.cc",
    ],
    header_libs: [
        "libbluetooth_headers",
    ],
    local_include_dirs: [
        ".",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/hci/include",
        "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib",
        "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/include",
    ],
    shared_libs: [
        "liblog",
    ],
    static_libs: [
        "libbluetooth-types",
        "libbt-rootcanal-packets",
    ],
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>
#include <forward_list>
#include <iterator>
#include <memory>
#include <vector>

namespace test_vendor_lib {
namespace packets {

// A little-endian PacketBuilder might contain a big-endian PacketBuilder,
// so BasePacketBuilder provides a common base class.
class BasePacketBuilder {
 public:
  virtual ~BasePacketBuilder() = default;

  virtual size_t size() const = 0;

  // Write to the vector with the given iterator.
  virtual void Serialize(
      std::back_insert_iterator<std::vector<uint8_t>> it) const = 0;

 protected:
  BasePacketBuilder() = default;
};

}  // namespace packets
}  // namespace test_vendor_lib
+168 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "iterator.h"

#include <base/logging.h>

namespace test_vendor_lib {
namespace packets {

template <bool little_endian>
Iterator<little_endian>::Iterator(std::forward_list<View> data, size_t offset) {
  data_ = data;
  index_ = offset;
  length_ = 0;
  for (auto& view : data) {
    length_ += view.size();
  }
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator+(int offset) {
  auto itr(*this);

  return itr += offset;
}

template <bool little_endian>
Iterator<little_endian>& Iterator<little_endian>::operator+=(int offset) {
  index_ += offset;
  return *this;
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator++(int) {
  auto itr(*this);
  index_++;
  return itr;
}

template <bool little_endian>
Iterator<little_endian>& Iterator<little_endian>::operator++() {
  index_++;
  return *this;
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator-(int offset) {
  auto itr(*this);

  return itr -= offset;
}

template <bool little_endian>
int Iterator<little_endian>::operator-(Iterator<little_endian>& itr) {
  return index_ - itr.index_;
}

template <bool little_endian>
Iterator<little_endian>& Iterator<little_endian>::operator-=(int offset) {
  index_ -= offset;

  return *this;
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator--(int) {
  auto itr(*this);
  if (index_ != 0) index_--;

  return itr;
}

template <bool little_endian>
Iterator<little_endian>& Iterator<little_endian>::operator--() {
  if (index_ != 0) index_--;

  return *this;
}

template <bool little_endian>
Iterator<little_endian>& Iterator<little_endian>::operator=(
    const Iterator<little_endian>& itr) {
  data_ = itr.data_;
  index_ = itr.index_;

  return *this;
}

template <bool little_endian>
bool Iterator<little_endian>::operator==(
    const Iterator<little_endian>& itr) const {
  return index_ == itr.index_;
}

template <bool little_endian>
bool Iterator<little_endian>::operator!=(
    const Iterator<little_endian>& itr) const {
  return !(*this == itr);
}

template <bool little_endian>
bool Iterator<little_endian>::operator<(
    const Iterator<little_endian>& itr) const {
  return index_ < itr.index_;
}

template <bool little_endian>
bool Iterator<little_endian>::operator>(
    const Iterator<little_endian>& itr) const {
  return index_ > itr.index_;
}

template <bool little_endian>
bool Iterator<little_endian>::operator<=(
    const Iterator<little_endian>& itr) const {
  return index_ <= itr.index_;
}

template <bool little_endian>
bool Iterator<little_endian>::operator>=(
    const Iterator<little_endian>& itr) const {
  return index_ >= itr.index_;
}

template <bool little_endian>
uint8_t Iterator<little_endian>::operator*() const {
  CHECK(index_ < length_) << "Index " << index_
                          << " out of bounds: " << length_;
  size_t index = index_;

  for (auto view : data_) {
    if (index < view.size()) {
      return view[index];
    }
    index -= view.size();
  }
  CHECK(false) << "Out of fragments searching for Index " << index_;
  return 0;
}

template <bool little_endian>
size_t Iterator<little_endian>::NumBytesRemaining() const {
  if (length_ > index_) {
    return length_ - index_;
  } else {
    return 0;
  }
}

// Explicit instantiations for both types of Iterators.
template class Iterator<true>;
template class Iterator<false>;
}  // namespace packets
}  // namespace test_vendor_lib
Loading