From c3caf784c788af45fd6b657a09f4034b9d3387ba Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Thu, 3 Dec 2015 17:11:55 -0800 Subject: [PATCH] Fix net_test_hci unit tests * Added new function API to hci_layer: hci_layer_cleanup_interface() It can be used to cleanup after hci_layer_get_interface() or hci_layer_get_test_interface() * Fixed the unit tests inside HciLayerTest by removing usage of allocation_tracker_reset() and adding hci_layer_cleanup_interface() . The former was used as a hack to bypass the internal memory allocation of hci_layer_get_test_interface(). The latter is used to properly cleanup such allocation. Bug: 26014740 Change-Id: I498b996a931c59dd3b4258f1a5741cfa6d302e42 --- hci/include/hci_layer.h | 2 ++ hci/src/hci_layer.c | 15 +++++++++++++++ hci/test/hci_layer_test.cpp | 6 ++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hci/include/hci_layer.h b/hci/include/hci_layer.h index fe5a2caf2..54e1e4a5a 100644 --- a/hci/include/hci_layer.h +++ b/hci/include/hci_layer.h @@ -110,3 +110,5 @@ const hci_t *hci_layer_get_test_interface( const packet_fragmenter_t *packet_fragmenter_interface, const vendor_t *vendor_interface, const low_power_manager_t *low_power_manager_interface); + +void hci_layer_cleanup_interface(); diff --git a/hci/src/hci_layer.c b/hci/src/hci_layer.c index 99a8d0cfa..d74f4e00b 100644 --- a/hci/src/hci_layer.c +++ b/hci/src/hci_layer.c @@ -777,6 +777,21 @@ static void init_layer_interface() { } } +void hci_layer_cleanup_interface() { + if (interface_created) { + interface.send_low_power_command = NULL; + interface.do_postload = NULL; + + data_dispatcher_free(interface.event_dispatcher); + + interface.set_data_queue = NULL; + interface.transmit_command = NULL; + interface.transmit_command_futured = NULL; + interface.transmit_downward = NULL; + interface_created = false; + } +} + static const hci_hal_callbacks_t hal_callbacks = { hal_says_data_ready }; diff --git a/hci/test/hci_layer_test.cpp b/hci/test/hci_layer_test.cpp index e02bdc5d6..da0f1dd22 100644 --- a/hci/test/hci_layer_test.cpp +++ b/hci/test/hci_layer_test.cpp @@ -520,6 +520,7 @@ class HciLayerTest : public AlarmTestHarness { protected: virtual void SetUp() { AlarmTestHarness::SetUp(); + module_management_start(); hci = hci_layer_get_test_interface( &buffer_allocator, @@ -531,10 +532,6 @@ class HciLayerTest : public AlarmTestHarness { &low_power_manager ); - // Make sure the data dispatcher allocation isn't tracked - allocation_tracker_reset(); - module_management_start(); - packet_index = 0; data_size_sum = 0; @@ -584,6 +581,7 @@ class HciLayerTest : public AlarmTestHarness { EXPECT_CALL_COUNT(vendor_close, 1); semaphore_free(done); + hci_layer_cleanup_interface(); module_management_stop(); AlarmTestHarness::TearDown(); } -- 2.11.0