diff options
author | Etan Cohen <etancohen@google.com> | 2018-07-10 08:47:36 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2018-07-20 22:09:14 +0000 |
commit | 0ebd13f268eaca16e396089983475674620632f3 (patch) | |
tree | b93a3d3e669e12ef843ba3618ef5418a9b236d07 /tests | |
parent | a52e9108f44a2770dc7b0ce00bfb4493c3f8e65e (diff) |
[RTT] Recreate RTT controller when HAL indicates it is invalid
When there is a HAL mode transition the RTT controller is destroyed.
Mode transition is STA - SAP and back transitions for non-DBS devices.
Modification to allow framework to detect when the controller is
currently invalid and try to recreate it. Will allow recovery for
non-DBS devices: otherwise RTT would only recover when Wi-Fi is
toggled.
Note: not a full solution since the availability APIs (broadcast +
API) do not perform correctly in such transitions. That fix will
be deeper and require HalDeviceManager mods.
Bug: 111218083
Test: (new) unit test
Test: new ACTS - RangeApSupporting11McTest:test_rtt_in_and_after_softap_mode
Change-Id: I6d28ef7a50b02fe42e23b9172621bd83452658f1
(cherry picked from commit dfa13f1f48895759f77e5522e9c106765de327c8)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java index 3f5aa5f2d..7bbe6bb79 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -50,10 +51,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ErrorCollector; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -62,6 +66,7 @@ import java.util.List; public class RttNativeTest { private RttNative mDut; private WifiStatus mStatusSuccess; + private WifiStatus mStatusRttControllerInvalid; private ArgumentCaptor<ArrayList> mRttConfigCaptor = ArgumentCaptor.forClass(ArrayList.class); private ArgumentCaptor<List> mRttResultCaptor = ArgumentCaptor.forClass(List.class); @@ -97,6 +102,9 @@ public class RttNativeTest { when(mockRttController.rangeCancel(anyInt(), any(ArrayList.class))).thenReturn( mStatusSuccess); + mStatusRttControllerInvalid = new WifiStatus(); + mStatusRttControllerInvalid.code = WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID; + mDut = new RttNative(mockRttServiceImpl, mockHalDeviceManager); mDut.start(null); verify(mockHalDeviceManager).registerStatusListener(mHdmStatusListener.capture(), any()); @@ -324,15 +332,18 @@ public class RttNativeTest { int cmdId = 55; RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + InOrder order = inOrder(mockRttServiceImpl); + // (1) configure Wi-Fi down and send a status change indication when(mockHalDeviceManager.isStarted()).thenReturn(false); mHdmStatusListener.getValue().onStatusChanged(); - verify(mockRttServiceImpl).disable(); + order.verify(mockRttServiceImpl).disable(); assertFalse(mDut.isReady()); // (2) issue range request mDut.rangeRequest(cmdId, request, true); + order.verify(mockRttServiceImpl).disable(); // due to re-init attempt verifyNoMoreInteractions(mockRttServiceImpl, mockRttController); } @@ -436,6 +447,77 @@ public class RttNativeTest { } } + /** + * Validate correct re-initialization when the RTT Controller is invalid (which can happen + * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request. + */ + @Test + public void testRangeRequestInvalidRttControllerOnce() throws Exception { + int cmdId = 55; + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + + InOrder inOrder = Mockito.inOrder(mockRttController); + + // configure failure then success + when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn( + mStatusRttControllerInvalid).thenReturn(mStatusSuccess); + + // issue range request + boolean result = mDut.rangeRequest(cmdId, request, true); + assertTrue("rangeRequest should succeeed", result); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue(); + + // verify re-initialization (i.e. callback re-registered) + inOrder.verify(mockRttController).registerEventCallback(any()); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue(); + + assertTrue("HAL parameters different between calls!", + Arrays.equals(halRequest1.toArray(), halRequest2.toArray())); + verifyNoMoreInteractions(mockRttController); + } + + /** + * Validate correct re-initialization when the RTT Controller is invalid (which can happen + * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request - + * but only once (no infinite loop). + */ + @Test + public void testRangeRequestInvalidRttControllerForever() throws Exception { + int cmdId = 55; + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + + InOrder inOrder = Mockito.inOrder(mockRttController); + + // configure failure + when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn( + mStatusRttControllerInvalid); + + // issue range request + boolean result = mDut.rangeRequest(cmdId, request, true); + assertFalse("rangeRequest should fail", result); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue(); + + // verify re-initialization (i.e. callback re-registered) + inOrder.verify(mockRttController).registerEventCallback(any()); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue(); + + assertTrue("HAL parameters different between calls!", + Arrays.equals(halRequest1.toArray(), halRequest2.toArray())); + verifyNoMoreInteractions(mockRttController); + } + // Utilities /** |