diff options
author | xshu <xshu@google.com> | 2018-04-17 15:46:53 -0700 |
---|---|---|
committer | xshu <xshu@google.com> | 2018-04-23 15:02:28 -0700 |
commit | ac16e622382ff0b82b0b47c102938d5103ddb53a (patch) | |
tree | 419c7b4e3e8473e2905f8402f85ee2053cb1c35f /tests | |
parent | d5faea1644d2360f5c776cb833f2123e1c082f35 (diff) |
LRWD: masking bugreport triggers
If watchdog experiences another network connection failure after
restarting wifi, then assume that the restart did not fix the problem
and therefore don't trigger a bugreport when wifi finally connects.
Bug: 77655949
Test: compile, unit tests
Manual test:
Flash build
create a soft AP on another device
Connect to that soft AP
Change the password of the soft AP
Wait for watchdog to trigger
Connect to Google Guest
Do "adb shell dumpsys wifi" and verify the following:
1. mWifiLogProto.numLastResortWatchdogTriggers=1
2. mWifiLogProto.numLastResortWatchdogSuccesses=0
Change-Id: I6756f9ee24329cb33cd48f19a3be374f9fa529b7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java | 116 |
1 files changed, 116 insertions, 0 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..0647892ab 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -1860,4 +1860,120 @@ public class WifiLastResortWatchdogTest { ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); verify(mWifiMetrics, times(1)).incrementWatchdogTotalConnectionFailureCountAfterTrigger(); } + + /** + * 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 testWatchdogAssumesSuccessOnlyIfFirstConnectionAfterRestartSucceeds() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] frequencies = {2437}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {-60}; + boolean[] isEphemeral = {false}; + boolean[] hasEverConnected = {true}; + List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates(ssids, + bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); + mLastResortWatchdog.updateAvailableNetworks(candidates); + + // Ensure new networks have zero'ed failure counts + for (int i = 0; i < ssids.length; i++) { + assertFailureCountEquals(bssids[i], 0, 0, 0); + } + + //Increment failure counts + 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(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 not called again + mLooper.dispatchAll(); + verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, never()).incrementNumLastResortWatchdogSuccesses(); + + // Simulate wifi disconnecting + mLastResortWatchdog.connectedStateTransition(false, "\"test1\""); + + // 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\""); + // Verify takeBugReport is not called again + mLooper.dispatchAll(); + verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); + } + + /** + * 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 testWatchdogVerifiesAtLeastOneNetworkIsConnectedBeforeTriggeringBugreport() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] frequencies = {2437}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {-60}; + boolean[] isEphemeral = {false}; + boolean[] hasEverConnected = {true}; + List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates(ssids, + bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); + mLastResortWatchdog.updateAvailableNetworks(candidates); + + // Ensure new networks have zero'ed failure counts + for (int i = 0; i < ssids.length; i++) { + assertFailureCountEquals(bssids[i], 0, 0, 0); + } + + //Increment failure counts + 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(1)).incrementNumLastResortWatchdogTriggers(); + + // Simulate user changing the configuration + when(candidates.get(0).second.getNetworkSelectionStatus().getHasEverConnected()) + .thenReturn(false); + + mLastResortWatchdog.connectedStateTransition(true, "\"test1\""); + // Verify takeBugReport is not called again + mLooper.dispatchAll(); + verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString()); + verify(mWifiMetrics, never()).incrementNumLastResortWatchdogSuccesses(); + } } |