diff options
author | Roshan Pius <rpius@google.com> | 2020-04-08 09:09:37 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-04-09 09:07:35 -0700 |
commit | 11c234cedda86e8b3a863f54d2a32d9c6730e258 (patch) | |
tree | 2800aba093dabf5429bb8995dbd2ddbcf21dc19d /tests | |
parent | 82298418fe24c1d0d8f62ba1b79e55d168bf6351 (diff) |
SelfRecovery: Add overlay for the recovery limit
Bug: 153395624
Test: atest com.android.server.wifi
Test: Manually crash wpa_supplicant from shell:
- Ensured that we restarted the stack the first 2 attempts.
- Ensured that we disabled wifi for all further attempts.
Change-Id: Iafcd193e373f7e6530446e69a927e2dd0056f402
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java index fe8bfd575..3538598c3 100644 --- a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java @@ -19,25 +19,39 @@ package com.android.server.wifi; import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.*; +import android.content.Context; + import androidx.test.filters.SmallTest; +import com.android.wifi.resources.R; + import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import java.util.concurrent.TimeUnit; + /** * Unit tests for {@link com.android.server.wifi.SelfRecovery}. */ @SmallTest public class SelfRecoveryTest extends WifiBaseTest { + private static final int DEFAULT_MAX_RECOVERY_PER_HOUR = 2; SelfRecovery mSelfRecovery; + MockResources mResources; + @Mock Context mContext; @Mock ActiveModeWarden mActiveModeWarden; @Mock Clock mClock; @Before public void setUp() throws Exception { initMocks(this); - mSelfRecovery = new SelfRecovery(mActiveModeWarden, mClock); + mResources = new MockResources(); + // Default value of 2 recovery per hour. + mResources.setInteger(R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour, + DEFAULT_MAX_RECOVERY_PER_HOUR); + when(mContext.getResources()).thenReturn(mResources); + mSelfRecovery = new SelfRecovery(mContext, mActiveModeWarden, mClock); } /** @@ -51,7 +65,7 @@ public class SelfRecoveryTest extends WifiBaseTest { reset(mActiveModeWarden); when(mClock.getElapsedSinceBootMillis()) - .thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1); + .thenReturn(TimeUnit.HOURS.toMillis(1) + 1); mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); reset(mActiveModeWarden); @@ -80,25 +94,16 @@ public class SelfRecoveryTest extends WifiBaseTest { } /** - * Verifies that invocations of {@link SelfRecovery#trigger(int)} for REASON_HAL_CRASH & - * REASON_WIFICOND_CRASH are limited to {@link SelfRecovery#MAX_RESTARTS_IN_TIME_WINDOW} in a - * {@link SelfRecovery#MAX_RESTARTS_TIME_WINDOW_MILLIS} millisecond time window. + * Verifies that invocations of {@link SelfRecovery#trigger(int)} for REASON_WIFI_NATIVE + * are limited to {@link R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour} in a + * 1 hour time window. */ @Test public void testTimeWindowLimiting_typicalUse() { when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); // Fill up the SelfRecovery's restart time window buffer, ensure all the restart triggers // aren't ignored - for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW / 2; i++) { - mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); - verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); - reset(mActiveModeWarden); - - mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); - verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); - reset(mActiveModeWarden); - } - if ((SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW % 2) == 1) { + for (int i = 0; i < DEFAULT_MAX_RECOVERY_PER_HOUR; i++) { mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); reset(mActiveModeWarden); @@ -128,27 +133,46 @@ public class SelfRecoveryTest extends WifiBaseTest { // now TRAVEL FORWARDS IN TIME and ensure that more restarts can occur when(mClock.getElapsedSinceBootMillis()) - .thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1); + .thenReturn(TimeUnit.HOURS.toMillis(1) + 1); mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); reset(mActiveModeWarden); when(mClock.getElapsedSinceBootMillis()) - .thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1); + .thenReturn(TimeUnit.HOURS.toMillis(1) + 1); mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); reset(mActiveModeWarden); } /** + * Verifies that invocations of {@link SelfRecovery#trigger(int)} for REASON_WIFI_NATIVE + * does not trigger recovery if {@link R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour} + * is set to 0 + */ + @Test + public void testTimeWindowLimiting_NativeFailureOff() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); + mResources.setInteger(R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour, 0); + mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE); + verify(mActiveModeWarden, never()) + .recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); + verify(mActiveModeWarden).recoveryDisableWifi(); + reset(mActiveModeWarden); + + // Verify L.R.Watchdog can still restart things (It has its own complex limiter) + mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); + verify(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); + } + + /** * Verifies that invocations of {@link SelfRecovery#trigger(int)} for * REASON_LAST_RESORT_WATCHDOG are NOT limited to - * {@link SelfRecovery#MAX_RESTARTS_IN_TIME_WINDOW} in a - * {@link SelfRecovery#MAX_RESTARTS_TIME_WINDOW_MILLIS} millisecond time window. + * {{@link R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour} in a 1 hour time window. */ @Test public void testTimeWindowLimiting_lastResortWatchdog_noEffect() { - for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW * 2; i++) { + for (int i = 0; i < DEFAULT_MAX_RECOVERY_PER_HOUR * 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(mActiveModeWarden).recoveryRestartWifi(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); @@ -159,12 +183,11 @@ public class SelfRecoveryTest extends WifiBaseTest { /** * Verifies that invocations of {@link SelfRecovery#trigger(int)} for * REASON_STA_IFACE_DOWN are NOT limited to - * {@link SelfRecovery#MAX_RESTARTS_IN_TIME_WINDOW} in a - * {@link SelfRecovery#MAX_RESTARTS_TIME_WINDOW_MILLIS} millisecond time window. + * {{@link R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour} in a 1 hour time window. */ @Test public void testTimeWindowLimiting_staIfaceDown_noEffect() { - for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW * 2; i++) { + for (int i = 0; i < DEFAULT_MAX_RECOVERY_PER_HOUR * 2; i++) { mSelfRecovery.trigger(SelfRecovery.REASON_STA_IFACE_DOWN); verify(mActiveModeWarden).recoveryDisableWifi(); verify(mActiveModeWarden, never()).recoveryRestartWifi(anyInt()); |