From 9d57736a73dedbc6afc53dfc74802d0cbf56fb2e Mon Sep 17 00:00:00 2001 From: xshu Date: Fri, 14 Sep 2018 11:01:44 -0700 Subject: Metrics for wifi link layer stats usage Collect and upload data on usage of important link layer stats that will be used as baseline for wifi scanning. **Some changes were introduced in the process of resolving merge conflict. In particular, a test which had dependency in WifiDataStall, which is not in P, is removed. Bug: 77603419 Test: compile, unit tests Test: Do "adb shell dumpsys wifi | grep -A10 mWifiLinkLayerUsageStats.loggingDurationMs=" and verify the wifi link layer usage stats are being printed properly. Change-Id: I0135b29200f7e4faa41d6c808e9d78fb4fb50f3c Merged-In: I0135b29200f7e4faa41d6c808e9d78fb4fb50f3c (cherry picked from commit f5e766890949a9abc6079678b0d36b52d4b5c483) --- .../com/android/server/wifi/WifiMetricsTest.java | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 5646efc62..1e49bf2c0 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -67,6 +67,7 @@ import java.util.BitSet; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,6 +80,7 @@ public class WifiMetricsTest { WifiMetrics mWifiMetrics; WifiMetricsProto.WifiLog mDecodedProto; TestLooper mTestLooper; + Random mRandom = new Random(); @Mock Clock mClock; @Mock ScoringParams mScoringParams; @Mock WifiConfigManager mWcm; @@ -1977,4 +1979,89 @@ public class WifiMetricsTest { } return bitSet; } + + private int nextRandInt() { + return mRandom.nextInt(10000); + } + + private WifiLinkLayerStats nextRandomStats(WifiLinkLayerStats current) { + WifiLinkLayerStats out = new WifiLinkLayerStats(); + out.timeStampInMs = current.timeStampInMs + nextRandInt(); + out.on_time = current.on_time + nextRandInt(); + out.tx_time = current.tx_time + nextRandInt(); + out.rx_time = current.rx_time + nextRandInt(); + out.on_time_scan = current.on_time_scan + nextRandInt(); + return out; + } + + private void assertWifiLinkLayerUsageHasDiff(WifiLinkLayerStats oldStats, + WifiLinkLayerStats newStats) { + assertEquals(newStats.timeStampInMs - oldStats.timeStampInMs, + mDecodedProto.wifiLinkLayerUsageStats.loggingDurationMs); + assertEquals(newStats.on_time - oldStats.on_time, + mDecodedProto.wifiLinkLayerUsageStats.radioOnTimeMs); + assertEquals(newStats.tx_time - oldStats.tx_time, + mDecodedProto.wifiLinkLayerUsageStats.radioTxTimeMs); + assertEquals(newStats.rx_time - oldStats.rx_time, + mDecodedProto.wifiLinkLayerUsageStats.radioRxTimeMs); + assertEquals(newStats.on_time_scan - oldStats.on_time_scan, + mDecodedProto.wifiLinkLayerUsageStats.radioScanTimeMs); + } + + /** + * Verify that WifiMetrics is counting link layer usage correctly when given a series of + * valid input. + * @throws Exception + */ + @Test + public void testWifiLinkLayerUsageStats() throws Exception { + WifiLinkLayerStats stat1 = nextRandomStats(new WifiLinkLayerStats()); + WifiLinkLayerStats stat2 = nextRandomStats(stat1); + WifiLinkLayerStats stat3 = nextRandomStats(stat2); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat1); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat2); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat3); + dumpProtoAndDeserialize(); + + // After 2 increments, the counters should have difference between |stat1| and |stat3| + assertWifiLinkLayerUsageHasDiff(stat1, stat3); + } + + /** + * Verify that null input is handled and wifi link layer usage stats are not incremented. + * @throws Exception + */ + @Test + public void testWifiLinkLayerUsageStatsNullInput() throws Exception { + WifiLinkLayerStats stat1 = nextRandomStats(new WifiLinkLayerStats()); + WifiLinkLayerStats stat2 = null; + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat1); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat2); + dumpProtoAndDeserialize(); + + // Counter should be zero + assertWifiLinkLayerUsageHasDiff(stat1, stat1); + } + + /** + * Verify that when the new data appears to be bad link layer usage stats are not being + * incremented and the buffered WifiLinkLayerStats get cleared. + * @throws Exception + */ + @Test + public void testWifiLinkLayerUsageStatsChipReset() throws Exception { + WifiLinkLayerStats stat1 = nextRandomStats(new WifiLinkLayerStats()); + WifiLinkLayerStats stat2 = nextRandomStats(stat1); + stat2.on_time = stat1.on_time - 1; + WifiLinkLayerStats stat3 = nextRandomStats(stat2); + WifiLinkLayerStats stat4 = nextRandomStats(stat3); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat1); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat2); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat3); + mWifiMetrics.incrementWifiLinkLayerUsageStats(stat4); + dumpProtoAndDeserialize(); + + // Should only count the difference between |stat3| and |stat4| + assertWifiLinkLayerUsageHasDiff(stat3, stat4); + } } -- cgit v1.2.3