diff options
author | David Su <dysu@google.com> | 2019-05-15 16:19:27 -0700 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-05-21 16:07:42 -0700 |
commit | 53648549ec4cc4a6aae5a70370b7e92ff5ebcb69 (patch) | |
tree | 87a0c7ab3d475861d1b8614281851b215d1c73a9 /tests | |
parent | 353e8733c58131f4f78e63f2adb6a4f6379a1d59 (diff) |
Adjust link probe manager parameters using experiment results
Shorten minimum delay between link probes to 6000ms to trigger
link probes more frequently using the results of the experiment.
Bug: 131091030
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I11f387b16cf56dd1a6dd0520c348ea4dc58b6c83
Diffstat (limited to 'tests')
4 files changed, 272 insertions, 55 deletions
diff --git a/tests/wifitests/Android.mk b/tests/wifitests/Android.mk index 9b44ecedf..8e48f0c7f 100644 --- a/tests/wifitests/Android.mk +++ b/tests/wifitests/Android.mk @@ -59,6 +59,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ frameworks-base-testutils \ services \ wifi-service \ + truth-prebuilt \ LOCAL_JAVA_LIBRARIES := \ android.test.runner \ diff --git a/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java index 35f63149c..6884c03c0 100644 --- a/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -54,7 +55,6 @@ public class LinkProbeManagerTest { private static final String TEST_IFACE_NAME = "testIfaceName"; private static final String TEST_BSSID = "6c:f3:7f:ae:8c:f3"; private static final int TEST_ELAPSED_TIME_MS = 100; - private static final long TEST_TIMESTAMP_MS = 1547837434690L; private LinkProbeManager mLinkProbeManager; @@ -107,8 +107,6 @@ public class LinkProbeManagerTest { */ @Test public void testLinkProbeTriggeredAndAcked() throws Exception { - mLinkProbeManager.resetOnNewConnection(); - // initialize tx success counter mWifiInfo.txSuccess = 50; mTimeMs += 3000; @@ -121,16 +119,15 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 50; // below RSSI threshold - int rssi = LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD - 5; + int rssi = LinkProbeManager.RSSI_THRESHOLD - 5; mWifiInfo.setRssi(rssi); // above link speed threshold - int linkSpeed = LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS + 10; + int linkSpeed = LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10; mWifiInfo.setLinkSpeed(linkSpeed); - // more than LINK_PROBE_INTERVAL_MS passed - long timeDelta = LinkProbeManager.LINK_PROBE_INTERVAL_MS + 1000; + // more than DELAY_AFTER_TX_SUCCESS_MS passed + long timeDelta = LinkProbeManager.DELAY_AFTER_TX_SUCCESS_MS + 20000; mTimeMs += timeDelta; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); - when(mClock.getWallClockMillis()).thenReturn(TEST_TIMESTAMP_MS); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); ArgumentCaptor<WifiNative.SendMgmtFrameCallback> callbackCaptor = ArgumentCaptor.forClass(WifiNative.SendMgmtFrameCallback.class); @@ -139,13 +136,13 @@ public class LinkProbeManagerTest { ArgumentCaptor<String> experimentIdCaptor = ArgumentCaptor.forClass(String.class); verify(mWifiMetrics, atLeastOnce()).incrementLinkProbeExperimentProbeCount( experimentIdCaptor.capture()); - int len = LinkProbeManager.EXPERIMENT_DELAYS_MS.length; - int numExperimentIds = len * len * len; + int numExperimentIds = LinkProbeManager.EXPERIMENT_DELAYS_MS.length + * LinkProbeManager.EXPERIMENT_RSSIS.length + * LinkProbeManager.EXPERIMENT_LINK_SPEEDS.length; assertEquals(numExperimentIds, new HashSet<>(experimentIdCaptor.getAllValues()).size()); callbackCaptor.getValue().onAck(TEST_ELAPSED_TIME_MS); - verify(mWifiMetrics).logLinkProbeSuccess(TEST_TIMESTAMP_MS, timeDelta, rssi, linkSpeed, - TEST_ELAPSED_TIME_MS); + verify(mWifiMetrics).logLinkProbeSuccess(timeDelta, rssi, linkSpeed, TEST_ELAPSED_TIME_MS); } /** @@ -154,8 +151,6 @@ public class LinkProbeManagerTest { */ @Test public void testLinkProbeTriggeredAndFailed() throws Exception { - mLinkProbeManager.resetOnNewConnection(); - // initialize tx success counter mWifiInfo.txSuccess = 50; mTimeMs += 3000; @@ -167,16 +162,15 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 50; // above RSSI threshold - int rssi = LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD + 5; + int rssi = LinkProbeManager.RSSI_THRESHOLD + 5; mWifiInfo.setRssi(rssi); // below link speed threshold - int linkSpeed = LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS - 2; + int linkSpeed = LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS - 2; mWifiInfo.setLinkSpeed(linkSpeed); - // more than LINK_PROBE_INTERVAL_MS passed - long timeDelta = LinkProbeManager.LINK_PROBE_INTERVAL_MS + 1000; + // more than DELAY_BETWEEN_PROBES_MS passed + long timeDelta = LinkProbeManager.DELAY_BETWEEN_PROBES_MS + 1000; mTimeMs += timeDelta; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); - when(mClock.getWallClockMillis()).thenReturn(TEST_TIMESTAMP_MS); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); ArgumentCaptor<WifiNative.SendMgmtFrameCallback> callbackCaptor = ArgumentCaptor.forClass(WifiNative.SendMgmtFrameCallback.class); @@ -184,12 +178,12 @@ public class LinkProbeManagerTest { anyInt()); callbackCaptor.getValue().onFailure(WifiNative.SEND_MGMT_FRAME_ERROR_NO_ACK); - verify(mWifiMetrics).logLinkProbeFailure(TEST_TIMESTAMP_MS, timeDelta, rssi, linkSpeed, + verify(mWifiMetrics).logLinkProbeFailure(timeDelta, rssi, linkSpeed, WifiNative.SEND_MGMT_FRAME_ERROR_NO_ACK); } /** - * Tests that link probing is not triggered more than once every LINK_PROBE_INTERVAL_MS + * Tests that link probing is not triggered more than once every DELAY_BETWEEN_PROBES_MS */ @Test public void testLinkProbeNotTriggeredTooFrequently() throws Exception { @@ -198,11 +192,11 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 50; // below RSSI threshold - mWifiInfo.setRssi(LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD - 5); + mWifiInfo.setRssi(LinkProbeManager.RSSI_THRESHOLD - 5); // above link speed threshold - mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS + 10); - // *** but less than LINK_PROBE_INTERVAL_MS has passed since last probe *** - mTimeMs += LinkProbeManager.LINK_PROBE_INTERVAL_MS - 1000; + mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10); + // *** but less than DELAY_BETWEEN_PROBES_MS has passed since last probe *** + mTimeMs += LinkProbeManager.DELAY_BETWEEN_PROBES_MS - 1000; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); // should not probe @@ -211,12 +205,10 @@ public class LinkProbeManagerTest { /** * Tests that link probing is not triggered when Tx has succeeded within the last - * LINK_PROBE_INTERVAL_MS. + * DELAY_AFTER_TX_SUCCESS_MS. */ @Test public void testLinkProbeNotTriggeredWhenTxSucceeded() throws Exception { - mLinkProbeManager.resetOnNewConnection(); - // initialize tx success counter mWifiInfo.txSuccess = 50; mTimeMs += 3000; @@ -236,17 +228,67 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 55; // below RSSI threshold - mWifiInfo.setRssi(LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD - 5); + mWifiInfo.setRssi(LinkProbeManager.RSSI_THRESHOLD - 5); // above link speed threshold - mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS + 10); - // *** but less than LINK_PROBE_INTERVAL_MS has passed since last tx success *** - mTimeMs += LinkProbeManager.LINK_PROBE_INTERVAL_MS - 1000; + mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10); + // *** but less than DELAY_AFTER_TX_SUCCESS_MS has passed since last tx success *** + mTimeMs += LinkProbeManager.DELAY_AFTER_TX_SUCCESS_MS - 1000; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); } /** + * Tests that link probing is not triggered when screen was turned on within the last + * {@link LinkProbeManager#SCREEN_ON_DELAY_MS}. + */ + @Test + public void testLinkProbeNotTriggeredWhenScreenJustTurnedOn() throws Exception { + mTimeMs += 30 * 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.resetOnScreenTurnedOn(); + // should not probe yet + verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); + + // tx success counter did not change since initialization + mWifiInfo.txSuccess = 0; + // below RSSI threshold + mWifiInfo.setRssi(LinkProbeManager.RSSI_THRESHOLD - 5); + // above link speed threshold + mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10); + // *** but less than SCREEN_ON_DELAY_MS has passed since last screen on *** + mTimeMs += LinkProbeManager.SCREEN_ON_DELAY_MS - 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); + } + + /** + * Tests that link probing is triggered when screen was turned on more than + * {@link LinkProbeManager#SCREEN_ON_DELAY_MS} ago. + */ + @Test + public void testLinkProbeTriggeredAfterScreenTurnedOn() throws Exception { + mTimeMs += 30 * 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.resetOnScreenTurnedOn(); + // should not probe yet + verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); + + // tx success counter did not change since initialization + mWifiInfo.txSuccess = 0; + // below RSSI threshold + mWifiInfo.setRssi(LinkProbeManager.RSSI_THRESHOLD - 5); + // above link speed threshold + mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10); + // *** more than SCREEN_ON_DELAY_MS has passed since last screen on *** + mTimeMs += LinkProbeManager.SCREEN_ON_DELAY_MS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative).probeLink(eq(TEST_IFACE_NAME), any(), any(), anyInt()); + } + + /** * Tests when link probing feature flag is disabled, no probes should run. */ @Test @@ -255,8 +297,6 @@ public class LinkProbeManagerTest { eq(Settings.Global.WIFI_LINK_PROBING_ENABLED), anyInt())).thenReturn(0); mContentObserver.onChange(false); - mLinkProbeManager.resetOnNewConnection(); - // initialize tx success counter mWifiInfo.txSuccess = 50; mTimeMs += 3000; @@ -268,16 +308,15 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 50; // below RSSI threshold - int rssi = LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD - 5; + int rssi = LinkProbeManager.RSSI_THRESHOLD - 5; mWifiInfo.setRssi(rssi); // above link speed threshold - int linkSpeed = LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS + 10; + int linkSpeed = LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10; mWifiInfo.setLinkSpeed(linkSpeed); - // more than LINK_PROBE_INTERVAL_MS passed - long timeDelta = LinkProbeManager.LINK_PROBE_INTERVAL_MS + 1000; + // more than DELAY_AFTER_TX_SUCCESS_MS passed + long timeDelta = LinkProbeManager.DELAY_AFTER_TX_SUCCESS_MS + 1000; mTimeMs += timeDelta; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); - when(mClock.getWallClockMillis()).thenReturn(TEST_TIMESTAMP_MS); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); verify(mWifiNative, never()).probeLink(any() , any(), any(), anyInt()); } @@ -290,8 +329,6 @@ public class LinkProbeManagerTest { mResources.setBoolean(R.bool.config_wifi_link_probing_supported, false); initLinkProbeManager(); - mLinkProbeManager.resetOnNewConnection(); - // initialize tx success counter mWifiInfo.txSuccess = 50; mTimeMs += 3000; @@ -303,17 +340,73 @@ public class LinkProbeManagerTest { // tx success counter did not change since last update mWifiInfo.txSuccess = 50; // below RSSI threshold - int rssi = LinkProbeManager.LINK_PROBE_RSSI_THRESHOLD - 5; + int rssi = LinkProbeManager.RSSI_THRESHOLD - 5; mWifiInfo.setRssi(rssi); // above link speed threshold - int linkSpeed = LinkProbeManager.LINK_PROBE_LINK_SPEED_THRESHOLD_MBPS + 10; + int linkSpeed = LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10; mWifiInfo.setLinkSpeed(linkSpeed); - // more than LINK_PROBE_INTERVAL_MS passed - long timeDelta = LinkProbeManager.LINK_PROBE_INTERVAL_MS + 1000; + // more than DELAY_AFTER_TX_SUCCESS_MS passed + long timeDelta = LinkProbeManager.DELAY_AFTER_TX_SUCCESS_MS + 1000; mTimeMs += timeDelta; when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); - when(mClock.getWallClockMillis()).thenReturn(TEST_TIMESTAMP_MS); mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); verify(mWifiNative, never()).probeLink(any() , any(), any(), anyInt()); } + + /** + * Tests exhausting the daily link probe quota and verify that no more link probes are made + * after the limit is reached. Tests that the quota is reset upon entering a new day. + */ + @Test + public void testLinkProbeQuotaExceeded() { + mTimeMs += 30 * 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + // should not probe yet + verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); + + // tx success counter did not change since initialization + mWifiInfo.txSuccess = 0; + // below RSSI threshold + mWifiInfo.setRssi(LinkProbeManager.RSSI_THRESHOLD - 5); + // above link speed threshold + mWifiInfo.setLinkSpeed(LinkProbeManager.LINK_SPEED_THRESHOLD_MBPS + 10); + + // exhaust quota + for (int i = 1; i <= LinkProbeManager.MAX_PROBE_COUNT_IN_PERIOD; i++) { + mTimeMs += LinkProbeManager.DELAY_BETWEEN_PROBES_MS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative, times(i)) + .probeLink(eq(TEST_IFACE_NAME), any(), any(), anyInt()); + } + // verify no more quota + for (int i = 0; i < 10; i++) { + mTimeMs += LinkProbeManager.DELAY_BETWEEN_PROBES_MS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative, times((int) LinkProbeManager.MAX_PROBE_COUNT_IN_PERIOD)) + .probeLink(eq(TEST_IFACE_NAME), any(), any(), anyInt()); + } + + // start new period + mTimeMs += LinkProbeManager.PERIOD_MILLIS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + + // exhaust quota again + for (int i = 1; i <= LinkProbeManager.MAX_PROBE_COUNT_IN_PERIOD; i++) { + mTimeMs += LinkProbeManager.DELAY_BETWEEN_PROBES_MS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative, times((int) (LinkProbeManager.MAX_PROBE_COUNT_IN_PERIOD + i))) + .probeLink(eq(TEST_IFACE_NAME), any(), any(), anyInt()); + } + // verify no more quota again + for (int i = 0; i < 10; i++) { + mTimeMs += LinkProbeManager.DELAY_BETWEEN_PROBES_MS + 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(mTimeMs); + mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); + verify(mWifiNative, times((int) (2 * LinkProbeManager.MAX_PROBE_COUNT_IN_PERIOD))) + .probeLink(eq(TEST_IFACE_NAME), any(), any(), anyInt()); + } + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 88ff48838..e45906a85 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -33,6 +33,7 @@ import static com.android.server.wifi.WifiMetricsTestUtil.buildInt32Count; import static com.android.server.wifi.WifiMetricsTestUtil.buildLinkProbeFailureReasonCount; import static com.android.server.wifi.WifiMetricsTestUtil.buildLinkProbeFailureStaEvent; import static com.android.server.wifi.WifiMetricsTestUtil.buildLinkProbeSuccessStaEvent; +import static com.android.server.wifi.nano.WifiMetricsProto.StaEvent.TYPE_LINK_PROBE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -115,6 +116,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; import java.util.HashMap; import java.util.List; @@ -1953,6 +1955,29 @@ public class WifiMetricsTest { } /** + * Tests that link probe StaEvents do not exceed + * {@link WifiMetrics#MAX_LINK_PROBE_STA_EVENTS}. + */ + @Test + public void testLinkProbeStaEventBounding() throws Exception { + for (int i = 0; i < WifiMetrics.MAX_LINK_PROBE_STA_EVENTS; i++) { + mWifiMetrics.logLinkProbeSuccess(0, 0, 0, 0); + mWifiMetrics.logLinkProbeFailure(0, 0, 0, 0); + } + for (int i = 0; i < 10; i++) { + mWifiMetrics.logStaEvent(StaEvent.TYPE_CMD_START_CONNECT); + } + + dumpProtoAndDeserialize(); + + long numLinkProbeStaEvents = Arrays.stream(mDecodedProto.staEventList) + .filter(event -> event.type == TYPE_LINK_PROBE) + .count(); + assertEquals(WifiMetrics.MAX_LINK_PROBE_STA_EVENTS, numLinkProbeStaEvents); + assertEquals(WifiMetrics.MAX_LINK_PROBE_STA_EVENTS + 10, mDecodedProto.staEventList.length); + } + + /** * Ensure WifiMetrics doesn't cause a null pointer exception when called with null args */ @Test @@ -2803,12 +2828,11 @@ public class WifiMetricsTest { WifiLinkLayerStats stats2 = nextRandomStats(stats1); mWifiMetrics.incrementWifiScoreCount(60); mWifiMetrics.incrementWifiUsabilityScoreCount(2, 55, 15); - mWifiMetrics.logLinkProbeSuccess(nextRandInt(), nextRandInt(), nextRandInt(), - nextRandInt(), 12); + mWifiMetrics.logLinkProbeSuccess(nextRandInt(), nextRandInt(), nextRandInt(), 12); mWifiMetrics.updateWifiUsabilityStatsEntries(info, stats1); mWifiMetrics.incrementWifiScoreCount(58); mWifiMetrics.incrementWifiUsabilityScoreCount(3, 56, 15); - mWifiMetrics.logLinkProbeFailure(nextRandInt(), nextRandInt(), nextRandInt(), + mWifiMetrics.logLinkProbeFailure(nextRandInt(), nextRandInt(), nextRandInt(), nextRandInt()); mWifiMetrics.enterDeviceMobilityState(DEVICE_MOBILITY_STATE_HIGH_MVMT); @@ -3375,14 +3399,14 @@ public class WifiMetricsTest { */ @Test public void testLogLinkProbeMetrics() throws Exception { - mWifiMetrics.logLinkProbeSuccess(1000, 10000, -75, 50, 5); - mWifiMetrics.logLinkProbeFailure(2000, 30000, -80, 10, + mWifiMetrics.logLinkProbeSuccess(10000, -75, 50, 5); + mWifiMetrics.logLinkProbeFailure(30000, -80, 10, WifiNative.SEND_MGMT_FRAME_ERROR_NO_ACK); - mWifiMetrics.logLinkProbeSuccess(3000, 3000, -71, 160, 12); - mWifiMetrics.logLinkProbeFailure(4000, 40000, -80, 6, + mWifiMetrics.logLinkProbeSuccess(3000, -71, 160, 12); + mWifiMetrics.logLinkProbeFailure(40000, -80, 6, WifiNative.SEND_MGMT_FRAME_ERROR_NO_ACK); - mWifiMetrics.logLinkProbeSuccess(5000, 5000, -73, 160, 10); - mWifiMetrics.logLinkProbeFailure(6000, 2000, -78, 6, + mWifiMetrics.logLinkProbeSuccess(5000, -73, 160, 10); + mWifiMetrics.logLinkProbeFailure(2000, -78, 6, WifiNative.SEND_MGMT_FRAME_ERROR_TIMEOUT); dumpProtoAndDeserialize(); diff --git a/tests/wifitests/src/com/android/server/wifi/util/TimedQuotaManagerTest.java b/tests/wifitests/src/com/android/server/wifi/util/TimedQuotaManagerTest.java new file mode 100644 index 000000000..3dcad7cd7 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/util/TimedQuotaManagerTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.util; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import androidx.test.filters.SmallTest; + +import com.android.server.wifi.Clock; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.time.Duration; + +/** + * Unit tests for {@link TimedQuotaManager}. + */ +@SmallTest +public class TimedQuotaManagerTest { + + private static final long DAY_MILLIS = Duration.ofDays(1).toMillis(); + + @Mock private Clock mClock; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(mClock.getElapsedSinceBootMillis()).thenReturn(100000000L); + } + + /** + * Tests that {@link TimedQuotaManager#requestQuota()} returns true before the quota is exceeded + * and returns false after it is exceeded. Tests that upon entering a new time period, the quota + * is reset correctly. + */ + @Test + public void exhaustQuota_newDay_exhaustQuotaAgain() { + TimedQuotaManager qm = new TimedQuotaManager(mClock, 10, DAY_MILLIS); + + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isTrue(); + } + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isFalse(); + } + + long now = mClock.getElapsedSinceBootMillis(); + when(mClock.getElapsedSinceBootMillis()).thenReturn(now + DAY_MILLIS + 1000); + + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isTrue(); + } + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isFalse(); + } + } + + /** + * Tests that {@link TimedQuotaManager#requestQuota()} returns true before the quota is exceeded + * and returns false after it is exceeded. Tests when advancing time within the same time + * period, the quota is still enforced. + */ + @Test + public void exhaustQuota_sameDay_stillExhausted() { + TimedQuotaManager qm = new TimedQuotaManager(mClock, 10, DAY_MILLIS); + + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isTrue(); + } + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isFalse(); + } + + long now = mClock.getElapsedSinceBootMillis(); + when(mClock.getElapsedSinceBootMillis()).thenReturn(now + DAY_MILLIS - 1000); + for (int i = 0; i < 10; i++) { + assertThat(qm.requestQuota()).isFalse(); + } + } +} |