summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Plass <mplass@google.com>2017-02-15 15:40:56 -0800
committerMichael Plass <mplass@google.com>2017-02-24 14:55:09 -0800
commit3401582e1b1defc1877c7c47c6a839611fa211c3 (patch)
tree25e1f51975e0c5a5ec997f0304007f44c08e3acd /tests
parente87ed1444a1affdaf20a42ce9b90f0acad1c2f6c (diff)
[WifiVendorHal] RSSI Monitoring
Test: New unit test Bug: 34903056 Change-Id: I0246a6bb21d3d4d49854ed1c8f64f0cdf48cb839
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java54
1 files changed, 51 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
index 19374ca8c..ec477b263 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
@@ -54,6 +54,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -82,8 +83,14 @@ public class WifiVendorHalTest {
private IWifiStaIface mIWifiStaIface;
@Mock
private IWifiRttController mIWifiRttController;
- @Mock
- private IWifiStaIfaceEventCallback mIWifistaIfaceEventCallback;
+ private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback;
+
+ /**
+ * Identity function to supply a type to its argument, which is a lambda
+ */
+ static Answer<WifiStatus> answerWifiStatus(Answer<WifiStatus> statusLambda) {
+ return (statusLambda);
+ }
/**
* Sets up for unit test
@@ -127,8 +134,13 @@ public class WifiVendorHalTest {
.thenReturn(mIWifiRttController);
when(mIWifiChip.registerEventCallback(any(IWifiChipEventCallback.class)))
.thenReturn(mWifiStatusSuccess);
+ mIWifiStaIfaceEventCallback = null;
when(mIWifiStaIface.registerEventCallback(any(IWifiStaIfaceEventCallback.class)))
- .thenReturn(mWifiStatusSuccess);
+ .thenAnswer(answerWifiStatus((invocation) -> {
+ Object[] args = invocation.getArguments();
+ mIWifiStaIfaceEventCallback = (IWifiStaIfaceEventCallback) args[0];
+ return (mWifiStatusSuccess);
+ }));
// Create the vendor HAL object under test.
mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread);
@@ -526,6 +538,42 @@ public class WifiVendorHalTest {
}
/**
+ * Test the setup, invocation, and removal of a RSSI event handler
+ *
+ */
+ @Test
+ public void testRssiMonitoring() throws Exception {
+ when(mIWifiStaIface.startRssiMonitoring(anyInt(), anyInt(), anyInt()))
+ .thenReturn(mWifiStatusSuccess);
+ when(mIWifiStaIface.stopRssiMonitoring(anyInt()))
+ .thenReturn(mWifiStatusSuccess);
+
+ ArrayList<Byte> breach = new ArrayList<>(10);
+ byte hi = -21;
+ byte med = -42;
+ byte lo = -84;
+ Byte lower = -88;
+ WifiNative.WifiRssiEventHandler handler;
+ handler = ((cur) -> {
+ breach.add(cur);
+ });
+ assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); // not started
+ assertEquals(-1, mWifiVendorHal.stopRssiMonitoring()); // not started
+ assertTrue(mWifiVendorHal.startVendorHalSta());
+ assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
+ int theCmdId = mWifiVendorHal.sRssiMonCmdId;
+ breach.clear();
+ mIWifiStaIfaceEventCallback.onRssiThresholdBreached(theCmdId, new byte[6], lower);
+ assertEquals(breach.get(0), lower);
+ assertEquals(0, mWifiVendorHal.stopRssiMonitoring());
+ assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
+ assertEquals(0, mWifiVendorHal.startRssiMonitoring(med, lo, handler)); // replacing works
+ assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, null)); // null handler fails
+ assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
+ assertEquals(-1, mWifiVendorHal.startRssiMonitoring(lo, hi, handler)); // empty range
+ }
+
+ /**
* Test that getApfCapabilities is hooked up to the HAL correctly
*
* A call before the vendor HAL is started should return a non-null result with version 0