diff options
author | xshu <xshu@google.com> | 2019-05-21 17:34:56 -0700 |
---|---|---|
committer | xshu <xshu@google.com> | 2019-05-23 13:54:57 -0700 |
commit | c6cb88c37c22daeeac819726cc91b6c452791a46 (patch) | |
tree | 10a3d34af6455d1e9f2af9b6e103273509406a98 /tests | |
parent | ab6b4546f9ba6eff785dd539890a0d4bdfcab4b1 (diff) |
Trigger bugreport for abnormally long connections
Bug: 132648941
Test: Unit tests
Test: mannually tested with a smaller threshold to verify bugreport is
triggering properly.
Change-Id: I2f5f9c9c08874f6f356a081b0a2575dd3851c241
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java | 39 |
1 files changed, 39 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 9ae382640..dab283539 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -24,6 +24,7 @@ import static org.mockito.MockitoAnnotations.*; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiSsid; +import android.os.Handler; import android.os.test.TestLooper; import android.util.Pair; @@ -72,6 +73,7 @@ public class WifiLastResortWatchdogTest { mLastResortWatchdog.setBugReportProbability(1); when(mClientModeImpl.getWifiInfo()).thenReturn(mWifiInfo); when(mWifiInfo.getSSID()).thenReturn(TEST_NETWORK_SSID); + when(mWifiInjector.getClientModeImplHandler()).thenReturn(mLastResortWatchdog.getHandler()); } private List<Pair<ScanDetail, WifiConfiguration>> createFilteredQnsCandidates(String[] ssids, @@ -2152,4 +2154,41 @@ public class WifiLastResortWatchdogTest { verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); } + /** + * Verifies that when a connection takes too long (time difference between + * StaEvent.TYPE_CMD_START_CONNECT and StaEvent.TYPE_NETWORK_CONNECTION_EVENT) a bugreport is + * taken. + */ + @Test + public void testAbnormalConnectionTimeTriggersBugreport() throws Exception { + // first verifies that bugreports are not taken when connection takes less than + // WifiLastResortWatchdog.ABNORMAL_SUCCESSFUL_CONNECTION_DURATION_MS + when(mClock.getElapsedSinceBootMillis()).thenReturn(1L); + mLastResortWatchdog.noteStartConnectTime(); + when(mClock.getElapsedSinceBootMillis()).thenReturn( + (long) WifiLastResortWatchdog.ABNORMAL_SUCCESSFUL_CONNECTION_DURATION_MS); + Handler handler = mLastResortWatchdog.getHandler(); + handler.sendMessage( + handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null)); + mLooper.dispatchAll(); + verify(mClientModeImpl, never()).takeBugReport(anyString(), anyString()); + + // Now verify that bugreport is taken + mLastResortWatchdog.noteStartConnectTime(); + when(mClock.getElapsedSinceBootMillis()).thenReturn( + (long) 2 * WifiLastResortWatchdog.ABNORMAL_SUCCESSFUL_CONNECTION_DURATION_MS + 1); + handler.sendMessage( + handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null)); + mLooper.dispatchAll(); + verify(mClientModeImpl).takeBugReport(anyString(), anyString()); + + // Verify additional connections (without more TYPE_CMD_START_CONNECT) don't trigger more + // bugreports. + when(mClock.getElapsedSinceBootMillis()).thenReturn( + (long) 4 * WifiLastResortWatchdog.ABNORMAL_SUCCESSFUL_CONNECTION_DURATION_MS); + handler.sendMessage( + handler.obtainMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null)); + mLooper.dispatchAll(); + verify(mClientModeImpl).takeBugReport(anyString(), anyString()); + } } |