diff options
author | Etan Cohen <etancohen@google.com> | 2018-10-09 12:51:20 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-09 12:51:20 +0000 |
commit | 1223e9aa52466139b4de0637c4f9dd3d00b8b20b (patch) | |
tree | 4dd2d01e58eff5c677baaf134c6e6bb908b4fbf9 /tests | |
parent | 8a8f9588cbecb8236ac724dd604a9a0a0d546ac7 (diff) | |
parent | d71b53361125ea4f7340426c5e6c90bb10561dab (diff) |
Merge changes from topic "rtt_hal"
* changes:
[RTT] Handle HAL concurrencly limitations on RTT availability
Revert "[RTT] Recreate RTT controller when HAL indicates it is invalid"
Diffstat (limited to 'tests')
3 files changed, 258 insertions, 264 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java index 823a28d13..e5391f16b 100644 --- a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java @@ -45,6 +45,7 @@ import android.hardware.wifi.V1_0.IWifiEventCallback; import android.hardware.wifi.V1_0.IWifiIface; import android.hardware.wifi.V1_0.IWifiNanIface; import android.hardware.wifi.V1_0.IWifiP2pIface; +import android.hardware.wifi.V1_0.IWifiRttController; import android.hardware.wifi.V1_0.IWifiStaIface; import android.hardware.wifi.V1_0.IfaceType; import android.hardware.wifi.V1_0.WifiStatus; @@ -86,6 +87,7 @@ public class HalDeviceManagerTest { private HalDeviceManager mDut; @Mock IServiceManager mServiceManagerMock; @Mock IWifi mWifiMock; + @Mock IWifiRttController mRttControllerMock; @Mock HalDeviceManager.ManagerStatusListener mManagerStatusListenerMock; @Mock private Clock mClock; private TestLooper mTestLooper; @@ -140,6 +142,7 @@ public class HalDeviceManagerTest { when(mWifiMock.registerEventCallback(any(IWifiEventCallback.class))).thenReturn(mStatusOk); when(mWifiMock.start()).thenReturn(mStatusOk); when(mWifiMock.stop()).thenReturn(mStatusOk); + when(mWifiMock.isStarted()).thenReturn(true); mDut = new HalDeviceManagerSpy(); } @@ -519,6 +522,196 @@ public class HalDeviceManagerTest { assertFalse(mDut.isSupported()); } + /** + * Validate RTT configuration when the callback is registered first and the chip is + * configured later - i.e. RTT isn't available immediately. + */ + @Test + public void testAndTriggerRttLifecycleCallbacksRegBeforeChipConfig() throws Exception { + HalDeviceManager.InterfaceRttControllerLifecycleCallback cb = mock( + HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); + + InOrder io = inOrder(cb); + + // initialize a test chip (V1 is fine since we're not testing any specifics of + // concurrency in this test). + ChipMockBase chipMock = new TestChipV1(); + chipMock.initialize(); + mInOrder = inOrder(mServiceManagerMock, mWifiMock, chipMock.chip, + mManagerStatusListenerMock); + executeAndValidateInitializationSequence(); + executeAndValidateStartupSequence(); + + // register initial cb: don't expect RTT since chip isn't configured + mDut.registerRttControllerLifecycleCallback(cb, mHandler); + mTestLooper.dispatchAll(); + io.verify(cb, times(0)).onNewRttController(any()); + + // create a STA - that will get the chip configured and get us an RTT controller + validateInterfaceSequence(chipMock, + false, // chipModeValid + -1000, // chipModeId (only used if chipModeValid is true) + IfaceType.STA, + "wlan0", + TestChipV1.STA_CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + verify(chipMock.chip).createRttController(any(), any()); + io.verify(cb).onNewRttController(any()); + + verifyNoMoreInteractions(cb); + } + + /** + * Validate the RTT Controller lifecycle using a multi-mode chip (i.e. a chip which can + * switch modes, during which RTT is destroyed). + * + * 1. Validate that an RTT is created as soon as the callback is registered - if the chip + * is already configured (i.e. it is possible to create the RTT controller). + * + * 2. Validate that only the registered callback is triggered, not previously registered ones + * and not duplicate ones. + * + * 3. Validate that onDestroy callbacks are triggered on mode change. + */ + @Test + public void testAndTriggerRttLifecycleCallbacksMultiModeChip() throws Exception { + HalDeviceManager.InterfaceRttControllerLifecycleCallback cb1 = mock( + HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); + HalDeviceManager.InterfaceRttControllerLifecycleCallback cb2 = mock( + HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); + + InOrder io1 = inOrder(cb1); + InOrder io2 = inOrder(cb2); + + // initialize a test chip (V1 is a must since we're testing a multi-mode chip) & create a + // STA (which will configure the chip). + ChipMockBase chipMock = new TestChipV1(); + chipMock.initialize(); + mInOrder = inOrder(mServiceManagerMock, mWifiMock, chipMock.chip, + mManagerStatusListenerMock); + executeAndValidateInitializationSequence(); + executeAndValidateStartupSequence(); + validateInterfaceSequence(chipMock, + false, // chipModeValid + -1000, // chipModeId (only used if chipModeValid is true) + IfaceType.STA, + "wlan0", + TestChipV1.STA_CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + mInOrder.verify(chipMock.chip, times(0)).createRttController(any(), any()); + + // register initial cb - expect the cb right away + mDut.registerRttControllerLifecycleCallback(cb1, mHandler); + mTestLooper.dispatchAll(); + verify(chipMock.chip).createRttController(any(), any()); + io1.verify(cb1).onNewRttController(mRttControllerMock); + + // register a second callback and the first one again + mDut.registerRttControllerLifecycleCallback(cb2, mHandler); + mDut.registerRttControllerLifecycleCallback(cb1, mHandler); + mTestLooper.dispatchAll(); + io2.verify(cb2).onNewRttController(mRttControllerMock); + + // change to AP mode (which for TestChipV1 doesn't allow RTT): trigger onDestroyed for all + validateInterfaceSequence(chipMock, + true, // chipModeValid + TestChipV1.STA_CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true) + IfaceType.AP, + "wlan0", + TestChipV1.AP_CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + mTestLooper.dispatchAll(); + verify(chipMock.chip, times(2)).createRttController(any(), any()); // but returns a null! + io1.verify(cb1).onRttControllerDestroyed(); + io2.verify(cb2).onRttControllerDestroyed(); + + // change back to STA mode (which for TestChipV1 will re-allow RTT): trigger onNew for all + validateInterfaceSequence(chipMock, + true, // chipModeValid + TestChipV1.AP_CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true) + IfaceType.STA, + "wlan0", + TestChipV1.STA_CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + mTestLooper.dispatchAll(); + verify(chipMock.chip, times(3)).createRttController(any(), any()); + io1.verify(cb1).onNewRttController(mRttControllerMock); + io2.verify(cb2).onNewRttController(mRttControllerMock); + + verifyNoMoreInteractions(cb1, cb2); + } + + /** + * Validate the RTT Controller lifecycle using a single-mode chip. Specifically validate + * that RTT isn't impacted during STA -> AP change. + */ + @Test + public void testAndTriggerRttLifecycleCallbacksSingleModeChip() throws Exception { + HalDeviceManager.InterfaceRttControllerLifecycleCallback cb = mock( + HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); + + InOrder io = inOrder(cb); + + // initialize a test chip (V2 is a must since we need a single mode chip) + // & create a STA (which will configure the chip). + ChipMockBase chipMock = new TestChipV2(); + chipMock.initialize(); + mInOrder = inOrder(mServiceManagerMock, mWifiMock, chipMock.chip, + mManagerStatusListenerMock); + executeAndValidateInitializationSequence(); + executeAndValidateStartupSequence(); + validateInterfaceSequence(chipMock, + false, // chipModeValid + -1000, // chipModeId (only used if chipModeValid is true) + IfaceType.STA, + "wlan0", + TestChipV2.CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + mInOrder.verify(chipMock.chip, times(0)).createRttController(any(), any()); + + // register initial cb - expect the cb right away + mDut.registerRttControllerLifecycleCallback(cb, mHandler); + mTestLooper.dispatchAll(); + verify(chipMock.chip).createRttController(any(), any()); + io.verify(cb).onNewRttController(mRttControllerMock); + + // create an AP: no mode change for TestChipV2 -> expect no impact on RTT + validateInterfaceSequence(chipMock, + true, // chipModeValid + TestChipV2.CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true) + IfaceType.AP, + "wlan0", + TestChipV2.CHIP_MODE_ID, + false, // high priority + null, // tearDownList + null, // destroyedListener + null // availableListener + ); + mTestLooper.dispatchAll(); + + verifyNoMoreInteractions(cb); + } + ////////////////////////////////////////////////////////////////////////////////////// // Chip Specific Tests - but should work on all chips! // (i.e. add copies for each test chip) @@ -2198,6 +2391,7 @@ public class HalDeviceManagerTest { /////////////////////////////////////////////////////////////////////////////////////// // utilities /////////////////////////////////////////////////////////////////////////////////////// + private void dumpDut(String prefix) { StringWriter sw = new StringWriter(); mDut.dump(null, new PrintWriter(sw), null); @@ -2234,7 +2428,7 @@ public class HalDeviceManagerTest { } } - private void executeAndValidateStartupSequence()throws Exception { + private void executeAndValidateStartupSequence() throws Exception { executeAndValidateStartupSequence(1, true); } @@ -2684,6 +2878,7 @@ public class HalDeviceManagerTest { } public WifiStatus answer(int chipMode) { + mChipMockBase.chipModeValid = true; mChipMockBase.chipModeId = chipMode; return mStatusOk; } @@ -2784,6 +2979,24 @@ public class HalDeviceManagerTest { } } + private class CreateRttControllerAnswer extends MockAnswerUtil.AnswerWithArguments { + private final ChipMockBase mChipMockBase; + private final IWifiRttController mRttController; + + CreateRttControllerAnswer(ChipMockBase chipMockBase, IWifiRttController rttController) { + mChipMockBase = chipMockBase; + mRttController = rttController; + } + + public void answer(IWifiIface boundIface, IWifiChip.createRttControllerCallback cb) { + if (mChipMockBase.chipModeIdValidForRtt == mChipMockBase.chipModeId) { + cb.onValues(mStatusOk, mRttController); + } else { + cb.onValues(mStatusFail, null); + } + } + } + private class RemoveXxxIfaceAnswer extends MockAnswerUtil.AnswerWithArguments { private ChipMockBase mChipMockBase; private int mType; @@ -2850,6 +3063,7 @@ public class HalDeviceManagerTest { public int chipId; public boolean chipModeValid = false; public int chipModeId = -1000; + public int chipModeIdValidForRtt = -1; // single chip mode ID where RTT can be created public Map<Integer, ArrayList<String>> interfaceNames = new HashMap<>(); public Map<Integer, Map<String, IWifiIface>> interfacesByName = new HashMap<>(); @@ -2900,6 +3114,9 @@ public class HalDeviceManagerTest { anyString()); doAnswer(new RemoveXxxIfaceAnswer(this, IfaceType.NAN)).when(chip).removeNanIface( anyString()); + + doAnswer(new CreateRttControllerAnswer(this, mRttControllerMock)).when( + chip).createRttController(any(), any()); } } @@ -2962,6 +3179,8 @@ public class HalDeviceManagerTest { cm.availableCombinations.add(cic); availableModes.add(cm); + chipModeIdValidForRtt = STA_CHIP_MODE_ID; + doAnswer(new GetAvailableModesAnswer(this)).when(chip) .getAvailableModes(any(IWifiChip.getAvailableModesCallback.class)); } @@ -3020,6 +3239,8 @@ public class HalDeviceManagerTest { cm.availableCombinations.add(cic); availableModes.add(cm); + chipModeIdValidForRtt = CHIP_MODE_ID; + doAnswer(new GetAvailableModesAnswer(this)).when(chip) .getAvailableModes(any(IWifiChip.getAvailableModesCallback.class)); } @@ -3090,6 +3311,8 @@ public class HalDeviceManagerTest { cm.availableCombinations.add(cic); availableModes.add(cm); + chipModeIdValidForRtt = CHIP_MODE_ID; + doAnswer(new GetAvailableModesAnswer(this)).when(chip) .getAvailableModes(any(IWifiChip.getAvailableModesCallback.class)); } @@ -3159,6 +3382,8 @@ public class HalDeviceManagerTest { cm.availableCombinations.add(cic); availableModes.add(cm); + chipModeIdValidForRtt = CHIP_MODE_ID; + doAnswer(new GetAvailableModesAnswer(this)).when(chip) .getAvailableModes(any(IWifiChip.getAvailableModesCallback.class)); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index d5259c710..9ca722164 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -48,15 +48,9 @@ import android.hardware.wifi.V1_0.IWifiApIface; import android.hardware.wifi.V1_0.IWifiChip; import android.hardware.wifi.V1_0.IWifiChipEventCallback; import android.hardware.wifi.V1_0.IWifiIface; -import android.hardware.wifi.V1_0.IWifiRttController; -import android.hardware.wifi.V1_0.IWifiRttControllerEventCallback; import android.hardware.wifi.V1_0.IWifiStaIface; import android.hardware.wifi.V1_0.IWifiStaIfaceEventCallback; import android.hardware.wifi.V1_0.IfaceType; -import android.hardware.wifi.V1_0.RttBw; -import android.hardware.wifi.V1_0.RttCapabilities; -import android.hardware.wifi.V1_0.RttConfig; -import android.hardware.wifi.V1_0.RttPreamble; import android.hardware.wifi.V1_0.StaApfPacketFilterCapabilities; import android.hardware.wifi.V1_0.StaBackgroundScanCapabilities; import android.hardware.wifi.V1_0.StaBackgroundScanParameters; @@ -86,7 +80,6 @@ import android.hardware.wifi.V1_2.IWifiChipEventCallback.RadioModeInfo; import android.net.KeepalivePacketData; import android.net.MacAddress; import android.net.apf.ApfCapabilities; -import android.net.wifi.RttManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.net.wifi.WifiScanner; @@ -154,8 +147,6 @@ public class WifiVendorHalTest { private android.hardware.wifi.V1_2.IWifiStaIface mIWifiStaIfaceV12; @Mock private android.hardware.wifi.V1_3.IWifiStaIface mIWifiStaIfaceV13; - @Mock - private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; private android.hardware.wifi.V1_2.IWifiChipEventCallback mIWifiChipEventCallbackV12; @@ -310,7 +301,6 @@ public class WifiVendorHalTest { when(mHalDeviceManager.removeIface(any())).thenReturn(true); when(mHalDeviceManager.getChip(any(IWifiIface.class))) .thenReturn(mIWifiChip); - when(mHalDeviceManager.createRttController()).thenReturn(mIWifiRttController); when(mIWifiChip.registerEventCallback(any(IWifiChipEventCallback.class))) .thenReturn(mWifiStatusSuccess); mIWifiStaIfaceEventCallback = null; @@ -335,9 +325,6 @@ public class WifiVendorHalTest { return (mWifiStatusSuccess); })); - when(mIWifiRttController.registerEventCallback(any(IWifiRttControllerEventCallback.class))) - .thenReturn(mWifiStatusSuccess); - doAnswer(new AnswerWithArguments() { public void answer(IWifiIface.getNameCallback cb) throws RemoteException { @@ -375,7 +362,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).start(); verify(mHalDeviceManager).createStaIface(eq(false), any(), eq(null)); verify(mHalDeviceManager).getChip(eq(mIWifiStaIface)); - verify(mHalDeviceManager).createRttController(); verify(mHalDeviceManager).isReady(); verify(mHalDeviceManager).isStarted(); verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); @@ -400,7 +386,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).isStarted(); verify(mHalDeviceManager, never()).createStaIface(anyBoolean(), any(), eq(null)); - verify(mHalDeviceManager, never()).createRttController(); } /** @@ -424,7 +409,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager, never()).createStaIface(anyBoolean(), any(), eq(null)); verify(mHalDeviceManager, never()).createApIface(any(), eq(null)); verify(mHalDeviceManager, never()).getChip(any(IWifiIface.class)); - verify(mHalDeviceManager, never()).createRttController(); verify(mIWifiStaIface, never()) .registerEventCallback(any(IWifiStaIfaceEventCallback.class)); } @@ -445,7 +429,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager, never()).createApIface(any(), eq(null)); verify(mHalDeviceManager, never()).getChip(any(IWifiIface.class)); - verify(mHalDeviceManager, never()).createRttController(); verify(mIWifiStaIface, never()) .registerEventCallback(any(IWifiStaIfaceEventCallback.class)); } @@ -455,26 +438,6 @@ public class WifiVendorHalTest { * {@link WifiVendorHal#startVendorHalSta()}. */ @Test - public void testStartHalFailureInRttControllerCreationInStaMode() throws Exception { - when(mHalDeviceManager.createRttController()).thenReturn(null); - assertFalse(mWifiVendorHal.startVendorHalSta()); - assertFalse(mWifiVendorHal.isHalStarted()); - - verify(mHalDeviceManager).start(); - verify(mHalDeviceManager).createStaIface(eq(false), any(), eq(null)); - verify(mHalDeviceManager).createRttController(); - verify(mHalDeviceManager).stop(); - verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); - - verify(mHalDeviceManager, never()).createApIface(any(), eq(null)); - verify(mHalDeviceManager, never()).getChip(any(IWifiIface.class)); - } - - /** - * Tests the failure to start HAL in STA mode using - * {@link WifiVendorHal#startVendorHalSta()}. - */ - @Test public void testStartHalFailureInChipGetInStaMode() throws Exception { when(mHalDeviceManager.getChip(any(IWifiIface.class))).thenReturn(null); assertFalse(mWifiVendorHal.startVendorHalSta()); @@ -482,7 +445,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).start(); verify(mHalDeviceManager).createStaIface(eq(false), any(), eq(null)); - verify(mHalDeviceManager).createRttController(); verify(mHalDeviceManager).getChip(any(IWifiIface.class)); verify(mHalDeviceManager).stop(); verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); @@ -506,7 +468,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).stop(); verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); - verify(mHalDeviceManager, never()).createRttController(); verify(mHalDeviceManager, never()).getChip(any(IWifiIface.class)); verify(mHalDeviceManager, never()).createApIface(any(), eq(null)); } @@ -524,7 +485,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).start(); verify(mHalDeviceManager).createStaIface(eq(false), any(), eq(null)); - verify(mHalDeviceManager).createRttController(); verify(mHalDeviceManager).getChip(any(IWifiIface.class)); verify(mHalDeviceManager).stop(); verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); @@ -549,7 +509,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager, never()).createStaIface(anyBoolean(), any(), eq(null)); verify(mHalDeviceManager, never()).getChip(any(IWifiIface.class)); - verify(mHalDeviceManager, never()).createRttController(); } /** @@ -568,7 +527,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).stop(); verify(mHalDeviceManager).createStaIface(eq(false), any(), eq(null)); verify(mHalDeviceManager).getChip(eq(mIWifiStaIface)); - verify(mHalDeviceManager).createRttController(); verify(mHalDeviceManager, times(2)).isReady(); verify(mHalDeviceManager, times(2)).isStarted(); @@ -595,7 +553,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager, times(2)).isStarted(); verify(mHalDeviceManager, never()).createStaIface(anyBoolean(), any(), eq(null)); - verify(mHalDeviceManager, never()).createRttController(); } /** @@ -615,7 +572,6 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).createStaIface(eq(false), internalListenerCaptor.capture(), eq(null)); verify(mHalDeviceManager).getChip(eq(mIWifiStaIface)); - verify(mHalDeviceManager).createRttController(); verify(mHalDeviceManager).isReady(); verify(mHalDeviceManager).isStarted(); verify(mIWifiStaIface).registerEventCallback(any(IWifiStaIfaceEventCallback.class)); @@ -1103,137 +1059,6 @@ public class WifiVendorHalTest { assertEquals(2, ex); } - - /** - * Test translations of RTT type - */ - @Test - public void testRttTypeTranslation() throws Exception { - checkRoundTripIntTranslation( - (y) -> WifiVendorHal.halRttTypeFromFrameworkRttType(y), - (x) -> WifiVendorHal.frameworkRttTypeFromHalRttType(x), - 1, 3); - } - - /** - * Test translations of peer type - */ - @Test - public void testPeerTranslation() throws Exception { - checkRoundTripIntTranslation( - (y) -> WifiVendorHal.halPeerFromFrameworkPeer(y), - (x) -> WifiVendorHal.frameworkPeerFromHalPeer(x), - 1, 6); - } - - /** - * Test translations of channel width - */ - @Test - public void testChannelWidth() throws Exception { - checkRoundTripIntTranslation( - (y) -> WifiVendorHal.halChannelWidthFromFrameworkChannelWidth(y), - (x) -> WifiVendorHal.frameworkChannelWidthFromHalChannelWidth(x), - 0, 5); - } - - /** - * Test translations of preamble type mask - */ - @Test - public void testPreambleTranslation() throws Exception { - checkRoundTripIntTranslation( - (y) -> WifiVendorHal.halPreambleFromFrameworkPreamble(y), - (x) -> WifiVendorHal.frameworkPreambleFromHalPreamble(x), - 0, 8); - } - - /** - * Test translations of bandwidth mask - */ - @Test - public void testBandwidthTranslations() throws Exception { - checkRoundTripIntTranslation( - (y) -> WifiVendorHal.halBwFromFrameworkBw(y), - (x) -> WifiVendorHal.frameworkBwFromHalBw(x), - 0, 64); - } - - /** - * Test translation of framwork RttParams to hal RttConfig - */ - @Test - public void testGetRttStuff() throws Exception { - RttManager.RttParams params = new RttManager.RttParams(); - params.bssid = "03:01:04:01:05:09"; - params.frequency = 2420; - params.channelWidth = ScanResult.CHANNEL_WIDTH_40MHZ; - params.centerFreq0 = 2440; - params.centerFreq1 = 1; - params.num_samples = 2; - params.num_retries = 3; - params.numberBurst = 4; - params.interval = 5; - params.numSamplesPerBurst = 8; - params.numRetriesPerMeasurementFrame = 6; - params.numRetriesPerFTMR = 7; - params.LCIRequest = false; - params.LCRRequest = false; - params.burstTimeout = 15; - String frameish = params.toString(); - assertFalse(frameish.contains("=0,")); // make sure all fields are initialized - RttConfig config = WifiVendorHal.halRttConfigFromFrameworkRttParams(params); - String halish = config.toString(); - StringBuffer expect = new StringBuffer(200); - expect.append("{.addr = [3, 1, 4, 1, 5, 9], .type = ONE_SIDED, .peer = AP, "); - expect.append(".channel = {.width = WIDTH_40, .centerFreq = 2420, "); - expect.append(".centerFreq0 = 2440, .centerFreq1 = 1}, "); - expect.append(".burstPeriod = 5, .numBurst = 4, .numFramesPerBurst = 8, "); - expect.append(".numRetriesPerRttFrame = 6, .numRetriesPerFtmr = 7, "); - expect.append(".mustRequestLci = false, .mustRequestLcr = false, .burstDuration = 15, "); - expect.append(".preamble = HT, .bw = BW_20MHZ}"); - assertEquals(expect.toString(), halish); - } - - /** - * Test that RTT capabilities are plumbed through - */ - @Test - public void testGetRttCapabilities() throws Exception { - RttCapabilities capabilities = new RttCapabilities(); - capabilities.lcrSupported = true; - capabilities.preambleSupport = RttPreamble.LEGACY | RttPreamble.VHT; - capabilities.bwSupport = RttBw.BW_5MHZ | RttBw.BW_20MHZ; - capabilities.mcVersion = 43; - doAnswer(new AnswerWithArguments() { - public void answer(IWifiRttController.getCapabilitiesCallback cb) - throws RemoteException { - cb.onValues(mWifiStatusSuccess, capabilities); - } - }).when(mIWifiRttController).getCapabilities(any( - IWifiRttController.getCapabilitiesCallback.class)); - - assertNull(mWifiVendorHal.getRttCapabilities()); - - assertTrue(mWifiVendorHal.startVendorHalSta()); - - RttManager.RttCapabilities actual = mWifiVendorHal.getRttCapabilities(); - assertTrue(actual.lcrSupported); - assertEquals(RttManager.PREAMBLE_LEGACY | RttManager.PREAMBLE_VHT, - actual.preambleSupported); - assertEquals(RttManager.RTT_BW_5_SUPPORT | RttManager.RTT_BW_20_SUPPORT, - actual.bwSupported); - assertEquals(43, (int) capabilities.mcVersion); - } - - /** - * Negative test of disableRttResponder - */ - @Test - public void testDisableOfUnstartedRtt() throws Exception { - assertFalse(mWifiVendorHal.disableRttResponder()); - } - /** * Test that setScanningMacOui is hooked up to the HAL correctly */ 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 751a6a4ee..59ef71666 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java @@ -23,7 +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.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -52,13 +52,10 @@ 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; /** @@ -68,12 +65,14 @@ 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); private ArgumentCaptor<HalDeviceManager.ManagerStatusListener> mHdmStatusListener = ArgumentCaptor.forClass(HalDeviceManager.ManagerStatusListener.class); + private ArgumentCaptor<HalDeviceManager.InterfaceRttControllerLifecycleCallback> + mRttLifecycleCbCaptor = ArgumentCaptor.forClass( + HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); private ArgumentCaptor<IWifiRttController.getCapabilitiesCallback> mGetCapCbCatpr = ArgumentCaptor.forClass(IWifiRttController.getCapabilitiesCallback.class); @@ -94,7 +93,6 @@ public class RttNativeTest { MockitoAnnotations.initMocks(this); when(mockHalDeviceManager.isStarted()).thenReturn(true); - when(mockHalDeviceManager.createRttController()).thenReturn(mockRttController); mStatusSuccess = new WifiStatus(); mStatusSuccess.code = WifiStatusCode.SUCCESS; @@ -104,12 +102,12 @@ 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()); + verify(mockHalDeviceManager).initialize(); + verify(mockHalDeviceManager).registerRttControllerLifecycleCallback( + mRttLifecycleCbCaptor.capture(), any()); + mRttLifecycleCbCaptor.getValue().onNewRttController(mockRttController); verify(mockRttController).registerEventCallback(any()); verify(mockRttServiceImpl).enableIfPossible(); verify(mockRttController).getCapabilities(mGetCapCbCatpr.capture()); @@ -334,18 +332,35 @@ 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(); - order.verify(mockRttServiceImpl).disable(); + // (1) simulate Wi-Fi down and send a status change indication + mRttLifecycleCbCaptor.getValue().onRttControllerDestroyed(); + 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); + } + + /** + * Validate that we react correctly (i.e. enable/disable global RTT availability) when + * notified that the RTT controller has disappear and appeared. + */ + @Test + public void testRttControllerLifecycle() throws Exception { + // RTT controller disappears + mRttLifecycleCbCaptor.getValue().onRttControllerDestroyed(); + verify(mockRttServiceImpl).disable(); + assertFalse(mDut.isReady()); + + // RTT controller re-appears (verification is x2 since 1st time is in setup()) + mRttLifecycleCbCaptor.getValue().onNewRttController(mockRttController); + verify(mockRttController, times(2)).registerEventCallback(any()); + verify(mockRttServiceImpl, times(2)).enableIfPossible(); + verify(mockRttController, times(2)).getCapabilities(mGetCapCbCatpr.capture()); + assertTrue(mDut.isReady()); + verifyNoMoreInteractions(mockRttServiceImpl, mockRttController); } @@ -449,77 +464,6 @@ 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 /** |