diff options
author | David Su <dysu@google.com> | 2019-04-21 13:08:46 -0700 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-04-23 14:16:52 -0700 |
commit | 7742c758bcea64b00d0aac2a25140eab9c89d8e5 (patch) | |
tree | a92df857d5389a7b5c76d128db7137262b30c8e0 /tests | |
parent | be70cc2e5eb921f4c49ad2ca118211335df8a5dd (diff) |
Link Probing: Experiments to vary trigger criteria
Run experiments by varying the delay between probes,
the delay after screen on, and the delay after last
Tx success. Count the number of probes that *would*
be triggered by each experiment, and upload to metrics.
Bug: 131091030
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: Id795b8acb86c4e64672e3ca5a9147647d93a1115
Diffstat (limited to 'tests')
4 files changed, 88 insertions, 7 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 452dfa399..b96fc3a90 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -3270,7 +3270,8 @@ public class ClientModeImplTest { connect(); // reset() should be called when RSSI polling is enabled and entering L2ConnectedState - verify(mLinkProbeManager).reset(); + verify(mLinkProbeManager).resetOnNewConnection(); // called first time here + verify(mLinkProbeManager, never()).resetOnScreenTurnedOn(); // not called verify(mLinkProbeManager).updateConnectionStats(any(), any()); mCmi.enableRssiPolling(false); @@ -3279,7 +3280,8 @@ public class ClientModeImplTest { // becomes enabled mCmi.enableRssiPolling(true); mLooper.dispatchAll(); - verify(mLinkProbeManager, times(2)).reset(); + verify(mLinkProbeManager, times(1)).resetOnNewConnection(); // verify not called again + verify(mLinkProbeManager).resetOnScreenTurnedOn(); // verify called here } /** diff --git a/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java index 614ec7e57..35f63149c 100644 --- a/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/LinkProbeManagerTest.java @@ -16,9 +16,12 @@ package com.android.server.wifi; +import static junit.framework.Assert.assertEquals; + import static org.mockito.ArgumentMatchers.eq; 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.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -40,6 +43,8 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.HashSet; + /** * Unit tests for LinkProbeManager */ @@ -102,7 +107,7 @@ public class LinkProbeManagerTest { */ @Test public void testLinkProbeTriggeredAndAcked() throws Exception { - mLinkProbeManager.reset(); + mLinkProbeManager.resetOnNewConnection(); // initialize tx success counter mWifiInfo.txSuccess = 50; @@ -111,6 +116,7 @@ public class LinkProbeManagerTest { mLinkProbeManager.updateConnectionStats(mWifiInfo, TEST_IFACE_NAME); // should not probe yet verify(mWifiNative, never()).probeLink(any(), any(), any(), anyInt()); + verify(mWifiMetrics, never()).incrementLinkProbeExperimentProbeCount(any()); // tx success counter did not change since last update mWifiInfo.txSuccess = 50; @@ -130,6 +136,12 @@ public class LinkProbeManagerTest { ArgumentCaptor.forClass(WifiNative.SendMgmtFrameCallback.class); verify(mWifiNative).probeLink(eq(TEST_IFACE_NAME), any(), callbackCaptor.capture(), anyInt()); + 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; + assertEquals(numExperimentIds, new HashSet<>(experimentIdCaptor.getAllValues()).size()); callbackCaptor.getValue().onAck(TEST_ELAPSED_TIME_MS); verify(mWifiMetrics).logLinkProbeSuccess(TEST_TIMESTAMP_MS, timeDelta, rssi, linkSpeed, @@ -142,7 +154,7 @@ public class LinkProbeManagerTest { */ @Test public void testLinkProbeTriggeredAndFailed() throws Exception { - mLinkProbeManager.reset(); + mLinkProbeManager.resetOnNewConnection(); // initialize tx success counter mWifiInfo.txSuccess = 50; @@ -203,7 +215,7 @@ public class LinkProbeManagerTest { */ @Test public void testLinkProbeNotTriggeredWhenTxSucceeded() throws Exception { - mLinkProbeManager.reset(); + mLinkProbeManager.resetOnNewConnection(); // initialize tx success counter mWifiInfo.txSuccess = 50; @@ -243,7 +255,7 @@ public class LinkProbeManagerTest { eq(Settings.Global.WIFI_LINK_PROBING_ENABLED), anyInt())).thenReturn(0); mContentObserver.onChange(false); - mLinkProbeManager.reset(); + mLinkProbeManager.resetOnNewConnection(); // initialize tx success counter mWifiInfo.txSuccess = 50; @@ -278,7 +290,7 @@ public class LinkProbeManagerTest { mResources.setBoolean(R.bool.config_wifi_link_probing_supported, false); initLinkProbeManager(); - mLinkProbeManager.reset(); + mLinkProbeManager.resetOnNewConnection(); // initialize tx success counter mWifiInfo.txSuccess = 50; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 9b9f032ce..a55f1d29c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -21,11 +21,13 @@ import static android.net.wifi.WifiManager.DEVICE_MOBILITY_STATE_STATIONARY; import static android.net.wifi.WifiManager.DEVICE_MOBILITY_STATE_UNKNOWN; import static com.android.server.wifi.WifiMetricsTestUtil.assertDeviceMobilityStatePnoScanStatsEqual; +import static com.android.server.wifi.WifiMetricsTestUtil.assertExperimentProbeCountsEqual; import static com.android.server.wifi.WifiMetricsTestUtil.assertHistogramBucketsEqual; import static com.android.server.wifi.WifiMetricsTestUtil.assertKeyCountsEqual; import static com.android.server.wifi.WifiMetricsTestUtil.assertLinkProbeFailureReasonCountsEqual; import static com.android.server.wifi.WifiMetricsTestUtil.assertLinkProbeStaEventsEqual; import static com.android.server.wifi.WifiMetricsTestUtil.buildDeviceMobilityStatePnoScanStats; +import static com.android.server.wifi.WifiMetricsTestUtil.buildExperimentProbeCounts; import static com.android.server.wifi.WifiMetricsTestUtil.buildHistogramBucketInt32; import static com.android.server.wifi.WifiMetricsTestUtil.buildInt32Count; import static com.android.server.wifi.WifiMetricsTestUtil.buildLinkProbeFailureReasonCount; @@ -85,6 +87,7 @@ import com.android.server.wifi.nano.WifiMetricsProto.DeviceMobilityStatePnoScanS import com.android.server.wifi.nano.WifiMetricsProto.HistogramBucketInt32; import com.android.server.wifi.nano.WifiMetricsProto.Int32Count; import com.android.server.wifi.nano.WifiMetricsProto.LinkProbeStats; +import com.android.server.wifi.nano.WifiMetricsProto.LinkProbeStats.ExperimentProbeCounts; import com.android.server.wifi.nano.WifiMetricsProto.LinkProbeStats.LinkProbeFailureReasonCount; import com.android.server.wifi.nano.WifiMetricsProto.NetworkSelectionExperimentDecisions; import com.android.server.wifi.nano.WifiMetricsProto.PasspointProfileTypeCount; @@ -3467,6 +3470,32 @@ public class WifiMetricsTest { } /** + * Tests counting the number of link probes triggered per day for each experiment. + */ + @Test + public void testIncrementLinkProbeExperimentProbeCount() throws Exception { + String experimentId1 = "screenOnDelay=6000,noTxDelay=3000,delayBetweenProbes=9000," + + "rssiThreshold=-70,linkSpeedThreshold=15,"; + mWifiMetrics.incrementLinkProbeExperimentProbeCount(experimentId1); + + String experimentId2 = "screenOnDelay=9000,noTxDelay=12000,delayBetweenProbes=15000," + + "rssiThreshold=-72,linkSpeedThreshold=20,"; + mWifiMetrics.incrementLinkProbeExperimentProbeCount(experimentId2); + mWifiMetrics.incrementLinkProbeExperimentProbeCount(experimentId2); + + dumpProtoAndDeserialize(); + + ExperimentProbeCounts[] actual = mDecodedProto.linkProbeStats.experimentProbeCounts; + + ExperimentProbeCounts[] expected = { + buildExperimentProbeCounts(experimentId1, 1), + buildExperimentProbeCounts(experimentId2, 2) + }; + + assertExperimentProbeCountsEqual(expected, actual); + } + + /** * Tests logNetworkSelectionDecision() */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTestUtil.java index 407d20932..0e9f661ca 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTestUtil.java @@ -23,6 +23,7 @@ import android.net.wifi.WifiManager; import com.android.server.wifi.nano.WifiMetricsProto.DeviceMobilityStatePnoScanStats; import com.android.server.wifi.nano.WifiMetricsProto.HistogramBucketInt32; import com.android.server.wifi.nano.WifiMetricsProto.Int32Count; +import com.android.server.wifi.nano.WifiMetricsProto.LinkProbeStats.ExperimentProbeCounts; import com.android.server.wifi.nano.WifiMetricsProto.LinkProbeStats.LinkProbeFailureReasonCount; import com.android.server.wifi.nano.WifiMetricsProto.StaEvent; @@ -227,4 +228,41 @@ public class WifiMetricsTestUtil { } } } + + /** + * The constructor we wish ExperimentProbeCounts had. + */ + public static ExperimentProbeCounts buildExperimentProbeCounts( + String experimentId, int probeCount) { + ExperimentProbeCounts counts = new ExperimentProbeCounts(); + counts.experimentId = experimentId; + counts.probeCount = probeCount; + return counts; + } + + /** + * Asserts that the two arrays are equal (ignoring order), + * reporting any difference between them. + */ + public static void assertExperimentProbeCountsEqual( + ExperimentProbeCounts[] expected, ExperimentProbeCounts[] actual) { + + assertEquals("Number of ExperimentProbeCounts do not match!", + expected.length, actual.length); + + Arrays.sort(expected, Comparator.comparing(x -> x.experimentId)); + Arrays.sort(actual, Comparator.comparing(x -> x.experimentId)); + + for (int i = 0; i < expected.length; i++) { + ExperimentProbeCounts expectedCounts = expected[i]; + ExperimentProbeCounts actualCounts = actual[i]; + + assertEquals(String.format( + "ExperimentProbeCounts[%d].experimentId does not match!", i), + expectedCounts.experimentId, actualCounts.experimentId); + assertEquals(String.format( + "ExperimentProbeCounts[%d].probeCount does not match!", i), + expectedCounts.probeCount, actualCounts.probeCount); + } + } } |