diff options
author | Eric Schwarzenbach <easchwar@google.com> | 2017-12-07 11:25:51 -0800 |
---|---|---|
committer | Eric Schwarzenbach <easchwar@google.com> | 2017-12-20 16:53:45 -0800 |
commit | 46e3a9a060014c6a2e02ba46a73318c81298b7b5 (patch) | |
tree | 6cd5a25e35bbe6eb839785484b6aff170f6ec561 /tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java | |
parent | 340f87d8557b943d0d2f18e48881a6c9751104e6 (diff) | |
download | android_frameworks_opt_net_wifi-46e3a9a060014c6a2e02ba46a73318c81298b7b5.tar.gz android_frameworks_opt_net_wifi-46e3a9a060014c6a2e02ba46a73318c81298b7b5.tar.bz2 android_frameworks_opt_net_wifi-46e3a9a060014c6a2e02ba46a73318c81298b7b5.zip |
Add WakeupEvaluator.
The WakeupEvaluator searches through scan results to find an
in-range connectable network.
Bug: 64094365
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I24700b58307dca68814098f22c40cfcd40e46a12
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java new file mode 100644 index 000000000..d9750189f --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WakeupEvaluatorTest.java @@ -0,0 +1,156 @@ +/* + * Copyright 2017 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.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import android.net.wifi.ScanResult; +import android.util.ArraySet; + +import com.android.server.wifi.util.ScanResultUtil; + +import com.google.android.collect.Sets; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.Set; + + + +/** + * Unit tests for {@link WakeupEvaluator}. + */ +public class WakeupEvaluatorTest { + + private static final String SAVED_SSID_1 = "saved ssid 1"; + private static final String SAVED_SSID_2 = "saved ssid 2"; + private static final String UNSAVED_SSID = "unsaved ssid"; + + private static final int FREQ_24 = 2402; + private static final int FREQ_5 = 5000; + + private static final int THRESHOLD_24 = -10; + private static final int THRESHOLD_5 = -1; + + private WakeupEvaluator mWakeupEvaluator; + + private ScanResult makeScanResult(String ssid, int frequency, int level) { + ScanResult scanResult = new ScanResult(); + scanResult.SSID = ssid; + scanResult.frequency = frequency; + scanResult.level = level; + scanResult.capabilities = "[]"; + + return scanResult; + } + + private Set<ScanResultMatchInfo> getSavedNetworks() { + Set<ScanResultMatchInfo> networks = new ArraySet<>(); + networks.add(ScanResultMatchInfo.fromWifiConfiguration( + WifiConfigurationTestUtil.createOpenNetwork( + ScanResultUtil.createQuotedSSID(SAVED_SSID_1)))); + networks.add(ScanResultMatchInfo.fromWifiConfiguration( + WifiConfigurationTestUtil.createOpenNetwork( + ScanResultUtil.createQuotedSSID(SAVED_SSID_2)))); + return networks; + } + + @Before + public void setUp() { + mWakeupEvaluator = new WakeupEvaluator(THRESHOLD_24, THRESHOLD_5); + } + + /** + * Verify that isBelowThreshold returns true for networks below the filter threshold. + */ + @Test + public void isBelowThreshold_returnsTrueWhenRssiIsBelowThreshold() { + ScanResult scanResult24 = makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 - 1); + assertTrue(mWakeupEvaluator.isBelowThreshold(scanResult24)); + + ScanResult scanResult5 = makeScanResult(SAVED_SSID_1, FREQ_5, THRESHOLD_5 - 1); + assertTrue(mWakeupEvaluator.isBelowThreshold(scanResult5)); + } + + /** + * Verify that isBelowThreshold returns false for networks above the filter threshold. + */ + @Test + public void isBelowThreshold_returnsFalseWhenRssiIsAboveThreshold() { + ScanResult scanResult24 = makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 + 1); + assertFalse(mWakeupEvaluator.isBelowThreshold(scanResult24)); + + ScanResult scanResult5 = makeScanResult(SAVED_SSID_1, FREQ_5, THRESHOLD_5 + 1); + assertFalse(mWakeupEvaluator.isBelowThreshold(scanResult5)); + } + + /** + * Verify that findViableNetwork does not select ScanResult that is not present in the + * WifiConfigurations. + */ + @Test + public void findViableNetwork_returnsNullWhenScanResultIsNotInSavedNetworks() { + Set<ScanResult> scanResults = Collections.singleton( + makeScanResult(UNSAVED_SSID, FREQ_24, THRESHOLD_24 + 1)); + + ScanResult scanResult = mWakeupEvaluator.findViableNetwork(scanResults, getSavedNetworks()); + + assertNull(scanResult); + } + + /** + * Verify that findViableNetwork does not select a scan result that is below the threshold. + */ + @Test + public void findViableNetwork_returnsNullWhenScanResultIsBelowThreshold() { + Set<ScanResult> scanResults = Collections.singleton( + makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 - 1)); + + ScanResult scanResult = mWakeupEvaluator.findViableNetwork(scanResults, getSavedNetworks()); + assertNull(scanResult); + } + + /** + * Verify that findViableNetwork returns a viable ScanResult. + */ + @Test + public void findViableNetwork_returnsConnectableScanResult() { + ScanResult savedScanResult = makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 + 1); + Set<ScanResult> scanResults = Collections.singleton(savedScanResult); + + ScanResult scanResult = mWakeupEvaluator.findViableNetwork(scanResults, getSavedNetworks()); + assertEquals(savedScanResult, scanResult); + } + + /** + * Verify that findViableNetwork returns the viable ScanResult with the highest RSSI. + */ + @Test + public void findViableNetwork_returnsConnectableScanResultWithHighestRssi() { + ScanResult savedScanResultLow = makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 + 1); + ScanResult savedScanResultHigh = makeScanResult(SAVED_SSID_1, FREQ_24, THRESHOLD_24 + 10); + Set<ScanResult> scanResults = Sets.newArraySet(savedScanResultLow, savedScanResultHigh); + + ScanResult scanResult = mWakeupEvaluator.findViableNetwork(scanResults, getSavedNetworks()); + assertEquals(savedScanResultHigh, scanResult); + } +} |