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

Commit 8303da22 authored by Myles Watson's avatar Myles Watson Committed by Automerger Merge Worker
Browse files

Merge "Remove controller dependency from fragmenter" into main am: 4489c713 am: 68dada95

parents b981484a 68dada95
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -15,9 +15,6 @@ cc_library_static {
        "src/buffer_allocator.cc",
        "src/packet_fragmenter.cc",
    ],
    generated_headers: [
        "BluetoothGeneratedDumpsysDataSchema_h",
    ],
    local_include_dirs: [
        "include",
    ],
@@ -54,24 +51,17 @@ cc_test {
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/osi/test",
        "packages/modules/Bluetooth/system/stack/include",
        "system/libhwbinder/include",
    ],
    srcs: [
        "test/packet_fragmenter_test.cc",
    ],
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "libbase",
        "libdl",
        "liblog",
    ],
    static_libs: [
        "libbluetooth-for-tests",
        "libbluetooth-types",
        "libbt-hci",
        "libbtcore",
        "libchrome",
        "libosi",
    ],
@@ -80,5 +70,4 @@ cc_test {
        cfi: true,
        misc_undefined: ["bounds"],
    },
    cflags: ["-Wno-unused-parameter"],
}
+1 −3
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@
#include <base/functional/callback.h>
#include <base/location.h>

#include "osi/include/future.h"
#include "osi/include/osi.h"  // INVALID_FD
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_types.h"

@@ -63,7 +61,7 @@ typedef struct hci_t {
                           command_status_cb status_cb, void* context);

  // Send some data downward through the HCI layer
  void (*transmit_downward)(uint16_t type, void* data);
  void (*transmit_downward)(void* data, uint16_t iso_buffer_size);
} hci_t;

const hci_t* hci_layer_get_interface();
+1 −6
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@

#pragma once

#include "device/include/controller.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"

