diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java | 99 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java | 150 |
2 files changed, 197 insertions, 52 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index fb583ca1b..a8c9d3409 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -37,6 +37,7 @@ import android.content.Context; import android.hardware.wifi.supplicant.V1_0.ISupplicant; import android.hardware.wifi.supplicant.V1_0.ISupplicantIface; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; import android.hardware.wifi.supplicant.V1_0.IfaceType; import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; @@ -87,6 +88,7 @@ public class SupplicantStaIfaceHalTest { ISupplicant.IfaceInfo mStaIface; ISupplicant.IfaceInfo mP2pIface; ArrayList<ISupplicant.IfaceInfo> mIfaceInfoList; + ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback; private SupplicantStaIfaceHal mDut; private ArgumentCaptor<IHwBinder.DeathRecipient> mDeathRecipientCaptor = ArgumentCaptor.forClass(IHwBinder.DeathRecipient.class); @@ -146,7 +148,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testInitialize_success() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(false, false, false, false); } /** @@ -155,7 +157,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testInitialize_remoteExceptionFailure() throws Exception { - executeAndValidateInitializationSequence(true, false, false); + executeAndValidateInitializationSequence(true, false, false, false); } /** @@ -164,7 +166,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testInitialize_zeroInterfacesFailure() throws Exception { - executeAndValidateInitializationSequence(false, true, false); + executeAndValidateInitializationSequence(false, true, false, false); } /** @@ -173,7 +175,16 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testInitialize_nullInterfaceFailure() throws Exception { - executeAndValidateInitializationSequence(false, false, true); + executeAndValidateInitializationSequence(false, false, true, false); + } + + /** + * Tests the initialization flow, with a callback registration failure. + * Ensures initialization fails. + */ + @Test + public void testInitialize_callbackRegistrationFailure() throws Exception { + executeAndValidateInitializationSequence(false, false, false, true); } /** @@ -182,7 +193,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testLoadNetworks() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); @@ -235,7 +246,7 @@ public class SupplicantStaIfaceHalTest { // Network ID which will have the same config key as the previous one. final int duplicateNetworkId = 2; final int toRemoveNetworkId = duplicateNetworkId - 1; - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); @@ -306,7 +317,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testLoadNetworksFailedDueToListNetworks() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusFailure, null); @@ -324,7 +335,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testLoadNetworksFailedDueToGetNetwork() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); @@ -349,7 +360,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testLoadNetworksFailedDueToLoadWifiConfiguration() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); @@ -373,7 +384,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectWithNoDisconnectAndEmptyExistingNetworks() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); executeAndValidateConnectSequence(0, false, false); } @@ -382,7 +393,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectWithNoDisconnectAndSingleExistingNetwork() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); executeAndValidateConnectSequence(0, true, false); } @@ -391,7 +402,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectWithDisconnectAndSingleExistingNetwork() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); executeAndValidateConnectSequence(0, false, true); } @@ -400,7 +411,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectFailureDueToNetworkAddFailure() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); setupMocksForConnectSequence(false); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.addNetworkCallback cb) throws RemoteException { @@ -418,7 +429,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectFailureDueToNetworkSaveFailure() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); setupMocksForConnectSequence(false); when(mSupplicantStaNetworkMock.saveWifiConfiguration(any(WifiConfiguration.class))) @@ -432,7 +443,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testConnectFailureDueToNetworkSelectFailure() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); setupMocksForConnectSequence(false); when(mSupplicantStaNetworkMock.select()).thenReturn(false); @@ -445,7 +456,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testRoamToSameNetwork() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); executeAndValidateRoamSequence(true); } @@ -454,7 +465,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testRoamToDifferentNetwork() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); executeAndValidateRoamSequence(false); } @@ -463,7 +474,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testRoamFailureDueToBssidSet() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); int connectedNetworkId = 5; executeAndValidateConnectSequence(connectedNetworkId, false, false); when(mSupplicantStaNetworkMock.setBssid(anyString())).thenReturn(false); @@ -479,7 +490,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testRemoveAllNetworks() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); doAnswer(new MockAnswerUtil.AnswerWithArguments() { public void answer(ISupplicantStaIface.listNetworksCallback cb) { cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); @@ -502,7 +513,7 @@ public class SupplicantStaIfaceHalTest { */ @Test public void testRoamFailureDueToReassociate() throws Exception { - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); int connectedNetworkId = 5; executeAndValidateConnectSequence(connectedNetworkId, false, false); @@ -527,7 +538,7 @@ public class SupplicantStaIfaceHalTest { String token = "45adbc1"; when(mSupplicantStaNetworkMock.getWpsNfcConfigurationToken()).thenReturn(token); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // Return null when not connected to the network. assertTrue(mDut.getCurrentNetworkWpsNfcConfigurationToken() == null); @@ -545,7 +556,7 @@ public class SupplicantStaIfaceHalTest { String bssidStr = "34:34:12:12:12:90"; when(mSupplicantStaNetworkMock.setBssid(eq(bssidStr))).thenReturn(true); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // Fail when not connected to a network. assertFalse(mDut.setCurrentNetworkBssid(bssidStr)); @@ -567,7 +578,7 @@ public class SupplicantStaIfaceHalTest { when(mISupplicantStaIfaceMock.setWpsDeviceType(any(byte[].class))) .thenReturn(mStatusSuccess); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // This should work. assertTrue(mDut.setWpsDeviceType(validDeviceTypeStr)); @@ -590,7 +601,7 @@ public class SupplicantStaIfaceHalTest { String invalidConfigMethodsStr = "physical_display virtual_push_button test"; when(mISupplicantStaIfaceMock.setWpsConfigMethods(anyShort())).thenReturn(mStatusSuccess); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // This should work. assertTrue(mDut.setWpsConfigMethods(validConfigMethodsStr)); @@ -605,6 +616,10 @@ public class SupplicantStaIfaceHalTest { assertTrue(false); } + private void executeAndValidateInitializationSequence() throws Exception { + executeAndValidateInitializationSequence(false, false, false, false); + } + /** * Tests the setting of log level. */ @@ -616,7 +631,7 @@ public class SupplicantStaIfaceHalTest { // Fail before initialization is performed. assertFalse(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG)); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // This should work. assertTrue(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG)); @@ -634,7 +649,7 @@ public class SupplicantStaIfaceHalTest { // Fail before initialization is performed. assertFalse(mDut.setConcurrencyPriority(false)); - executeAndValidateInitializationSequence(false, false, false); + executeAndValidateInitializationSequence(); // This should work. assertTrue(mDut.setConcurrencyPriority(false)); @@ -650,9 +665,12 @@ public class SupplicantStaIfaceHalTest { */ private void executeAndValidateInitializationSequence(boolean causeRemoteException, boolean getZeroInterfaces, - boolean getNullInterface) + boolean getNullInterface, + boolean causeCallbackRegFailure) throws Exception { - boolean shouldSucceed = !causeRemoteException && !getZeroInterfaces && !getNullInterface; + boolean shouldSucceed = + !causeRemoteException && !getZeroInterfaces && !getNullInterface + && !causeCallbackRegFailure; // Setup callback mock answers ArrayList<ISupplicant.IfaceInfo> interfaces; if (getZeroInterfaces) { @@ -671,8 +689,27 @@ public class SupplicantStaIfaceHalTest { .when(mISupplicantMock).getInterface(any(ISupplicant.IfaceInfo.class), any(ISupplicant.getInterfaceCallback.class)); } + /** Callback registeration */ + if (causeCallbackRegFailure) { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public SupplicantStatus answer(ISupplicantStaIfaceCallback cb) + throws RemoteException { + return mStatusFailure; + } + }).when(mISupplicantStaIfaceMock) + .registerCallback(any(ISupplicantStaIfaceCallback.class)); + } else { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public SupplicantStatus answer(ISupplicantStaIfaceCallback cb) + throws RemoteException { + mISupplicantStaIfaceCallback = cb; + return mStatusSuccess; + } + }).when(mISupplicantStaIfaceMock) + .registerCallback(any(ISupplicantStaIfaceCallback.class)); + } - mInOrder = inOrder(mServiceManagerMock, mISupplicantMock); + mInOrder = inOrder(mServiceManagerMock, mISupplicantMock, mISupplicantStaIfaceMock); // Initialize SupplicantStaIfaceHal, should call serviceManager.registerForNotifications assertTrue(mDut.initialize()); // verify: service manager initialization sequence @@ -692,6 +729,10 @@ public class SupplicantStaIfaceHalTest { .getInterface(any(ISupplicant.IfaceInfo.class), any(ISupplicant.getInterfaceCallback.class)); } + if (!causeRemoteException && !getZeroInterfaces && !getNullInterface) { + mInOrder.verify(mISupplicantStaIfaceMock) + .registerCallback(any(ISupplicantStaIfaceCallback.class)); + } } private SupplicantStatus createSupplicantStatus(int code) { diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java index c1596f00a..48c478948 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java @@ -16,14 +16,21 @@ package com.android.server.wifi; import static org.junit.Assert.*; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.content.Context; import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback + .NetworkRequestEapSimGsmAuthParams; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback + .NetworkRequestEapSimUmtsAuthParams; import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode; import android.net.wifi.WifiConfiguration; @@ -42,12 +49,13 @@ import org.mockito.MockitoAnnotations; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Random; /** * Unit tests for SupplicantStaNetworkHal */ public class SupplicantStaNetworkHalTest { - private static final String TAG = "SupplicantStaNetworkHalTest"; + private static final String IFACE_NAME = "wlan0"; private SupplicantStaNetworkHal mSupplicantNetwork; private SupplicantStatus mStatusSuccess; @@ -57,6 +65,7 @@ public class SupplicantStaNetworkHalTest { @Mock private WifiMonitor mWifiMonitor; private SupplicantNetworkVariables mSupplicantVariables; private MockResources mResources; + private ISupplicantStaNetworkCallback mISupplicantStaNetworkCallback; @Before public void setUp() throws Exception { @@ -600,6 +609,111 @@ public class SupplicantStaNetworkHalTest { WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); } + /** + * Tests the retrieval of WPS NFC token. + */ + @Test + public void testGetWpsNfcConfigurationToken() throws Exception { + final ArrayList<Byte> token = new ArrayList<>(); + token.add(Byte.valueOf((byte) 0x45)); + token.add(Byte.valueOf((byte) 0x34)); + + doAnswer(new AnswerWithArguments() { + public void answer(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback cb) + throws RemoteException { + cb.onValues(mStatusSuccess, token); + } + }).when(mISupplicantStaNetworkMock) + .getWpsNfcConfigurationToken( + any(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback.class)); + + assertEquals("4534", mSupplicantNetwork.getWpsNfcConfigurationToken()); + } + + /** + * Tests that callback registration failure triggers a failure in saving network config. + */ + @Test + public void testSaveFailureDueToCallbackReg() throws Exception { + when(mISupplicantStaNetworkMock.registerCallback(any(ISupplicantStaNetworkCallback.class))) + .thenReturn(mStatusFailure); + WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); + assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); + } + + /** + * Tests the network gsm auth callback. + */ + @Test + public void testNetworkEapGsmAuthCallback() throws Exception { + WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); + assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); + assertNotNull(mISupplicantStaNetworkCallback); + + // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor. + NetworkRequestEapSimGsmAuthParams params = new NetworkRequestEapSimGsmAuthParams(); + Random random = new Random(); + byte[] rand1 = new byte[16]; + byte[] rand2 = new byte[16]; + byte[] rand3 = new byte[16]; + random.nextBytes(rand1); + random.nextBytes(rand2); + random.nextBytes(rand3); + params.rands.add(rand1); + params.rands.add(rand2); + params.rands.add(rand3); + + String[] expectedRands = { + NativeUtil.hexStringFromByteArray(rand1), NativeUtil.hexStringFromByteArray(rand2), + NativeUtil.hexStringFromByteArray(rand3) + }; + + mISupplicantStaNetworkCallback.onNetworkEapSimGsmAuthRequest(params); + verify(mWifiMonitor).broadcastNetworkGsmAuthRequestEvent( + eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands)); + } + + /** + * Tests the network umts auth callback. + */ + @Test + public void testNetworkEapUmtsAuthCallback() throws Exception { + WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); + assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); + assertNotNull(mISupplicantStaNetworkCallback); + + // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor. + NetworkRequestEapSimUmtsAuthParams params = new NetworkRequestEapSimUmtsAuthParams(); + Random random = new Random(); + random.nextBytes(params.autn); + random.nextBytes(params.rand); + + String[] expectedRands = { + NativeUtil.hexStringFromByteArray(params.autn), + NativeUtil.hexStringFromByteArray(params.rand) + }; + + mISupplicantStaNetworkCallback.onNetworkEapSimUmtsAuthRequest(params); + verify(mWifiMonitor).broadcastNetworkUmtsAuthRequestEvent( + eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands)); + } + + /** + * Tests the network identity callback. + */ + @Test + public void testNetworkIdentityCallback() throws Exception { + WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); + assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); + assertNotNull(mISupplicantStaNetworkCallback); + + // Now trigger identity request callback and ensure that the event is broadcast via + // WifiMonitor. + mISupplicantStaNetworkCallback.onNetworkEapIdentityRequest(); + verify(mWifiMonitor).broadcastNetworkIdentityRequestEvent( + eq(IFACE_NAME), eq(config.networkId), eq(config.SSID)); + } + private void testWifiConfigurationSaveLoad(WifiConfiguration config) { assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); WifiConfiguration loadConfig = new WifiConfiguration(); @@ -628,27 +742,6 @@ public class SupplicantStaNetworkHalTest { } /** - * Tests the retrieval of WPS NFC token. - */ - @Test - public void testGetWpsNfcConfigurationToken() throws Exception { - final ArrayList<Byte> token = new ArrayList<>(); - token.add(Byte.valueOf((byte) 0x45)); - token.add(Byte.valueOf((byte) 0x34)); - - doAnswer(new AnswerWithArguments() { - public void answer(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback cb) - throws RemoteException { - cb.onValues(mStatusSuccess, token); - } - }).when(mISupplicantStaNetworkMock) - .getWpsNfcConfigurationToken( - any(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback.class)); - - assertEquals("4534", mSupplicantNetwork.getWpsNfcConfigurationToken()); - } - - /** * Sets up the HIDL interface mock with all the setters/getter values. * Note: This only sets up the mock to return success on all methods. */ @@ -1086,6 +1179,16 @@ public class SupplicantStaNetworkHalTest { return mStatusSuccess; } }).when(mISupplicantStaNetworkMock).setProactiveKeyCaching(any(boolean.class)); + + /** Callback registeration */ + doAnswer(new AnswerWithArguments() { + public SupplicantStatus answer(ISupplicantStaNetworkCallback cb) + throws RemoteException { + mISupplicantStaNetworkCallback = cb; + return mStatusSuccess; + } + }).when(mISupplicantStaNetworkMock) + .registerCallback(any(ISupplicantStaNetworkCallback.class)); } private SupplicantStatus createSupplicantStatus(int code) { @@ -1099,7 +1202,8 @@ public class SupplicantStaNetworkHalTest { */ private void createSupplicantStaNetwork() { mSupplicantNetwork = - new SupplicantStaNetworkHal(mISupplicantStaNetworkMock, mContext, mWifiMonitor); + new SupplicantStaNetworkHal( + mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor); } // Private class to to store/inspect values set via the HIDL mock. |