diff options
author | Oscar Shu <xshu@google.com> | 2018-04-24 18:32:08 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-04-24 18:32:08 +0000 |
commit | 61b3c8fc8d4af0ed5283520dcd7b40723721d720 (patch) | |
tree | d9245124644692b4660270b3aa5effc2975eeaa8 /tests | |
parent | 27fc131752a0742318d2c952e8ac64635dbb6990 (diff) | |
parent | d9d2a093b6f1613f08c72798f0dee7abdedc8213 (diff) |
Merge changes Ic48999b4,I6756f9ee into pi-dev
* changes:
LRWD: Remove obsolete snapshot grabbing check
LRWD: masking bugreport triggers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java | 110 |
1 files changed, 66 insertions, 44 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java index 1cd9750fe..3809c7f74 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -901,7 +901,7 @@ public class WifiLastResortWatchdogTest { int dhcpFailures = 11; // Set Watchdogs internal wifi state tracking to 'connected' - mLastResortWatchdog.connectedStateTransition(true, ""); + mLastResortWatchdog.connectedStateTransition(true); // Buffer potential candidates 1,2,3 & 4 List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates(mSsids, @@ -980,7 +980,7 @@ public class WifiLastResortWatchdogTest { assertFailureCountEquals(mBssids[2], 0, 0, dhcpFailures); // Transition to 'ConnectedState' - mLastResortWatchdog.connectedStateTransition(true, ""); + mLastResortWatchdog.connectedStateTransition(true); // Check that we have no failures for (int i = 0; i < mSsids.length; i++) { @@ -1234,7 +1234,7 @@ public class WifiLastResortWatchdogTest { mLastResortWatchdog.updateAvailableNetworks(candidates); // Set Watchdogs internal wifi state tracking to 'connected' - mLastResortWatchdog.connectedStateTransition(true, ""); + mLastResortWatchdog.connectedStateTransition(true); // Count failures on all 4 networks until all of them are over the failure threshold boolean watchdogTriggered = false; @@ -1349,8 +1349,8 @@ public class WifiLastResortWatchdogTest { } // transition Watchdog wifi state tracking to 'connected' then back to 'disconnected' - mLastResortWatchdog.connectedStateTransition(true, ""); - mLastResortWatchdog.connectedStateTransition(false, ""); + mLastResortWatchdog.connectedStateTransition(true); + mLastResortWatchdog.connectedStateTransition(false); // Fail 3/4 networks until they're over threshold for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD + 1; i++) { @@ -1492,7 +1492,7 @@ public class WifiLastResortWatchdogTest { verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggersWithBadDhcp(); // Simulate wifi connecting after triggering - mLastResortWatchdog.connectedStateTransition(true, "\"test1\""); + mLastResortWatchdog.connectedStateTransition(true); // Verify that WifiMetrics counted this as a Watchdog success verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); @@ -1503,7 +1503,7 @@ public class WifiLastResortWatchdogTest { verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); // Simulate wifi disconnecting - mLastResortWatchdog.connectedStateTransition(false, "\"test1\""); + mLastResortWatchdog.connectedStateTransition(false); // Verify that WifiMetrics has still only counted one success verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); @@ -1546,7 +1546,7 @@ public class WifiLastResortWatchdogTest { mLastResortWatchdog.updateAvailableNetworks(candidates); // Simulate wifi connecting - mLastResortWatchdog.connectedStateTransition(true, ""); + mLastResortWatchdog.connectedStateTransition(true); // Verify that WifiMetrics did not count another success, as the connection could be due // to the newly available network #5 @@ -1729,13 +1729,10 @@ public class WifiLastResortWatchdogTest { } /** - * Case 29: Test connection success after wifi restart with an unexpected SSID - * Setup 1 network. Fail the network until watchcdog triggers. Trigger a connection success on - * a network which has a different SSID than the network that has been failing. - * Expected behavior: bugreport is not triggered + * Test metrics incrementing connection failure count after watchdog has already been triggered */ @Test - public void testConnectionSuccessWithUnexpectedSsidDoesNotTriggerBugreport() { + public void testIncrementingWatchdogConnectionFailuresAfterTrigger() { String[] ssids = {"\"test1\""}; String[] bssids = {"6c:f3:7f:ae:8c:f3"}; int[] frequencies = {2437}; @@ -1761,28 +1758,26 @@ public class WifiLastResortWatchdogTest { // Verify relevant WifiMetrics calls were made once with appropriate arguments verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggers(); - // Simulate wifi connecting after triggering on a unexpected SSID - mLastResortWatchdog.connectedStateTransition(true, "blahssss"); - // Verify takeBugReport is not called - mLooper.dispatchAll(); - verify(mWifiStateMachine, times(0)).takeBugReport(anyString(), anyString()); + // Verify that failure count after trigger is not incremented yet + verify(mWifiMetrics, never()).incrementWatchdogTotalConnectionFailureCountAfterTrigger(); - // Simulate wifi connecting after triggering is the expected SSID, which should be ignored - // because watchdog state should already be reset to detect for failures - mLastResortWatchdog.connectedStateTransition(true, "\"test1\""); - // Verify takeBugReport is not called - mLooper.dispatchAll(); - verify(mWifiStateMachine, times(0)).takeBugReport(anyString(), anyString()); + // Fail 1 more time and verify this time it's counted + mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( + ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); + verify(mWifiMetrics, times(1)).incrementWatchdogTotalConnectionFailureCountAfterTrigger(); } /** - * Case 30: Test connection success after wifi restart with a previously failing SSID - * Setup 1 network. Fail the network until watchcdog triggers. Trigger a connection success on - * a network which has the same SSID than the network that has been failing. - * Expected behavior: bugreport is triggered + * Test that LRWD success is only declared when the first connection after restarting wifi + * is successful. + * + * First tests the failure case: check success metric is not incremented when the first + * connection is a failure. + * Then test state transition and the success case: check success metric is incremented + * when the first connection is a success. */ @Test - public void testConnectionSuccessWithPreviouslyFailingSsidTriggersBugreport() { + public void testWatchdogAssumesSuccessOnlyIfFirstConnectionAfterRestartSucceeds() { String[] ssids = {"\"test1\""}; String[] bssids = {"6c:f3:7f:ae:8c:f3"}; int[] frequencies = {2437}; @@ -1805,28 +1800,53 @@ public class WifiLastResortWatchdogTest { ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); } - // Verify relevant WifiMetrics calls were made once with appropriate arguments + // Verify watchdog has triggered a restart verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggers(); + // Fail 1 more time and verify this time it's counted + mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( + ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); + // Simulate wifi connecting after triggering - mLastResortWatchdog.connectedStateTransition(true, "\"test1\""); - // Verify takeBugReport is called + mLastResortWatchdog.connectedStateTransition(true); + // Verify takeBugReport is not called again mLooper.dispatchAll(); - verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); + verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, never()).incrementNumLastResortWatchdogSuccesses(); + // Simulate wifi disconnecting + mLastResortWatchdog.connectedStateTransition(false); + + // Test another round, and this time successfully connect after restart trigger + for (int i = 0; i < ssids.length; i++) { + assertFailureCountEquals(bssids[i], 0, 0, 0); + } + for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) { + mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( + ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); + } + + // Verify watchdog has triggered a restart + verify(mWifiMetrics, times(2)).incrementNumLastResortWatchdogTriggers(); // Simulate wifi connecting after triggering - mLastResortWatchdog.connectedStateTransition(true, "\"test1\""); + mLastResortWatchdog.connectedStateTransition(true); // Verify takeBugReport is not called again mLooper.dispatchAll(); verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); } - /** - * Test metrics incrementing connection failure count after watchdog has already been triggered + * If the user changes the configuration and then we have a successful connection, don't + * trigger bugreport. + * Tests this specific path: + * 1. watchdog triggers restart + * 2. wifi configuration changes + * 3. wifi successfully connects immedietly after + * Expected result: bugreport should not trigger */ @Test - public void testIncrementingWatchdogConnectionFailuresAfterTrigger() { + public void testWatchdogVerifiesAtLeastOneNetworkIsConnectedBeforeTriggeringBugreport() { String[] ssids = {"\"test1\""}; String[] bssids = {"6c:f3:7f:ae:8c:f3"}; int[] frequencies = {2437}; @@ -1849,15 +1869,17 @@ public class WifiLastResortWatchdogTest { ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); } - // Verify relevant WifiMetrics calls were made once with appropriate arguments + // Verify watchdog has triggered a restart verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggers(); - // Verify that failure count after trigger is not incremented yet - verify(mWifiMetrics, never()).incrementWatchdogTotalConnectionFailureCountAfterTrigger(); + // Simulate user changing the configuration + when(candidates.get(0).second.getNetworkSelectionStatus().getHasEverConnected()) + .thenReturn(false); - // Fail 1 more time and verify this time it's counted - mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( - ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); - verify(mWifiMetrics, times(1)).incrementWatchdogTotalConnectionFailureCountAfterTrigger(); + mLastResortWatchdog.connectedStateTransition(true); + // Verify takeBugReport is not called again + mLooper.dispatchAll(); + verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, never()).incrementNumLastResortWatchdogSuccesses(); } } |