@@ -43,7 +42,7 @@ typedef struct packet_fragmenter_t {

  // Fragments |packet| if necessary and hands off everything to the fragmented
  // callback.
  void (*fragment_and_dispatch)(BT_HDR* packet);
  void (*fragment_and_dispatch)(BT_HDR* packet, uint16_t iso_buffer_size);
  // If |packet| is a complete packet, forwards to the reassembled callback.
  // Otherwise holds onto it until all fragments arrive, at which point the
  // reassembled callback is called with the reassembled data.
@@ -51,7 +50,3 @@ typedef struct packet_fragmenter_t {
} packet_fragmenter_t;

const packet_fragmenter_t* packet_fragmenter_get_interface();

const packet_fragmenter_t* packet_fragmenter_get_test_interface(
    const controller_t* controller_interface,
    const allocator_t* buffer_allocator_interface);
+2 −14
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@

#include <unordered_map>

#include "device/include/controller.h"
#include "hci/include/buffer_allocator.h"
#include "hci/include/hci_layer.h"
#include "internal_include/bt_target.h"
@@ -78,7 +77,6 @@
// Our interface and callbacks

static const allocator_t* buffer_allocator;
static const controller_t* controller;
static const packet_fragmenter_callbacks_t* callbacks;

static std::unordered_map<uint16_t /* handle */, BT_HDR*> partial_iso_packets;
@@ -89,7 +87,7 @@ static void init(const packet_fragmenter_callbacks_t* result_callbacks) {

static void cleanup() { partial_iso_packets.clear(); }

static void fragment_and_dispatch(BT_HDR* packet) {
static void fragment_and_dispatch(BT_HDR* packet, uint16_t max_data_size) {
  CHECK(packet != NULL);

  uint16_t event = packet->event & MSG_EVT_MASK;
@@ -97,7 +95,6 @@ static void fragment_and_dispatch(BT_HDR* packet) {
  CHECK(event == MSG_STACK_TO_HC_HCI_ISO);

  uint8_t* stream = packet->data + packet->offset;
  uint16_t max_data_size = controller->get_iso_data_size();
  uint16_t max_packet_size = max_data_size + HCI_ISO_PREAMBLE_SIZE;
  uint16_t remaining_length = packet->len;

@@ -141,7 +138,7 @@ static void fragment_and_dispatch(BT_HDR* packet) {
  callbacks->fragmented(packet, true);
}

static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR* packet) {
static void reassemble_and_dispatch(BT_HDR* packet) {
  uint8_t* stream = packet->data;
  uint16_t handle;
  uint16_t iso_length;
@@ -331,15 +328,6 @@ static const packet_fragmenter_t interface = {init, cleanup,
                                              reassemble_and_dispatch};

const packet_fragmenter_t* packet_fragmenter_get_interface() {
  controller = controller_get_interface();
  buffer_allocator = buffer_allocator_get_interface();
  return &interface;
}

const packet_fragmenter_t* packet_fragmenter_get_test_interface(
    const controller_t* controller_interface,
    const allocator_t* buffer_allocator_interface) {
  controller = controller_interface;
  buffer_allocator = buffer_allocator_interface;
  return &interface;
}
+7 −62
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <gtest/gtest.h>
#include <stdint.h>

#include "device/include/controller.h"
#include "hci/include/hci_layer.h"
#include "internal_include/bt_target.h"
#include "osi/include/allocator.h"
@@ -33,11 +32,8 @@
#define HCI_ISO_PREAMBLE_SIZE 4
#endif

DECLARE_TEST_MODES(init, set_data_sizes, no_fragmentation, fragmentation,
                   ble_no_fragmentation, ble_fragmentation,
                   non_acl_passthrough_fragmentation, no_reassembly, reassembly,
                   non_acl_passthrough_reassembly, iso_no_reassembly,
                   iso_reassembly, iso_fragmentation, iso_no_fragmentation);
DECLARE_TEST_MODES(init, iso_no_reassembly, iso_reassembly, iso_fragmentation,
                   iso_no_fragmentation);

#define LOCAL_BLE_CONTROLLER_ID 1

@@ -284,19 +280,6 @@ static void manufacture_packet_and_then_reassemble(uint16_t event,
  }
}

static void expect_packet_reassembled(uint16_t event, BT_HDR* packet,
                                      const char* expected_data) {
  uint16_t expected_data_length = strlen(expected_data);
  uint8_t* data = packet->data + packet->offset;

  for (int i = 0; i < expected_data_length; i++) {
    EXPECT_EQ(expected_data[i], data[i]);
    data_size_sum++;
  }

  osi_free(packet);
}

static void expect_packet_reassembled_iso(uint16_t event, BT_HDR* packet,
                                          const char* expected_data,
                                          uint32_t expected_timestamp,
@@ -359,12 +342,6 @@ DURING(iso_no_fragmentation) {
  return;
}

DURING(non_acl_passthrough_fragmentation) AT_CALL(0) {
  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_CMD, 10, packet, sample_data,
                           send_complete);
  return;
}

UNEXPECTED_CALL;
}

@@ -382,30 +359,7 @@ DURING(iso_no_reassembly) AT_CALL(0) {
  return;
}

DURING(non_acl_passthrough_reassembly) AT_CALL(0) {
  expect_packet_reassembled(MSG_HC_TO_STACK_HCI_EVT, packet, sample_data);
  return;
}

UNEXPECTED_CALL;
}

STUB_FUNCTION(uint16_t, get_acl_data_size_classic, (void))
DURING(no_fragmentation, non_acl_passthrough_fragmentation, no_reassembly)
return 42;
DURING(fragmentation) return 10;
DURING(no_reassembly) return 1337;

UNEXPECTED_CALL;
return 0;
}

STUB_FUNCTION(uint16_t, get_acl_data_size_ble, (void))
DURING(ble_no_fragmentation) return 42;
DURING(ble_fragmentation) return 10;

UNEXPECTED_CALL;
return 0;
}

STUB_FUNCTION(uint16_t, get_iso_data_size, (void))
@@ -419,34 +373,25 @@ return 0;
static void reset_for(TEST_MODES_T next) {
  RESET_CALL_COUNT(fragmented_callback);
  RESET_CALL_COUNT(reassembled_callback);
  RESET_CALL_COUNT(get_acl_data_size_classic);
  RESET_CALL_COUNT(get_acl_data_size_ble);
  RESET_CALL_COUNT(get_iso_data_size);
  CURRENT_TEST_MODE = next;
}

class PacketFragmenterTest : public ::testing::Test {
 protected:
  void SetUp() override {
    fragmenter =
        packet_fragmenter_get_test_interface(&controller, &allocator_malloc);
    fragmenter = packet_fragmenter_get_interface();

    packet_index = 0;
    data_size_sum = 0;

    callbacks.fragmented = fragmented_callback;
    callbacks.reassembled = reassembled_callback;
    controller.get_acl_data_size_classic = get_acl_data_size_classic;
    controller.get_acl_data_size_ble = get_acl_data_size_ble;
    controller.get_iso_data_size = get_iso_data_size;

    reset_for(init);
    fragmenter->init(&callbacks);
  }

  void TearDown() override { fragmenter->cleanup(); }

  controller_t controller;
  packet_fragmenter_callbacks_t callbacks;
};

@@ -457,7 +402,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary) {
  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO,
                                                        sample_data);
  packet->event |= LOCAL_BLE_CONTROLLER_ID;
  fragmenter->fragment_and_dispatch(packet);
  fragmenter->fragment_and_dispatch(packet, get_iso_data_size());

  ASSERT_EQ(strlen(sample_data), data_size_sum);
}
@@ -469,7 +414,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary) {
  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO,
                                                        small_sample_data);
  packet->event |= LOCAL_BLE_CONTROLLER_ID;
  fragmenter->fragment_and_dispatch(packet);
  fragmenter->fragment_and_dispatch(packet, get_iso_data_size());

  ASSERT_EQ(strlen(small_sample_data), data_size_sum);
}
@@ -480,7 +425,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary_no_ts) {
  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO,
                                                        sample_data);
  packet->event |= LOCAL_BLE_CONTROLLER_ID;
  fragmenter->fragment_and_dispatch(packet);
  fragmenter->fragment_and_dispatch(packet, get_iso_data_size());

  ASSERT_EQ(strlen(sample_data), data_size_sum);
}
@@ -491,7 +436,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary_no_ts) {
  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO,
                                                        small_sample_data);
  packet->event |= LOCAL_BLE_CONTROLLER_ID;
  fragmenter->fragment_and_dispatch(packet);
  fragmenter->fragment_and_dispatch(packet, get_iso_data_size());

  ASSERT_EQ(strlen(small_sample_data), data_size_sum);
}
Loading