summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-06-20 16:19:19 -0700
committerRoshan Pius <rpius@google.com>2017-07-07 14:23:49 -0700
commitce1de180e7652e2b2313b401451ca3d9d027b372 (patch)
tree42007c5f827f8a7610999a2eb32e026638b9b281 /tests
parent61ad35a3ee80c0602bb6d4bfc20e49177aca8a9a (diff)
WifiStateMachine: Increment startup failure metrics
Increment the metrics for wifi native start failure reasons. WifiNative.setupForClientMode() and WifiNative.setupForSoftApMode() have been modified to return the reason for failure. WifiStateMachine can now use these reason codes to increment the corresponding metrics. Bug: 38457087 Test: Unit tests Change-Id: I94c4283bac1566c1edd3985d96e6f39b7dd56910
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java43
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java78
2 files changed, 103 insertions, 18 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
index d58af91fc..32d1daa92 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
@@ -31,6 +31,7 @@ import android.net.wifi.IApInterface;
import android.net.wifi.IClientInterface;
import android.net.wifi.WifiConfiguration;
import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Pair;
import org.junit.Before;
import org.junit.Test;
@@ -487,8 +488,9 @@ public class WifiNativeTest {
IClientInterface clientInterface = mock(IClientInterface.class);
when(mWificondControl.setupDriverForClientMode()).thenReturn(clientInterface);
- IClientInterface returnedClientInterface = mWifiNative.setupForClientMode();
- assertEquals(clientInterface, returnedClientInterface);
+ Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
+ assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
+ assertEquals(clientInterface, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl).setupDriverForClientMode();
}
@@ -503,8 +505,9 @@ public class WifiNativeTest {
IClientInterface clientInterface = mock(IClientInterface.class);
when(mWificondControl.setupDriverForClientMode()).thenReturn(clientInterface);
- IClientInterface returnedClientInterface = mWifiNative.setupForClientMode();
- assertEquals(clientInterface, returnedClientInterface);
+ Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
+ assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
+ assertEquals(clientInterface, statusAndClientInterface.second);
verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
verify(mWificondControl).setupDriverForClientMode();
}
@@ -517,8 +520,9 @@ public class WifiNativeTest {
public void testSetupDriverForClientModeWificondError() {
when(mWificondControl.setupDriverForClientMode()).thenReturn(null);
- IClientInterface returnedClientInterface = mWifiNative.setupForClientMode();
- assertEquals(null, returnedClientInterface);
+ Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
+ assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndClientInterface.first);
+ assertEquals(null, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl).setupDriverForClientMode();
}
@@ -530,8 +534,9 @@ public class WifiNativeTest {
public void testSetupDriverForClientModeHalError() {
when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
- IClientInterface returnedClientInterface = mWifiNative.setupForClientMode();
- assertEquals(null, returnedClientInterface);
+ Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
+ assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndClientInterface.first);
+ assertEquals(null, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl, never()).setupDriverForClientMode();
}
@@ -544,8 +549,9 @@ public class WifiNativeTest {
IApInterface apInterface = mock(IApInterface.class);
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(apInterface);
- IApInterface returnedApInterface = mWifiNative.setupForSoftApMode();
- assertEquals(apInterface, returnedApInterface);
+ Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
+ assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
+ assertEquals(apInterface, statusAndApInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl).setupDriverForSoftApMode();
}
@@ -560,8 +566,9 @@ public class WifiNativeTest {
IApInterface apInterface = mock(IApInterface.class);
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(apInterface);
- IApInterface returnedApInterface = mWifiNative.setupForSoftApMode();
- assertEquals(apInterface, returnedApInterface);
+ Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
+ assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
+ assertEquals(apInterface, statusAndApInterface.second);
verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
verify(mWificondControl).setupDriverForSoftApMode();
}
@@ -573,9 +580,11 @@ public class WifiNativeTest {
@Test
public void testSetupDriverForSoftApModeWificondError() {
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(null);
- IApInterface returnedApInterface = mWifiNative.setupForSoftApMode();
- assertEquals(null, returnedApInterface);
+ Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
+ assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndApInterface.first);
+ assertEquals(null, statusAndApInterface.second);
+
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl).setupDriverForSoftApMode();
}
@@ -587,8 +596,10 @@ public class WifiNativeTest {
public void testSetupDriverForSoftApModeHalError() {
when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
- IApInterface returnedApInterface = mWifiNative.setupForSoftApMode();
- assertEquals(null, returnedApInterface);
+ Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
+ assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndApInterface.first);
+ assertEquals(null, statusAndApInterface.second);
+
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl, never()).setupDriverForSoftApMode();
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index f2ec4d709..4568b743e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -84,6 +84,7 @@ import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
+import android.util.Pair;
import android.util.SparseArray;
import com.android.internal.R;
@@ -379,8 +380,10 @@ public class WifiStateMachineTest {
when(mWifiInjector.getWifiNative()).thenReturn(mWifiNative);
when(mWifiInjector.getSelfRecovery()).thenReturn(mSelfRecovery);
- when(mWifiNative.setupForClientMode()).thenReturn(mClientInterface);
- when(mWifiNative.setupForSoftApMode()).thenReturn(mApInterface);
+ when(mWifiNative.setupForClientMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_SUCCESS, mClientInterface));
+ when(mWifiNative.setupForSoftApMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_SUCCESS, mApInterface));
when(mApInterface.getInterfaceName()).thenReturn(WIFI_IFACE_NAME);
when(mWifiNative.getInterfaceName()).thenReturn(WIFI_IFACE_NAME);
when(mWifiNative.enableSupplicant()).thenReturn(true);
@@ -501,6 +504,7 @@ public class WifiStateMachineTest {
assertEquals("SoftApState", getCurrentState().getName());
+ verify(mWifiNative).setupForSoftApMode();
verify(mSoftApManager).start();
// reset expectations for mContext due to previously sent AP broadcast
@@ -1794,4 +1798,74 @@ public class WifiStateMachineTest {
mLooper.stopAutoDispatch();
assertFalse(succeeded);
}
+
+ /**
+ * Test that failure to start HAL in AP mode increments the corresponding metrics.
+ */
+ @Test
+ public void testSetupForSoftApModeHalFailureIncrementsMetrics() throws Exception {
+ when(mWifiNative.setupForSoftApMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_FAILURE_HAL, null));
+
+ SoftApModeConfiguration config = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
+ mLooper.dispatchAll();
+
+ verify(mWifiNative).setupForSoftApMode();
+ verify(mWifiMetrics).incrementNumWifiOnFailureDueToHal();
+ }
+
+ /**
+ * Test that failure to start HAL in AP mode increments the corresponding metrics.
+ */
+ @Test
+ public void testSetupForSoftApModeWificondFailureIncrementsMetrics() throws Exception {
+ when(mWifiNative.setupForSoftApMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_FAILURE_WIFICOND, null));
+
+ SoftApModeConfiguration config = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
+ mLooper.dispatchAll();
+
+ verify(mWifiNative).setupForSoftApMode();
+ verify(mWifiMetrics).incrementNumWifiOnFailureDueToWificond();
+ }
+
+ /**
+ * Test that failure to start HAL in client mode increments the corresponding metrics.
+ */
+ @Test
+ public void testSetupForClientModeHalFailureIncrementsMetrics() throws Exception {
+ when(mWifiNative.setupForClientMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_FAILURE_HAL, null));
+
+ mWsm.setSupplicantRunning(true);
+ mLooper.dispatchAll();
+
+ mWsm.sendMessage(WifiMonitor.SUP_CONNECTION_EVENT);
+ mLooper.dispatchAll();
+
+ verify(mWifiNative).setupForClientMode();
+ verify(mWifiMetrics).incrementNumWifiOnFailureDueToHal();
+ }
+
+ /**
+ * Test that failure to start HAL in client mode increments the corresponding metrics.
+ */
+ @Test
+ public void testSetupForClientModeWificondFailureIncrementsMetrics() throws Exception {
+ when(mWifiNative.setupForClientMode())
+ .thenReturn(Pair.create(WifiNative.SETUP_FAILURE_WIFICOND, null));
+
+ mWsm.setSupplicantRunning(true);
+ mLooper.dispatchAll();
+
+ mWsm.sendMessage(WifiMonitor.SUP_CONNECTION_EVENT);
+ mLooper.dispatchAll();
+
+ verify(mWifiNative).setupForClientMode();
+ verify(mWifiMetrics).incrementNumWifiOnFailureDueToWificond();
+ }
}