summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOscar Shu <xshu@google.com>2018-06-18 22:36:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-06-18 22:36:42 +0000
commit13842222e10f331dc1ac90d08211d2da804a14c1 (patch)
tree0217140f02bfa656136f5e065a1e835f800e07cc /tests
parent9b830ccff09601d89c83af21667ed4d214d31117 (diff)
parent110a9ead138555f221a7dd5202f3b317e5847877 (diff)
Merge "metrics: wifi radio usage"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiPowerMetricsTest.java116
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java3
3 files changed, 136 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 2a60a1096..186014d1d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -44,6 +44,7 @@ import com.android.server.wifi.nano.WifiMetricsProto.ConnectToNetworkNotificatio
import com.android.server.wifi.nano.WifiMetricsProto.PnoScanMetrics;
import com.android.server.wifi.nano.WifiMetricsProto.SoftApConnectedClientsEvent;
import com.android.server.wifi.nano.WifiMetricsProto.StaEvent;
+import com.android.server.wifi.nano.WifiMetricsProto.WifiRadioUsage;
import com.android.server.wifi.nano.WifiMetricsProto.WpsMetrics;
import com.android.server.wifi.rtt.RttMetrics;
@@ -76,6 +77,7 @@ public class WifiMetricsTest {
@Mock WifiConfigManager mWcm;
@Mock PasspointManager mPpm;
@Mock WifiNetworkSelector mWns;
+ @Mock WifiPowerMetrics mWifiPowerMetrics;
@Before
public void setUp() throws Exception {
@@ -84,7 +86,7 @@ public class WifiMetricsTest {
when(mClock.getElapsedSinceBootMillis()).thenReturn((long) 0);
mTestLooper = new TestLooper();
mWifiMetrics = new WifiMetrics(mClock, mTestLooper.getLooper(),
- new WifiAwareMetrics(mClock), new RttMetrics(mClock));
+ new WifiAwareMetrics(mClock), new RttMetrics(mClock), mWifiPowerMetrics);
mWifiMetrics.setWifiConfigManager(mWcm);
mWifiMetrics.setPasspointManager(mPpm);
mWifiMetrics.setScoringParams(mScoringParams);
@@ -295,6 +297,8 @@ public class WifiMetricsTest {
private static final int NUM_RADIO_MODE_CHANGE_TO_DBS = 34;
private static final int NUM_SOFTAP_USER_BAND_PREFERENCE_UNSATISFIED = 14;
private static final long NUM_WATCHDOG_SUCCESS_DURATION_MS = 65;
+ private static final long WIFI_POWER_METRICS_LOGGING_DURATION = 280;
+ private static final long WIFI_POWER_METRICS_SCAN_TIME = 33;
/** Number of notifications per "Connect to Network" notification type. */
private static final int[] NUM_CONNECT_TO_NETWORK_NOTIFICATIONS = {0, 10, 20, 30, 40};
@@ -688,6 +692,15 @@ public class WifiMetricsTest {
mWifiMetrics.setWatchdogSuccessTimeDurationMs(NUM_WATCHDOG_SUCCESS_DURATION_MS);
mWifiMetrics.setIsMacRandomizationOn(IS_MAC_RANDOMIZATION_ON);
+
+ addWifiPowerMetrics();
+ }
+
+ private void addWifiPowerMetrics() {
+ WifiRadioUsage wifiRadioUsage = new WifiRadioUsage();
+ wifiRadioUsage.loggingDurationMs = WIFI_POWER_METRICS_LOGGING_DURATION;
+ wifiRadioUsage.scanTimeMs = WIFI_POWER_METRICS_SCAN_TIME;
+ when(mWifiPowerMetrics.buildWifiRadioUsageProto()).thenReturn(wifiRadioUsage);
}
private void addSoftApEventsToMetrics() {
@@ -965,6 +978,10 @@ public class WifiMetricsTest {
assertEquals(NUM_WATCHDOG_SUCCESS_DURATION_MS,
mDecodedProto.watchdogTriggerToConnectionSuccessDurationMs);
assertEquals(IS_MAC_RANDOMIZATION_ON, mDecodedProto.isMacRandomizationOn);
+ assertEquals(WIFI_POWER_METRICS_LOGGING_DURATION,
+ mDecodedProto.wifiRadioUsage.loggingDurationMs);
+ assertEquals(WIFI_POWER_METRICS_SCAN_TIME,
+ mDecodedProto.wifiRadioUsage.scanTimeMs);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiPowerMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiPowerMetricsTest.java
new file mode 100644
index 000000000..027eba259
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WifiPowerMetricsTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2018 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 org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+import android.os.RemoteException;
+import android.os.connectivity.WifiBatteryStats;
+import android.support.test.filters.SmallTest;
+
+import com.android.internal.app.IBatteryStats;
+import com.android.server.wifi.nano.WifiMetricsProto.WifiRadioUsage;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.WifiPowerMetrics}.
+ */
+@SmallTest
+public class WifiPowerMetricsTest {
+ @Mock IBatteryStats mBatteryStats;
+ WifiPowerMetrics mWifiPowerMetrics;
+
+ private static final long DEFAULT_VALUE = 0;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mWifiPowerMetrics = new WifiPowerMetrics(mBatteryStats);
+ }
+
+ /**
+ * Tests that WifiRadioUsage has its fields set according to the corresponding fields in
+ * WifiBatteryStats
+ * @throws Exception
+ */
+ @Test
+ public void testBuildWifiRadioUsageProto() throws Exception {
+ final long loggingDuration = 280;
+ final long scanTime = 23;
+ WifiBatteryStats wifiBatteryStats = new WifiBatteryStats();
+ wifiBatteryStats.setLoggingDurationMs(loggingDuration);
+ wifiBatteryStats.setScanTimeMs(scanTime);
+ when(mBatteryStats.getWifiBatteryStats()).thenReturn(wifiBatteryStats);
+ WifiRadioUsage wifiRadioUsage = mWifiPowerMetrics.buildWifiRadioUsageProto();
+ verify(mBatteryStats).getWifiBatteryStats();
+ assertEquals("loggingDurationMs must match with field from WifiBatteryStats",
+ loggingDuration, wifiRadioUsage.loggingDurationMs);
+ assertEquals("scanTimeMs must match with field from WifiBatteryStats",
+ scanTime, wifiRadioUsage.scanTimeMs);
+ }
+
+ /**
+ * Tests that WifiRadioUsage has its fields set to the |DEFAULT_VALUE| when IBatteryStats
+ * returns null
+ * @throws Exception
+ */
+ @Test
+ public void testBuildWifiRadioUsageProtoNull() throws Exception {
+ when(mBatteryStats.getWifiBatteryStats()).thenReturn(null);
+ WifiRadioUsage wifiRadioUsage = mWifiPowerMetrics.buildWifiRadioUsageProto();
+ verify(mBatteryStats).getWifiBatteryStats();
+ assertEquals("loggingDurationMs must be default value when getWifiBatteryStats returns "
+ + "null", DEFAULT_VALUE, wifiRadioUsage.loggingDurationMs);
+ assertEquals("scanTimeMs must be default value when getWifiBatteryStats returns null",
+ DEFAULT_VALUE, wifiRadioUsage.scanTimeMs);
+ }
+
+ /**
+ * Tests that WifiRadioUsage has its fields set to the |DEFAULT_VALUE| when IBatteryStats
+ * throws a RemoteException
+ * @throws Exception
+ */
+ @Test
+ public void testBuildWifiRadioUsageProtoRemoteException() throws Exception {
+ doThrow(new RemoteException()).when(mBatteryStats).getWifiBatteryStats();
+ WifiRadioUsage wifiRadioUsage = mWifiPowerMetrics.buildWifiRadioUsageProto();
+ verify(mBatteryStats).getWifiBatteryStats();
+ assertEquals("loggingDurationMs must be default value when getWifiBatteryStats throws "
+ + "RemoteException", DEFAULT_VALUE, wifiRadioUsage.loggingDurationMs);
+ assertEquals("scanTimeMs must be default value when getWifiBatteryStats throws "
+ + "RemoteException", DEFAULT_VALUE, wifiRadioUsage.scanTimeMs);
+ }
+
+ /**
+ * Tests that dump() pulls data from IBatteryStats
+ * @throws Exception
+ */
+ @Test
+ public void testDumpCallsAppropriateMethods() throws Exception {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter(stream);
+ mWifiPowerMetrics.dump(writer);
+ verify(mBatteryStats, atLeastOnce()).getWifiBatteryStats();
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
index 85f1bede0..f469c45ac 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -80,6 +80,7 @@ import com.android.server.wifi.TestUtil;
import com.android.server.wifi.WifiInjector;
import com.android.server.wifi.WifiMetrics;
import com.android.server.wifi.WifiNative;
+import com.android.server.wifi.WifiPowerMetrics;
import com.android.server.wifi.aware.WifiAwareMetrics;
import com.android.server.wifi.nano.WifiMetricsProto;
import com.android.server.wifi.rtt.RttMetrics;
@@ -141,7 +142,7 @@ public class WifiScanningServiceTest {
mLooper = new TestLooper();
mWifiMetrics = new WifiMetrics(mClock, mLooper.getLooper(), new WifiAwareMetrics(mClock),
- new RttMetrics(mClock));
+ new RttMetrics(mClock), new WifiPowerMetrics());
when(mWifiScannerImplFactory
.create(any(), any(), any()))
.thenReturn(mWifiScannerImpl);