summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOscar Shu <xshu@google.com>2018-03-01 21:00:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-03-01 21:00:34 +0000
commitc3f1a67704f4424c7c7097ea9214d0dd7b573a70 (patch)
treec036aed617c791a5982f31173d694a4ed0ddbfab /tests
parent554a9c0136e1bb7612ced93fb1ec60bc55484dcb (diff)
parentfa60acfff0a91af90b914c7f77cd35a850f38f9e (diff)
Merge "Delay bugreport trigger for watchdog recovery"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java20
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java11
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java15
3 files changed, 34 insertions, 12 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
index 607fcd6e6..cebcc28e5 100644
--- a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
@@ -47,19 +47,19 @@ public class SelfRecoveryTest {
@Test
public void testValidTriggerReasonsSendMessageToWifiController() {
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_HAL_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(2 * (SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1));
mSelfRecovery.trigger(SelfRecovery.REASON_WIFICOND_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
}
@@ -89,16 +89,16 @@ public class SelfRecoveryTest {
// aren't ignored
for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW / 2; i++) {
mSelfRecovery.trigger(SelfRecovery.REASON_HAL_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
mSelfRecovery.trigger(SelfRecovery.REASON_WIFICOND_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
}
if ((SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW % 2) == 1) {
mSelfRecovery.trigger(SelfRecovery.REASON_WIFICOND_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
}
@@ -115,20 +115,20 @@ public class SelfRecoveryTest {
// Verify L.R.Watchdog can still restart things (It has its own complex limiter)
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
// now TRAVEL FORWARDS IN TIME and ensure that more restarts can occur
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_HAL_CRASH);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
}
@@ -143,7 +143,7 @@ public class SelfRecoveryTest {
for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW * 2; i++) {
// Verify L.R.Watchdog can still restart things (It has it's own complex limiter)
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyString());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
reset(mWifiController);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
index 43d9cab47..c1d5b03ca 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
@@ -22,6 +22,7 @@ import static com.android.server.wifi.WifiController.CMD_EMERGENCY_MODE_CHANGED;
import static com.android.server.wifi.WifiController.CMD_RESTART_WIFI;
import static com.android.server.wifi.WifiController.CMD_SET_AP;
import static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED;
+
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
@@ -290,11 +291,19 @@ public class WifiControllerTest {
@Test
public void testRestartWifiStackInStaEnabledStateTriggersBugReport() throws Exception {
enableWifi();
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RESTART_WIFI, SelfRecovery.REASON_HAL_CRASH);
mLooper.dispatchAll();
verify(mWifiStateMachine).takeBugReport(anyString(), anyString());
}
+ @Test
+ public void testRestartWifiWatchdogDoesNotTriggerBugReport() throws Exception {
+ enableWifi();
+ mWifiController.sendMessage(CMD_RESTART_WIFI, SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
+ mLooper.dispatchAll();
+ verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString());
+ }
+
/**
* The command to trigger a WiFi reset should not trigger any action by WifiController if we
* are not in STA mode.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
index 85795349a..876950865 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
@@ -23,6 +23,7 @@ import static org.mockito.MockitoAnnotations.*;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiSsid;
+import android.os.test.TestLooper;
import android.support.test.filters.SmallTest;
import android.util.Pair;
@@ -42,6 +43,8 @@ public class WifiLastResortWatchdogTest {
WifiLastResortWatchdog mLastResortWatchdog;
@Mock WifiMetrics mWifiMetrics;
@Mock SelfRecovery mSelfRecovery;
+ @Mock WifiStateMachine mWifiStateMachine;
+
private String[] mSsids = {"\"test1\"", "\"test2\"", "\"test3\"", "\"test4\""};
private String[] mBssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "de:ad:ba:b1:e5:55",
"c0:ff:ee:ee:e3:ee"};
@@ -51,11 +54,15 @@ public class WifiLastResortWatchdogTest {
private int[] mLevels = {-60, -86, -50, -62};
private boolean[] mIsEphemeral = {false, false, false, false};
private boolean[] mHasEverConnected = {false, false, false, false};
+ private TestLooper mLooper;
@Before
public void setUp() throws Exception {
initMocks(this);
- mLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mWifiMetrics);
+ mLooper = new TestLooper();
+ mLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mWifiMetrics,
+ mWifiStateMachine, mLooper.getLooper());
+ mLastResortWatchdog.setBugReportProbability(1);
}
private List<Pair<ScanDetail, WifiConfiguration>> createFilteredQnsCandidates(String[] ssids,
@@ -1483,12 +1490,18 @@ public class WifiLastResortWatchdogTest {
// Verify that WifiMetrics counted this as a Watchdog success
verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses();
+ // Verify takeBugReport is called
+ mLooper.dispatchAll();
+ verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString());
// Simulate wifi disconnecting
mLastResortWatchdog.connectedStateTransition(false);
// Verify that WifiMetrics has still only counted one success
verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses();
+ // Verify takeBugReport not called again
+ mLooper.dispatchAll();
+ verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString());
// Remove the fifth network from candidates
candidates = createFilteredQnsCandidates(Arrays.copyOfRange(mSsids, 0, 4),