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

Commit 2c3d7eb9 authored by Dennis Cheng's avatar Dennis Cheng Committed by Arman Uguray
Browse files

test_vendor_lib: Add tests

This upload adds unit tests for the packet_stream and hci_transport
objects.

Bug: 21586676
Change-Id: Ica99be959cdd801ea10631d31fc0f0b8ea1d8456
parent 303fb245
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -36,3 +36,34 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := SHARED_LIBRARIES

include $(BUILD_SHARED_LIBRARY)

ifeq ($(HOST_OS), linux)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    src/command_packet.cc \
    src/event_packet.cc \
    src/hci_transport.cc \
    src/packet.cc \
    src/packet_stream.cc \
    test/hci_transport_unittest.cc \
    test/packet_stream_unittest.cc

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include \
    $(BT_DIR) \
    $(BT_DIR)/hci/include \
    $(BT_DIR)/osi/include \
    $(BT_DIR)/stack/include

LOCAL_SHARED_LIBRARIES := \
    liblog \
    libchrome-host

LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS += -std=c++11
LOCAL_MODULE := test-vendor_test_host
LOCAL_MODULE_TAGS := tests

include $(BUILD_HOST_NATIVE_TEST)
endif
+33 −4
Original line number Diff line number Diff line
@@ -2,11 +2,13 @@ shared_library("test_vendor_lib") {
  sources = [
    "src/bt_vendor.cc",
    "src/command_packet.cc",
    "src/dual_mode__controller.cc",
    "src/dual_mode_controller.cc",
    "src/event_packet.cc",
    "src/hci_transport.cc",
    "src/packet.cc",
    "src/packet_stream.cc",
    "src/test_channel_transport.cc",
    "src/vendor_manager.cc",
  ]

  include_dirs = [
@@ -17,10 +19,37 @@ shared_library("test_vendor_lib") {
    "//osi/include",
    "//stack/include",
  ]
}

executable("test_vendor_lib_test") {
  testonly = true
  sources = [
    "src/command_packet.cc",
    "src/event_packet.cc",
    "src/packet.cc",
    "src/packet_stream.cc",
    "test/hci_transport_unittest.cc",
    "test/packet_stream_unittest.cc",
  ]

  include_dirs = [
    "include",
    "//",
    "//btcore/include",
    "//hci/include",
    "//osi/include",
    "//stack/include",
  ]

  deps = [
    "//third_party/libchrome",
    "//third_party/gtest:gtest_main",
    "//third_party/libchrome:base",
    "//vendor_libs/test_vendor_lib",
  ]
}

# TODO(dennischeng): Add a unit test target.
  libs = [
    "-lpthread",
    "-lrt",
    "-ldl",
  ]
}
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ class HciTransport : public base::MessageLoopForIO::Watcher {

  void CloseHciFd();

  void CloseVendorFd();

  int GetHciFd() const;

  int GetVendorFd() const;
+6 −1
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ void HciTransport::CloseHciFd() {
  hci_fd_.reset(nullptr);
}

void HciTransport::CloseVendorFd() {
  vendor_fd_.reset(nullptr);
}

int HciTransport::GetHciFd() const {
  return hci_fd_->get();
}
@@ -124,7 +128,8 @@ void HciTransport::AddEventToOutboundEvents(
}

void HciTransport::PostEventResponse(std::unique_ptr<EventPacket> event) {
  AddEventToOutboundEvents(std::make_unique<TimeStampedEvent>(std::move(event)));
  AddEventToOutboundEvents(
      std::make_unique<TimeStampedEvent>(std::move(event)));
}

void HciTransport::PostDelayedEventResponse(std::unique_ptr<EventPacket> event,
+2 −1
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ uint8_t Packet::GetHeaderSize() const {
}

size_t Packet::GetPacketSize() const {
  return header_.size() + payload_.size() + sizeof(type_);
  // Add one for the type octet.
  return 1 + header_.size() + payload_.size();
}

const std::vector<uint8_t>& Packet::GetPayload() const {
Loading