OSDN Git Service

Fix net_test_hci unit tests
authorPavlin Radoslavov <pavlin@google.com>
Fri, 4 Dec 2015 01:11:55 +0000 (17:11 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 7 Dec 2015 17:25:07 +0000 (17:25 +0000)
* 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
hci/src/hci_layer.c
hci/test/hci_layer_test.cpp

index fe5a2ca..54e1e4a 100644 (file)
@@ -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();
index 99a8d0c..d74f4e0 100644 (file)
@@ -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
 };
index e02bdc5..da0f1dd 100644 (file)
@@ -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();
     }