summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Plass <mplass@google.com>2017-05-02 21:51:54 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-05-02 21:51:54 +0000
commit1a96bfa4c7cfb451aca65f90fa49461bcf679b4a (patch)
treeaa267fc81dc9332b37e632f4fb3cb9b9e8dc8eb0 /tests
parent91134c12fe55e8fefb80db981db6f4b18a40207b (diff)
parent8b484d08ba97fd99dfe56dba4bf2fd1bd81e3cde (diff)
Merge changes I2cb3160c,Ie98f2afa,Iebf4b1c3 into oc-dev
am: 8b484d08ba Change-Id: I3142218d6d855c6da6010be3b23cba2a167c58ec
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java115
1 files changed, 12 insertions, 103 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index 6d55b19f4..41f14dd75 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -16,12 +16,9 @@
package com.android.server.wifi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -51,11 +48,11 @@ public class WifiScoreReportTest {
WifiConfiguration mWifiConfiguration;
WifiScoreReport mWifiScoreReport;
ScanDetailCache mScanDetailCache;
+ WifiInfo mWifiInfo;
@Mock Context mContext;
@Mock NetworkAgent mNetworkAgent;
@Mock Resources mResources;
@Mock WifiConfigManager mWifiConfigManager;
- @Mock WifiInfo mWifiInfo;
@Mock WifiMetrics mWifiMetrics;
/**
@@ -94,31 +91,6 @@ public class WifiScoreReportTest {
when(resources.getInteger(
R.integer.config_wifi_framework_wifi_score_good_link_speed_5))
.thenReturn(36);
- when(resources.getBoolean(
- R.bool.config_wifi_framework_cellular_handover_enable_user_triggered_adjustment))
- .thenReturn(true);
- }
-
- /**
- * Pulls the final score from a report string
- *
- * The report string is essentially free-form, intended for debugging,
- * but we would like to know that the score is in there somewhere.
- *
- * Currently, the score is found as the last value in a comma-separated
- * list enclosed in square brackets.
- */
- private int fishScoreFromReportString(String report) {
- int score = 0;
- if (report != null) {
- String[] f = report.split("]");
- assertTrue(f.length > 1);
- f = f[f.length - 2].split(",");
- score = Integer.parseInt(f[f.length - 1]);
- // clipping happens after stashing in report string, so do that here.
- score = Integer.min(score, NetworkAgent.WIFI_BASE_SCORE);
- }
- return score;
}
/**
@@ -132,6 +104,8 @@ public class WifiScoreReportTest {
config.SSID = "nooooooooooo";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.hiddenSSID = false;
+ mWifiInfo = new WifiInfo();
+ mWifiInfo.setFrequency(2412);
when(mWifiConfigManager.getSavedNetworks()).thenReturn(Arrays.asList(config));
when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(config);
mWifiConfiguration = config;
@@ -164,8 +138,8 @@ public class WifiScoreReportTest {
*/
@Test
public void calculateAndReportScoreSucceeds() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-77);
int aggressiveHandover = 0;
+ mWifiInfo.setRssi(-77);
mWifiScoreReport.calculateAndReportScore(mWifiInfo,
mNetworkAgent, aggressiveHandover, mWifiMetrics);
verify(mNetworkAgent).sendNetworkScore(anyInt());
@@ -179,73 +153,13 @@ public class WifiScoreReportTest {
*/
@Test
public void networkAgentMayBeNull() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-33);
+ mWifiInfo.setRssi(-33);
mWifiScoreReport.enableVerboseLogging(true);
mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
verify(mWifiMetrics).incrementWifiScoreCount(anyInt());
}
/**
- * Test operation of saved last report
- *
- * One score is calculated
- * Expect: last report is not valid before any score is calculated
- * Expect: last report is valid after a score is calculated
- * Expect: the score in the last report string matches the reported score
- * Expect: reset makes the last report invalid again
- */
- @Test
- public void makeSureLastReportWorks() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-33);
- assertFalse(mWifiScoreReport.isLastReportValid());
- mWifiScoreReport.enableVerboseLogging(true);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, mNetworkAgent, 0, mWifiMetrics);
- assertTrue(mWifiScoreReport.isLastReportValid());
- String report = mWifiScoreReport.getLastReport();
- int score = fishScoreFromReportString(report);
- verify(mWifiMetrics).incrementWifiScoreCount(score);
- verify(mNetworkAgent).sendNetworkScore(score);
- mWifiScoreReport.reset();
- assertFalse(mWifiScoreReport.isLastReportValid());
- assertTrue(mWifiScoreReport.getLastReport().equals(""));
- }
-
- /**
- * Test bad linkspeed counter
- *
- * Expect badLinkspeed count to be incemented based on bad link speed.
- * Expect counter to be pinned at a maximum value.
- * Expect counter to be cleared by reset.
- */
- @Test
- public void badLinkspeedCounter() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-123);
- when(mWifiInfo.getLinkSpeed()).thenReturn(1);
- when(mWifiInfo.is24GHz()).thenReturn(true);
- assertFalse(mWifiScoreReport.isLastReportValid());
- mWifiScoreReport.enableVerboseLogging(true);
- assertEquals(0, mWifiScoreReport.getLastBadLinkspeedcount());
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- assertEquals(1, mWifiScoreReport.getLastBadLinkspeedcount());
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- assertEquals(2, mWifiScoreReport.getLastBadLinkspeedcount());
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- assertEquals(3, mWifiScoreReport.getLastBadLinkspeedcount());
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 1, mWifiMetrics);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 1, mWifiMetrics);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- mWifiScoreReport.calculateAndReportScore(mWifiInfo, null, 0, mWifiMetrics);
- assertEquals(6, mWifiScoreReport.getLastBadLinkspeedcount()); // pinned at limit
- verify(mWifiMetrics, times(9)).incrementWifiScoreCount(anyInt());
- verify(mWifiInfo, atLeast(9)).is24GHz();
- assertTrue(mWifiScoreReport.isLastReportValid());
- mWifiScoreReport.reset();
- assertEquals(0, mWifiScoreReport.getLastBadLinkspeedcount());
- }
-
- /**
* Exercise the rates with low RSSI
*
* The setup has a low (not bad) RSSI, and data movement (txSuccessRate) above
@@ -255,16 +169,14 @@ public class WifiScoreReportTest {
*/
@Test
public void allowLowRssiIfDataIsMoving() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-80);
- when(mWifiInfo.getLinkSpeed()).thenReturn(6); // Mbps
- when(mWifiInfo.is24GHz()).thenReturn(true);
+ mWifiInfo.setRssi(-80);
+ mWifiInfo.setLinkSpeed(6); // Mbps
mWifiInfo.txSuccessRate = 5.1; // proportional to pps
mWifiInfo.rxSuccessRate = 5.1;
for (int i = 0; i < 10; i++) {
mWifiScoreReport.calculateAndReportScore(mWifiInfo, mNetworkAgent, 0, mWifiMetrics);
}
- assertTrue(mWifiScoreReport.isLastReportValid());
- int score = fishScoreFromReportString(mWifiScoreReport.getLastReport());
+ int score = mWifiInfo.score;
assertTrue(score > CELLULAR_THRESHOLD_SCORE);
}
@@ -278,19 +190,16 @@ public class WifiScoreReportTest {
*/
@Test
public void giveUpOnBadRssiWhenDataIsNotMoving() throws Exception {
- when(mWifiInfo.getRssi()).thenReturn(-100);
- when(mWifiInfo.getLinkSpeed()).thenReturn(6); // Mbps
- when(mWifiInfo.is24GHz()).thenReturn(true);
+ mWifiInfo.setRssi(-100);
+ mWifiInfo.setLinkSpeed(6); // Mbps
+ mWifiInfo.setFrequency(5220);
mWifiScoreReport.enableVerboseLogging(true);
mWifiInfo.txSuccessRate = 0.1;
mWifiInfo.rxSuccessRate = 0.1;
for (int i = 0; i < 10; i++) {
mWifiScoreReport.calculateAndReportScore(mWifiInfo, mNetworkAgent, 0, mWifiMetrics);
- String report = mWifiScoreReport.getLastReport();
- assertTrue(report.contains(" br "));
}
- assertTrue(mWifiScoreReport.isLastReportValid());
- int score = fishScoreFromReportString(mWifiScoreReport.getLastReport());
+ int score = mWifiInfo.score;
assertTrue(score < CELLULAR_THRESHOLD_SCORE);
verify(mNetworkAgent, atLeast(1)).sendNetworkScore(score);
}