diff options
author | Jong Wook Kim <jongwook@google.com> | 2018-03-16 16:19:34 -0700 |
---|---|---|
committer | mukesh agrawal <quiche@google.com> | 2018-03-30 14:07:48 -0700 |
commit | 1c7f0d2c83318cdd1c127a083362e91765c0d941 (patch) | |
tree | 60bdda8edc06bd6e98766289b01a4b6ffa955339 /tests | |
parent | 9adae7cd853e952b4528d6faa874556772ba3b4d (diff) |
Move setMacAddress from wifiCond to vendor HAL
To dynamically set MAC address, use Vendor HAL instead of wificond to
give vendors flexibility of implementing their own versions of
setMacAddress.
Bug: 74347653
Test: Unittest
Test: Manual Test
Change-Id: I5dbcf3dfd7190e0cd9b36b1b66e8aaf3fe5f5435
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java | 73 |
2 files changed, 73 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index bc383aee0..546a33c05 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -565,11 +565,11 @@ public class WifiNativeTest { } /** - * Verifies that setMacAddress() calls underlying WificondControl. + * Verifies that setMacAddress() calls underlying WifiVendorHal. */ @Test public void testSetMacAddress() throws Exception { mWifiNative.setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); - verify(mWificondControl).setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); + verify(mWifiVendorHal).setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 9da4c70b9..70c612918 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.anyShort; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -75,6 +76,7 @@ import android.hardware.wifi.V1_0.WifiInformationElement; import android.hardware.wifi.V1_0.WifiStatus; import android.hardware.wifi.V1_0.WifiStatusCode; import android.net.KeepalivePacketData; +import android.net.MacAddress; import android.net.apf.ApfCapabilities; import android.net.wifi.RttManager; import android.net.wifi.ScanResult; @@ -113,6 +115,8 @@ import java.util.Set; public class WifiVendorHalTest { private static final String TEST_IFACE_NAME = "wlan0"; + private static final MacAddress TEST_MAC_ADDRESS = MacAddress.fromString("ee:33:a2:94:10:92"); + WifiVendorHal mWifiVendorHal; private WifiStatus mWifiStatusSuccess; private WifiStatus mWifiStatusFailure; @@ -134,6 +138,8 @@ public class WifiVendorHalTest { @Mock private IWifiStaIface mIWifiStaIface; @Mock + private android.hardware.wifi.V1_2.IWifiStaIface mIWifiStaIfaceV12; + @Mock private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; @@ -159,11 +165,17 @@ public class WifiVendorHalTest { protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { return null; } + + @Override + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + String ifaceName) { + return null; + } } /** - * Spy used to return the V1_2 IWifiChip mock object to simulate the 1.2 HAL running on the - * device. + * Spy used to return the V1_2 IWifiChip and IWifiStaIface mock objects to simulate + * the 1.2 HAL running on the device. */ private class WifiVendorHalSpyV1_2 extends WifiVendorHal { WifiVendorHalSpyV1_2(HalDeviceManager halDeviceManager, Looper looper) { @@ -179,6 +191,12 @@ public class WifiVendorHalTest { protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { return mIWifiChipV12; } + + @Override + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + String ifaceName) { + return mIWifiStaIfaceV12; + } } /** @@ -2089,6 +2107,57 @@ public class WifiVendorHalTest { testAlertCallbackUsingProvidedCallback(mIWifiChipEventCallbackV12); } + /** + * Verifies setMacAddress() success. + */ + @Test + public void testSetMacAddressSuccess() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + when(mIWifiStaIfaceV12.setMacAddress(macByteArray)).thenReturn(mWifiStatusSuccess); + + assertTrue(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() can handle failure status. + */ + @Test + public void testSetMacAddressFailDueToStatusFailure() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + when(mIWifiStaIfaceV12.setMacAddress(macByteArray)).thenReturn(mWifiStatusFailure); + + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() can handle RemoteException. + */ + @Test + public void testSetMacAddressFailDueToRemoteException() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + doThrow(new RemoteException()).when(mIWifiStaIfaceV12).setMacAddress(macByteArray); + + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() does not crash with older HALs. + */ + @Test + public void testSetMacAddressDoesNotCrashOnOlderHal() throws Exception { + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + } + private void testAlertCallbackUsingProvidedCallback(IWifiChipEventCallback chipCallback) throws Exception { when(mIWifiChip.enableDebugErrorAlerts(anyBoolean())).thenReturn(mWifiStatusSuccess); |