diff options
author | Zach Johnson <zachoverflow@google.com> | 2014-08-27 16:30:29 -0700 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2015-03-16 16:51:30 -0700 |
commit | 1e0ede7f5522a853fc39d4f183e508ed38f01636 (patch) | |
tree | bac60a31b42cbf521e683f2a312026960b478397 | |
parent | ee2aa45def216a3c4d6a23481fa96f1b02a5de8c (diff) | |
download | android_system_bt-1e0ede7f5522a853fc39d4f183e508ed38f01636.tar.gz android_system_bt-1e0ede7f5522a853fc39d4f183e508ed38f01636.tar.bz2 android_system_bt-1e0ede7f5522a853fc39d4f183e508ed38f01636.zip |
Move HCI over to the osi allocators, and fix the tests accordingly
-rw-r--r-- | hci/include/packet_fragmenter.h | 3 | ||||
-rw-r--r-- | hci/src/hci_inject.c | 4 | ||||
-rw-r--r-- | hci/src/hci_layer.c | 8 | ||||
-rw-r--r-- | hci/src/packet_fragmenter.c | 7 | ||||
-rw-r--r-- | hci/test/hci_hal_h4_test.cpp | 6 | ||||
-rw-r--r-- | hci/test/hci_hal_mct_test.cpp | 6 | ||||
-rw-r--r-- | hci/test/hci_layer_test.cpp | 18 | ||||
-rw-r--r-- | hci/test/low_power_manager_test.cpp | 3 | ||||
-rw-r--r-- | hci/test/packet_fragmenter_test.cpp | 24 |
9 files changed, 54 insertions, 25 deletions
diff --git a/hci/include/packet_fragmenter.h b/hci/include/packet_fragmenter.h index 7d13c905b..2d6ed280d 100644 --- a/hci/include/packet_fragmenter.h +++ b/hci/include/packet_fragmenter.h @@ -41,6 +41,9 @@ typedef struct packet_fragmenter_interface_t { // is used to allocate and free buffers for the reassembled packets. void (*init)(const packet_fragmenter_callbacks_t *result_callbacks, const allocator_t *buffer_allocator); + // Release all resources associated with the fragmenter. + void (*cleanup)(void); + // Sets the fragmentation size for normal acl data. void (*set_acl_data_size)(uint16_t size); // Sets the fragmentation size for bluetooth low energy acl data. diff --git a/hci/src/hci_inject.c b/hci/src/hci_inject.c index e894b73ff..0d91c7edd 100644 --- a/hci/src/hci_inject.c +++ b/hci/src/hci_inject.c @@ -22,6 +22,7 @@ #include <errno.h> #include <utils/Log.h> +#include "allocator.h" #include "bt_types.h" #include "hci_inject.h" #include "hci_layer.h" @@ -122,7 +123,7 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) { if (!socket) return; - client_t *client = (client_t *)calloc(1, sizeof(client_t)); + client_t *client = (client_t *)osi_calloc(sizeof(client_t)); if (!client) { ALOGE("%s unable to allocate memory for client.", __func__); socket_free(socket); @@ -190,6 +191,7 @@ static void client_free(void *ptr) { client_t *client = (client_t *)ptr; socket_free(client->socket); + osi_free(client); } static const hci_inject_interface_t interface = { diff --git a/hci/src/hci_layer.c b/hci/src/hci_layer.c index 7e1920cfe..171732fef 100644 --- a/hci/src/hci_layer.c +++ b/hci/src/hci_layer.c @@ -234,6 +234,8 @@ static void hci_cleanup() { fixed_queue_free(packet_queue, buffer_allocator->free); fixed_queue_free(waiting_internal_commands, buffer_allocator->free); + packet_fragmenter->cleanup(); + alarm_free(epilog_alarm); epilog_alarm = NULL; @@ -316,7 +318,7 @@ static bool filter_incoming_event(BT_HDR *packet) { else buffer_allocator->free(packet); - free(first_waiting); + osi_free(first_waiting); return true; } @@ -331,7 +333,7 @@ static bool filter_incoming_event(BT_HDR *packet) { // Send an internal command. Called by the vendor library, and also // internally by the HCI layer to fetch controller buffer sizes. static bool send_internal_command(uint16_t opcode, BT_HDR *packet, internal_command_cb callback) { - waiting_internal_command_t *wait_entry = (waiting_internal_command_t *)calloc(1, sizeof(waiting_internal_command_t)); + waiting_internal_command_t *wait_entry = osi_calloc(sizeof(waiting_internal_command_t)); if (!wait_entry) { ALOGE("%s couldn't allocate space for wait entry.", __func__); return false; @@ -341,7 +343,7 @@ static bool send_internal_command(uint16_t opcode, BT_HDR *packet, internal_comm wait_entry->callback = callback; if (!fixed_queue_try_enqueue(waiting_internal_commands, wait_entry)) { - free(wait_entry); + osi_free(wait_entry); ALOGE("%s too many waiting internal commands. Rejecting 0x%04X", __func__, opcode); return false; } diff --git a/hci/src/packet_fragmenter.c b/hci/src/packet_fragmenter.c index 3bca95f41..cf4f86906 100644 --- a/hci/src/packet_fragmenter.c +++ b/hci/src/packet_fragmenter.c @@ -59,10 +59,12 @@ static void init(const packet_fragmenter_callbacks_t *result_callbacks, const al acl_data_size = 1021; ble_acl_data_size = 27; + partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL); +} + +static void cleanup() { if (partial_packets) hash_map_free(partial_packets); - - partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL); } static void set_acl_data_size(uint16_t size) { @@ -213,6 +215,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) { static const packet_fragmenter_interface_t interface = { init, + cleanup, set_acl_data_size, set_ble_acl_data_size, diff --git a/hci/test/hci_hal_h4_test.cpp b/hci/test/hci_hal_h4_test.cpp index 8055d807a..2e34ddc71 100644 --- a/hci/test/hci_hal_h4_test.cpp +++ b/hci/test/hci_hal_h4_test.cpp @@ -18,6 +18,8 @@ #include <gtest/gtest.h> +#include "AllocationTestHarness.h" + extern "C" { #include <stdint.h> #include <sys/types.h> @@ -131,9 +133,10 @@ static void reset_for(TEST_MODES_T next) { CURRENT_TEST_MODE = next; } -class HciHalH4Test : public ::testing::Test { +class HciHalH4Test : public AllocationTestHarness { protected: virtual void SetUp() { + AllocationTestHarness::SetUp(); hal = hci_hal_h4_get_test_interface(&vendor); vendor.send_command = vendor_send_command; callbacks.data_ready = data_ready_callback; @@ -158,6 +161,7 @@ class HciHalH4Test : public ::testing::Test { semaphore_free(done); thread_free(thread); + AllocationTestHarness::TearDown(); } int sockfd[2]; diff --git a/hci/test/hci_hal_mct_test.cpp b/hci/test/hci_hal_mct_test.cpp index 60fb1c004..ba1b574a4 100644 --- a/hci/test/hci_hal_mct_test.cpp +++ b/hci/test/hci_hal_mct_test.cpp @@ -18,6 +18,8 @@ #include <gtest/gtest.h> +#include "AllocationTestHarness.h" + extern "C" { #include <stdint.h> #include <sys/types.h> @@ -130,9 +132,10 @@ static void reset_for(TEST_MODES_T next) { CURRENT_TEST_MODE = next; } -class HciHalMctTest : public ::testing::Test { +class HciHalMctTest : public AllocationTestHarness { protected: virtual void SetUp() { + AllocationTestHarness::SetUp(); hal = hci_hal_mct_get_test_interface(&vendor); vendor.send_command = vendor_send_command; callbacks.data_ready = data_ready_callback; @@ -164,6 +167,7 @@ class HciHalMctTest : public ::testing::Test { semaphore_free(done); thread_free(thread); + AllocationTestHarness::TearDown(); } int command_sockfd[2]; diff --git a/hci/test/hci_layer_test.cpp b/hci/test/hci_layer_test.cpp index ec86254ef..c9367f6a5 100644 --- a/hci/test/hci_layer_test.cpp +++ b/hci/test/hci_layer_test.cpp @@ -18,11 +18,14 @@ #include <gtest/gtest.h> +#include "AlarmTestHarness.h" + extern "C" { #include <stdint.h> #include <utils/Log.h> -#include "AlarmTestHarness.h" +#include "allocation_tracker.h" +#include "allocator.h" #include "btsnoop.h" #include "hci_hal.h" #include "hci_inject.h" @@ -76,7 +79,7 @@ static BT_HDR *manufacture_packet(uint16_t event, const char *data) { size += 4; // 2 for the handle, 2 for the length; } - BT_HDR *packet = (BT_HDR *)malloc(size + sizeof(BT_HDR)); + BT_HDR *packet = (BT_HDR *)osi_malloc(size + sizeof(BT_HDR)); packet->len = size; packet->offset = 0; packet->event = event; @@ -370,11 +373,13 @@ STUB_FUNCTION(int, vendor_send_async_command, (UNUSED_ATTR vendor_async_opcode_t STUB_FUNCTION(void, callback_transmit_finished, (UNUSED_ATTR void *buffer, bool all_fragments_sent)) DURING(transmit_simple) AT_CALL(0) { EXPECT_TRUE(all_fragments_sent); + osi_free(buffer); return; } DURING(send_internal_command) AT_CALL(0) { EXPECT_TRUE(all_fragments_sent); + osi_free(buffer); return; } @@ -426,6 +431,9 @@ class HciLayerTest : public AlarmTestHarness { &low_power_manager ); + // Make sure the data dispatcher allocation isn't tracked + allocation_tracker_reset(); + packet_index = 0; data_size_sum = 0; @@ -530,8 +538,6 @@ TEST_F(HciLayerTest, test_transmit_simple) { EXPECT_CALL_COUNT(low_power_transmit_done, 1); EXPECT_CALL_COUNT(low_power_wake_assert, 1); EXPECT_CALL_COUNT(callback_transmit_finished, 1); - - free(packet); } TEST_F(HciLayerTest, test_receive_simple) { @@ -543,7 +549,7 @@ TEST_F(HciLayerTest, test_receive_simple) { EXPECT_CALL_COUNT(hal_packet_finished, 1); EXPECT_CALL_COUNT(btsnoop_capture, 1); - free(data_to_receive); + osi_free(data_to_receive); } TEST_F(HciLayerTest, test_send_internal_command) { @@ -560,8 +566,6 @@ TEST_F(HciLayerTest, test_send_internal_command) { EXPECT_CALL_COUNT(callback_transmit_finished, 1); // TODO(zachoverflow): send a response and make sure the response ends up at the callback - - free(data_to_receive); } // TODO(zachoverflow): test post-reassembly better, stub out fragmenter instead of using it diff --git a/hci/test/low_power_manager_test.cpp b/hci/test/low_power_manager_test.cpp index c108038eb..3c07728c3 100644 --- a/hci/test/low_power_manager_test.cpp +++ b/hci/test/low_power_manager_test.cpp @@ -18,11 +18,12 @@ #include <gtest/gtest.h> +#include "AlarmTestHarness.h" + extern "C" { #include <stdint.h> #include <utils/Log.h> -#include "AlarmTestHarness.h" #include "low_power_manager.h" #include "osi.h" #include "semaphore.h" diff --git a/hci/test/packet_fragmenter_test.cpp b/hci/test/packet_fragmenter_test.cpp index 1a9f4f371..e22bef248 100644 --- a/hci/test/packet_fragmenter_test.cpp +++ b/hci/test/packet_fragmenter_test.cpp @@ -18,10 +18,13 @@ #include <gtest/gtest.h> +#include "AllocationTestHarness.h" + extern "C" { #include <stdint.h> #include <utils/Log.h> +#include "allocator.h" #include "hci_internals.h" #include "packet_fragmenter.h" #include "osi.h" @@ -67,7 +70,7 @@ static BT_HDR *manufacture_packet_for_fragmentation(uint16_t event, const char * size += 4; // 2 for the handle, 2 for the length; } - BT_HDR *packet = (BT_HDR *)malloc(size + sizeof(BT_HDR)); + BT_HDR *packet = (BT_HDR *)osi_malloc(size + sizeof(BT_HDR)); packet->len = size; packet->offset = 0; packet->event = event; @@ -121,6 +124,9 @@ static void expect_packet_fragmented(uint16_t event, int max_acl_data_size, BT_H if (event == MSG_STACK_TO_HC_HCI_ACL) EXPECT_TRUE(send_complete == (data_size_sum == strlen(expected_data))); + + if (send_complete) + osi_free(packet); } static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_size, const char *data) { @@ -133,7 +139,7 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_ do { int length_to_send = (length_sent + (acl_size - 4) < total_length) ? (acl_size - 4) : (total_length - length_sent); - BT_HDR *packet = (BT_HDR *)malloc(length_to_send + 4 + sizeof(BT_HDR)); + BT_HDR *packet = (BT_HDR *)osi_malloc(length_to_send + 4 + sizeof(BT_HDR)); packet->len = length_to_send + 4; packet->offset = 0; packet->event = event; @@ -155,7 +161,7 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_ fragmenter->reassemble_and_dispatch(packet); } while (length_sent < total_length); } else { - BT_HDR *packet = (BT_HDR *)malloc(data_length + sizeof(BT_HDR)); + BT_HDR *packet = (BT_HDR *)osi_malloc(data_length + sizeof(BT_HDR)); packet->len = data_length; packet->offset = 0; packet->event = event; @@ -188,6 +194,8 @@ static void expect_packet_reassembled(uint16_t event, BT_HDR *packet, const char EXPECT_EQ(expected_data[i], data[i]); data_size_sum++; } + + osi_free(packet); } STUB_FUNCTION(void, fragmented_callback, (BT_HDR *packet, bool send_complete)) @@ -249,9 +257,10 @@ static void reset_for(TEST_MODES_T next) { CURRENT_TEST_MODE = next; } -class PacketFragmenterTest : public ::testing::Test { +class PacketFragmenterTest : public AllocationTestHarness { protected: virtual void SetUp() { + AllocationTestHarness::SetUp(); fragmenter = packet_fragmenter_get_interface(); packet_index = 0; data_size_sum = 0; @@ -265,6 +274,8 @@ class PacketFragmenterTest : public ::testing::Test { } virtual void TearDown() { + fragmenter->cleanup(); + AllocationTestHarness::TearDown(); } packet_fragmenter_callbacks_t callbacks; @@ -282,7 +293,6 @@ TEST_F(PacketFragmenterTest, test_no_fragment_necessary) { BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, small_sample_data); fragmenter->fragment_and_dispatch(packet); - free(packet); EXPECT_EQ(strlen(small_sample_data), data_size_sum); EXPECT_CALL_COUNT(fragmented_callback, 1); @@ -294,7 +304,6 @@ TEST_F(PacketFragmenterTest, test_fragment_necessary) { BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, sample_data); fragmenter->fragment_and_dispatch(packet); - free(packet); EXPECT_EQ(strlen(sample_data), data_size_sum); } @@ -307,7 +316,6 @@ TEST_F(PacketFragmenterTest, test_ble_no_fragment_necessary) { BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, small_sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); - free(packet); EXPECT_EQ(strlen(small_sample_data), data_size_sum); EXPECT_CALL_COUNT(fragmented_callback, 1); @@ -321,7 +329,6 @@ TEST_F(PacketFragmenterTest, test_ble_fragment_necessary) { BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); - free(packet); EXPECT_EQ(strlen(sample_data), data_size_sum); } @@ -333,7 +340,6 @@ TEST_F(PacketFragmenterTest, test_non_acl_passthrough_fragmentation) { BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_CMD, sample_data); fragmenter->fragment_and_dispatch(packet); - free(packet); EXPECT_EQ(strlen(sample_data), data_size_sum); EXPECT_CALL_COUNT(fragmented_callback, 1); |