diff options
author | Kai Shi <kaishi@google.com> | 2019-11-13 20:40:01 -0800 |
---|---|---|
committer | Kai Shi <kaishi@google.com> | 2019-11-16 04:46:18 +0000 |
commit | 6ff1d98e75558a16574fbbbb6fe234d118678c9f (patch) | |
tree | 481fea196c9dc804e5f26bb1756100f60d744db4 /tests | |
parent | e0c471f05a40c5dc60873d8a9e7214d947877283 (diff) |
Wifi: add throughputPredictor and throughputScorer classes
They are used in WifiNetworkSelector for predict throughput and
calculate network selection score with Nss, Rssi, channelWidth,
wifiStandard and channelUtilization info collected from scan and
bluetoothConnected information from BluetoothAdaptor broadcast message.
Bug: 141770991
Test: Wifi unit test with frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: run manual test to make sure throughput and score are calculated
correctly with various APs with 2, 4 and 8 antennas in 20, 40 and 80MHz
modes with and without BT connected.
Change-Id: I1ae36460d2f719cce157d94f5b65039597878f49
Diffstat (limited to 'tests')
7 files changed, 340 insertions, 27 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/CandidateScorerTest.java b/tests/wifitests/src/com/android/server/wifi/CandidateScorerTest.java index 037fd14ab..368ee92cf 100644 --- a/tests/wifitests/src/com/android/server/wifi/CandidateScorerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/CandidateScorerTest.java @@ -73,6 +73,13 @@ public class CandidateScorerTest extends WifiBaseTest { new BubbleFunScorer(sp), sp}); + sp = new ScoringParams(); + ans.add(new Object[]{ + "Throughput Scorer", + ThroughputScorer.THROUGHPUT_SCORER_DEFAULT_EXPID, + new ThroughputScorer(sp), + sp}); + return ans; } @@ -167,7 +174,7 @@ public class CandidateScorerTest extends WifiBaseTest { @Test public void testPreferTheCurrentNetworkEvenIfRssiDifferenceIsSignificant() throws Exception { assertThat(evaluate(mCandidate1.setScanRssi(-74).setCurrentNetwork(true)), - greaterThan(evaluate(mCandidate2.setScanRssi(-65)))); + greaterThan(evaluate(mCandidate2.setScanRssi(-70)))); } /** @@ -181,4 +188,16 @@ public class CandidateScorerTest extends WifiBaseTest { greaterThan(evaluate(mCandidate2.setScanRssi(unbelievablyGoodRssi)))); } + /** + * Prefer high throughput network + */ + @Test + public void testPreferHighThroughputNetwork() throws Exception { + if (mExpectedExpId == ThroughputScorer.THROUGHPUT_SCORER_DEFAULT_EXPID) { + assertThat(evaluate(mCandidate1.setScanRssi(-74) + .setPredictedThroughputMbps(100)), + greaterThan(evaluate(mCandidate2.setScanRssi(-74) + .setPredictedThroughputMbps(50)))); + } + } } diff --git a/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java b/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java index 517d69aff..832daf30e 100644 --- a/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java +++ b/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java @@ -16,6 +16,7 @@ package com.android.server.wifi; +import android.net.MacAddress; import android.util.ArrayMap; import com.android.server.wifi.proto.WifiScoreCardProto; @@ -23,7 +24,8 @@ import com.android.server.wifi.proto.WifiScoreCardProto; import java.util.Map; public final class ConcreteCandidate implements WifiCandidates.Candidate { - private WifiCandidates.Key mKey; + private WifiCandidates.Key mKey = new WifiCandidates.Key(new ScanResultMatchInfo(), + MacAddress.fromString("14:59:c0:51:0e:1b"), 0); private ScanDetail mScanDetail; private int mNetworkConfigId = -1; private boolean mIsOpenNetwork; @@ -38,6 +40,8 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate { private double mLastSelectionWeight; private int mScanRssi = -127; private int mFrequency = -1; + private int mPredictedThroughputMbps = 0; + private final Map<WifiScoreCardProto.Event, WifiScoreCardProto.Signal> mEventStatisticsMap = new ArrayMap<>(); @@ -60,6 +64,7 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate { mLastSelectionWeight = candidate.getLastSelectionWeight(); mScanRssi = candidate.getScanRssi(); mFrequency = candidate.getFrequency(); + mPredictedThroughputMbps = candidate.getPredictedThroughputMbps(); for (WifiScoreCardProto.Event event : WifiScoreCardProto.Event.values()) { WifiScoreCardProto.Signal signal = candidate.getEventStatistics(event); if (signal != null) { @@ -218,6 +223,16 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate { return mFrequency; } + public ConcreteCandidate setPredictedThroughputMbps(int predictedThroughputMbps) { + mPredictedThroughputMbps = predictedThroughputMbps; + return this; + } + + @Override + public int getPredictedThroughputMbps() { + return mPredictedThroughputMbps; + } + public ConcreteCandidate setEventStatistics( WifiScoreCardProto.Event event, WifiScoreCardProto.Signal signal) { diff --git a/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java b/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java new file mode 100644 index 000000000..08119e59b --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java @@ -0,0 +1,235 @@ +/* + * 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; + +import static com.android.server.wifi.util.InformationElementUtil.BssLoad.INVALID; +import static com.android.server.wifi.util.InformationElementUtil.BssLoad.MAX_CHANNEL_UTILIZATION; +import static com.android.server.wifi.util.InformationElementUtil.BssLoad.MIN_CHANNEL_UTILIZATION; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.validateMockitoUsage; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.net.wifi.ScanResult; + +import androidx.test.filters.SmallTest; + +import com.android.wifi.R; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; + +/** + * Unit tests for {@link com.android.server.wifi.ThroughputPredictor}. + */ +@SmallTest +public class ThroughputPredictorTest extends WifiBaseTest { + @Mock private Context mContext; + // For simulating the resources, we use a Spy on a MockResource + // (which is really more of a stub than a mock, in spite if its name). + // This is so that we get errors on any calls that we have not explicitly set up. + @Spy + private MockResources mResource = new MockResources(); + ThroughputPredictor mThroughputPredictor; + + /** + * Sets up for unit test + */ + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + doReturn(false).when(mResource).getBoolean(R.bool.config_wifi_11ax_supported); + doReturn(false).when(mResource).getBoolean( + R.bool.config_wifi_contiguous_160mhz_supported); + doReturn(2).when(mResource).getInteger( + R.integer.config_wifi_max_num_spatial_stream_supported); + when(mContext.getResources()).thenReturn(mResource); + mThroughputPredictor = new ThroughputPredictor(mContext); + } + + /** Cleans up test. */ + @After + public void cleanup() { + validateMockitoUsage(); + } + + @Test + public void verifyVeryLowRssi() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, -200, 2412, 1, + 0, 0, false); + + assertEquals(0, predictedThroughputMbps); + } + + @Test + public void verifyMaxChannelUtilizationBssLoad() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, 0, 2412, 1, + MAX_CHANNEL_UTILIZATION, 0, false); + + assertEquals(0, predictedThroughputMbps); + } + + @Test + public void verifyMaxChannelUtilizationLinkLayerStats() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, 0, 5210, 1, + INVALID, MAX_CHANNEL_UTILIZATION, false); + + assertEquals(0, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationAc5g80Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_80MHZ, 0, 5180, 2, + MIN_CHANNEL_UTILIZATION, 50, false); + + assertEquals(866, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationAx5g160Mhz4ss() { + doReturn(true).when(mResource).getBoolean(R.bool.config_wifi_11ax_supported); + doReturn(true).when(mResource).getBoolean( + R.bool.config_wifi_contiguous_160mhz_supported); + doReturn(4).when(mResource).getInteger( + R.integer.config_wifi_max_num_spatial_stream_supported); + when(mContext.getResources()).thenReturn(mResource); + mThroughputPredictor = new ThroughputPredictor(mContext); + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AX, ScanResult.CHANNEL_WIDTH_160MHZ, 0, 5180, 4, + MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(4803, predictedThroughputMbps); + } + + @Test + public void verifyMidRssiMinChannelUtilizationAc5g80Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_80MHZ, -50, 5180, 2, + MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(866, predictedThroughputMbps); + } + + @Test + public void verifyLowRssiMinChannelUtilizationAc5g80Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_80MHZ, -80, 5180, 2, + MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(41, predictedThroughputMbps); + } + + @Test + public void verifyLowRssiDefaultChannelUtilizationAc5g80Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_80MHZ, -80, 5180, 2, + INVALID, INVALID, false); + + assertEquals(31, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationAc2g20Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, -20, 2437, 2, + MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(192, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationAc2g20Mhz2ssBluetoothConnected() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, -20, 2437, 2, + MIN_CHANNEL_UTILIZATION, INVALID, true); + + assertEquals(144, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationLegacy5g20Mhz() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_LEGACY, ScanResult.CHANNEL_WIDTH_20MHZ, -50, 5180, + 1, MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(54, predictedThroughputMbps); + } + + @Test + public void verifyLowRssiDefaultChannelUtilizationLegacy5g20Mhz() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_LEGACY, ScanResult.CHANNEL_WIDTH_20MHZ, -80, 5180, + 2, INVALID, INVALID, false); + + assertEquals(11, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiMinChannelUtilizationHt2g20Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11N, ScanResult.CHANNEL_WIDTH_20MHZ, -50, 2437, 2, + MIN_CHANNEL_UTILIZATION, INVALID, false); + + assertEquals(144, predictedThroughputMbps); + } + + @Test + public void verifyLowRssiDefaultChannelUtilizationHt2g20Mhz1ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11N, ScanResult.CHANNEL_WIDTH_20MHZ, -80, 2437, 1, + INVALID, INVALID, true); + + assertEquals(5, predictedThroughputMbps); + } + + @Test + public void verifyHighRssiHighChannelUtilizationAx2g20Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, -50, 2437, 2, + INVALID, 80, true); + + assertEquals(84, predictedThroughputMbps); + } + + @Test + public void verifyRssiBoundaryHighChannelUtilizationAc2g20Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_20MHZ, -69, 2437, 2, + INVALID, 80, true); + + assertEquals(46, predictedThroughputMbps); + } + + @Test + public void verifyRssiBoundaryHighChannelUtilizationAc5g40Mhz2ss() { + int predictedThroughputMbps = mThroughputPredictor.predictThroughput( + ScanResult.WIFI_STANDARD_11AC, ScanResult.CHANNEL_WIDTH_40MHZ, -66, 5180, 2, + INVALID, 80, false); + + assertEquals(103, predictedThroughputMbps); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java index 5c07edc27..65bedc476 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java @@ -59,6 +59,7 @@ public class WifiCandidatesTest extends WifiBaseTest { MockitoAnnotations.initMocks(this); mWifiCandidates = new WifiCandidates(mWifiScoreCard); mConfig1 = WifiConfigurationTestUtil.createOpenNetwork(); + mScanResult1 = new ScanResult() {{ SSID = removeEnclosingQuotes(mConfig1.SSID); capabilities = "[ESS]"; @@ -69,6 +70,7 @@ public class WifiCandidatesTest extends WifiBaseTest { SSID = removeEnclosingQuotes(mConfig2.SSID); capabilities = "[ESS]"; }}; + doReturn(mScanResult1).when(mScanDetail1).getScanResult(); doReturn(mScanResult2).when(mScanDetail2).getScanResult(); doReturn(mPerBssid).when(mWifiScoreCard).lookupBssid(any(), any()); @@ -79,10 +81,10 @@ public class WifiCandidatesTest extends WifiBaseTest { */ @Test public void testDontDieFromNulls() throws Exception { - mWifiCandidates.add(null, mConfig1, 1, 42, 0.0, false); - mWifiCandidates.add(mScanDetail1, null, 2, 16, 0.0, false); + mWifiCandidates.add(null, mConfig1, 1, 42, 0.0, false, 100); + mWifiCandidates.add(mScanDetail1, null, 2, 16, 0.0, false, 100); doReturn(null).when(mScanDetail2).getScanResult(); - mWifiCandidates.add(mScanDetail2, mConfig2, 3, 314, 1.0, true); + mWifiCandidates.add(mScanDetail2, mConfig2, 3, 314, 1.0, true, 100); assertFalse(mWifiCandidates.remove(null)); assertEquals(0, mWifiCandidates.size()); @@ -93,7 +95,7 @@ public class WifiCandidatesTest extends WifiBaseTest { */ @Test public void testAddJustOne() throws Exception { - assertTrue(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false)); + assertTrue(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100)); assertEquals(1, mWifiCandidates.size()); assertEquals(0, mWifiCandidates.getFaultCount()); @@ -108,7 +110,7 @@ public class WifiCandidatesTest extends WifiBaseTest { public void testQuotingBotch() throws Exception { // Unfortunately ScanResult.SSID is not quoted; make sure we catch that mScanResult1.SSID = mConfig1.SSID; - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, true); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, true, 100); // Should not have added this one assertEquals(0, mWifiCandidates.size()); @@ -167,7 +169,7 @@ public class WifiCandidatesTest extends WifiBaseTest { assertTrue(mWifiCandidates == mWifiCandidates.setPicky(true)); try { mScanResult1.SSID = mConfig1.SSID; // As in testQuotingBotch() - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100); fail("Exception not raised in picky mode"); } catch (IllegalArgumentException e) { assertEquals(1, mWifiCandidates.getFaultCount()); @@ -181,23 +183,23 @@ public class WifiCandidatesTest extends WifiBaseTest { @Test public void testNoOverwriteCases() throws Exception { // Setup is to add the first candidate - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100); assertEquals(1, mWifiCandidates.size()); // Same evaluator, same score. Should not add. - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100)); assertEquals(0, mWifiCandidates.getFaultCount()); // But not considered a fault // Same evaluator, lower score. Should not add. - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 13, 0.0, false)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 13, 0.0, false, 100)); assertEquals(0, mWifiCandidates.getFaultCount()); // Also not a fault // Later evaluator. Should not add (regardless of score). - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 5, 13, 0.0, false)); - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 5, 15, 0.0, false)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 5, 13, 0.0, false, 100)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 5, 15, 0.0, false, 100)); assertEquals(0, mWifiCandidates.getFaultCount()); // Still no faults // Evaluator out of order. Should not add (regardless of score). - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 1, 12, 0.0, false)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 1, 12, 0.0, false, 100)); assertNotNull(mWifiCandidates.getLastFault()); // This one is considered a caller error - assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 1, 15, 0.0, false)); + assertFalse(mWifiCandidates.add(mScanDetail1, mConfig1, 1, 15, 0.0, false, 100)); assertEquals(2, mWifiCandidates.getFaultCount()); // After all that, only one candidate should be there. assertEquals(1, mWifiCandidates.size()); @@ -210,12 +212,12 @@ public class WifiCandidatesTest extends WifiBaseTest { public void testBssidValidation() throws Exception { // Null BSSID. mScanResult1.BSSID = null; - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100); assertTrue("Expecting NPE, got " + mWifiCandidates.getLastFault(), mWifiCandidates.getLastFault() instanceof NullPointerException); // Malformed BSSID mScanResult1.BSSID = "NotaBssid!"; - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100); assertTrue("Expecting IAE, got " + mWifiCandidates.getLastFault(), mWifiCandidates.getLastFault() instanceof IllegalArgumentException); assertEquals(0, mWifiCandidates.size()); @@ -232,8 +234,8 @@ public class WifiCandidatesTest extends WifiBaseTest { mScanResult2.SSID = mScanResult1.SSID; mScanResult2.BSSID = mScanResult1.BSSID.replace('1', '2'); // Add both - mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false); - mWifiCandidates.add(mScanDetail2, mConfig2, 2, 14, 0.0, false); + mWifiCandidates.add(mScanDetail1, mConfig1, 2, 14, 0.0, false, 100); + mWifiCandidates.add(mScanDetail2, mConfig2, 2, 14, 0.0, false, 100); // We expect them both to be there assertEquals(2, mWifiCandidates.size()); // But just one group @@ -268,8 +270,8 @@ public class WifiCandidatesTest extends WifiBaseTest { mScanResult2.SSID = mScanResult1.SSID; mScanResult2.BSSID = mScanResult1.BSSID; // Try adding them both, the higher-scoring one second - assertTrue(mWifiCandidates.add(mScanDetail2, mConfig2, 2, 14, 0.0, false)); - assertTrue(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 15, 0.0, false)); + assertTrue(mWifiCandidates.add(mScanDetail2, mConfig2, 2, 14, 0.0, false, 100)); + assertTrue(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 15, 0.0, false, 90)); // Only one should survive assertEquals(1, mWifiCandidates.size()); // And no faults @@ -278,6 +280,6 @@ public class WifiCandidatesTest extends WifiBaseTest { WifiCandidates.Candidate c; c = mWifiCandidates.getGroupedCandidates().iterator().next().iterator().next(); assertEquals(15, c.getEvaluatorScore()); + assertEquals(90, c.getPredictedThroughputMbps()); } - } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 14ecc0c4c..e77cce9cb 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -2012,7 +2012,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** - * Verify that WifiChannelUtilization is updated after a scan + * Verify that WifiChannelUtilization is updated */ @Test public void verifyWifiChannelUtilizationRefreshedAfterScanResults() { @@ -2056,4 +2056,15 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { verify(mWifiChannelUtilization).setDeviceMobilityState( WifiManager.DEVICE_MOBILITY_STATE_STATIONARY); } + + /** + * Verify that WifiNetworkSelector sets bluetoothConnected correctly + */ + @Test + public void verifyWifiNetworkSelectorSetBluetoothConnected() { + mWifiConnectivityManager.setBluetoothConnected(true); + verify(mWifiNS).setBluetoothConnected(true); + mWifiConnectivityManager.setBluetoothConnected(false); + verify(mWifiNS).setBluetoothConnected(false); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index f576d2ce3..d9abbed12 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -80,6 +80,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { setupThresholds(); mLocalLog = new LocalLog(512); + mThroughputPredictor = new ThroughputPredictor(mContext); mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiScoreCard, @@ -87,7 +88,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { mWifiConfigManager, mClock, mLocalLog, mWifiMetrics, - mWifiNative); + mWifiNative, + mThroughputPredictor + ); mWifiNetworkSelector.registerNetworkEvaluator(mDummyEvaluator); mDummyEvaluator.setEvaluatorToSelectCandidate(true); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); @@ -95,6 +98,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { when(mWifiScoreCard.lookupBssid(any(), any())).thenReturn(mPerBssid); mCompatibilityScorer = new CompatibilityScorer(mScoringParams); mScoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams); + mThroughputScorer = new ThroughputScorer(mScoringParams); when(mWifiNative.getClientInterfaceName()).thenReturn("wlan0"); } @@ -210,6 +214,8 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { private int mStayOnNetworkMinimumRxRate; private CompatibilityScorer mCompatibilityScorer; private ScoreCardBasedScorer mScoreCardBasedScorer; + private ThroughputScorer mThroughputScorer; + private ThroughputPredictor mThroughputPredictor; private void setupContext() { when(mContext.getResources()).thenReturn(mResource); @@ -228,6 +234,11 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { R.integer.config_wifi_framework_min_tx_rate_for_staying_on_network, 16); mStayOnNetworkMinimumRxRate = setupIntegerResource( R.integer.config_wifi_framework_min_rx_rate_for_staying_on_network, 16); + doReturn(false).when(mResource).getBoolean(R.bool.config_wifi_11ax_supported); + doReturn(false).when(mResource).getBoolean( + R.bool.config_wifi_contiguous_160mhz_supported); + doReturn(2).when(mResource).getInteger( + R.integer.config_wifi_max_num_spatial_stream_supported); } private void setupThresholds() { @@ -1155,8 +1166,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { HashSet<String> blacklist = new HashSet<String>(); // DummyNetworkEvaluator always return the first network in the scan results // for connection, so this should connect to the first network. - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork( - scanDetails, + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, true); assertNotNull("Result should be not null", candidate); WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, @@ -1582,4 +1592,25 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { int expid = CompatibilityScorer.COMPATIBILITY_SCORER_DEFAULT_EXPID; verify(mWifiMetrics, atLeastOnce()).setNetworkSelectorExperimentId(eq(expid)); } + + /** + * Tests that metrics are recorded for legacy scorer and throughput scorer. + */ + @Test + public void testCandidateScorerMetricsThrougputScorer() { + mWifiNetworkSelector.registerCandidateScorer(mThroughputScorer); + + // add a second NetworkEvaluator that returns the second network in the scan list + mWifiNetworkSelector.registerNetworkEvaluator( + new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2)); + + test2GhzHighQuality5GhzAvailable(); + + int throughputExpId = experimentIdFromIdentifier(mThroughputScorer.getIdentifier()); + + // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls + // WifiNetworkSelector.selectNetwork() twice + verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(throughputExpId, + WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, true, 2); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java index 287d0b0d8..74954a875 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java @@ -48,7 +48,7 @@ import java.util.Set; * Helper for WifiNetworkSelector unit tests. */ public class WifiNetworkSelectorTestUtil { - + private static final String TAG = "WifiNetworkSelectorTestUtil"; /** * A class that holds a list of scanDetail and their associated WifiConfiguration. */ |