blob: 32d1daa928be402c040ba221ab87d45eb9f4d579 [file] [log] [blame]
/*
* Copyright (C) 2016 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.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.net.wifi.IApInterface;
import android.net.wifi.IClientInterface;
import android.net.wifi.WifiConfiguration;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Pair;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
/**
* Unit tests for {@link com.android.server.wifi.WifiNative}.
*/
@SmallTest
public class WifiNativeTest {
private static final long FATE_REPORT_DRIVER_TIMESTAMP_USEC = 12345;
private static final byte[] FATE_REPORT_FRAME_BYTES = new byte[] {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 0, 1, 2, 3, 4, 5, 6, 7};
private static final WifiNative.TxFateReport TX_FATE_REPORT = new WifiNative.TxFateReport(
WifiLoggerHal.TX_PKT_FATE_SENT,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_ETHERNET_II,
FATE_REPORT_FRAME_BYTES
);
private static final WifiNative.RxFateReport RX_FATE_REPORT = new WifiNative.RxFateReport(
WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_ETHERNET_II,
FATE_REPORT_FRAME_BYTES
);
private static final FrameTypeMapping[] FRAME_TYPE_MAPPINGS = new FrameTypeMapping[] {
new FrameTypeMapping(WifiLoggerHal.FRAME_TYPE_UNKNOWN, "unknown", "N/A"),
new FrameTypeMapping(WifiLoggerHal.FRAME_TYPE_ETHERNET_II, "data", "Ethernet"),
new FrameTypeMapping(WifiLoggerHal.FRAME_TYPE_80211_MGMT, "802.11 management",
"802.11 Mgmt"),
new FrameTypeMapping((byte) 42, "42", "N/A")
};
private static final FateMapping[] TX_FATE_MAPPINGS = new FateMapping[] {
new FateMapping(WifiLoggerHal.TX_PKT_FATE_ACKED, "acked"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_SENT, "sent"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_FW_QUEUED, "firmware queued"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_FW_DROP_INVALID,
"firmware dropped (invalid frame)"),
new FateMapping(
WifiLoggerHal.TX_PKT_FATE_FW_DROP_NOBUFS, "firmware dropped (no bufs)"),
new FateMapping(
WifiLoggerHal.TX_PKT_FATE_FW_DROP_OTHER, "firmware dropped (other)"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_DRV_QUEUED, "driver queued"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_DRV_DROP_INVALID,
"driver dropped (invalid frame)"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_DRV_DROP_NOBUFS,
"driver dropped (no bufs)"),
new FateMapping(WifiLoggerHal.TX_PKT_FATE_DRV_DROP_OTHER, "driver dropped (other)"),
new FateMapping((byte) 42, "42")
};
private static final FateMapping[] RX_FATE_MAPPINGS = new FateMapping[] {
new FateMapping(WifiLoggerHal.RX_PKT_FATE_SUCCESS, "success"),
new FateMapping(WifiLoggerHal.RX_PKT_FATE_FW_QUEUED, "firmware queued"),
new FateMapping(
WifiLoggerHal.RX_PKT_FATE_FW_DROP_FILTER, "firmware dropped (filter)"),
new FateMapping(WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID,
"firmware dropped (invalid frame)"),
new FateMapping(
WifiLoggerHal.RX_PKT_FATE_FW_DROP_NOBUFS, "firmware dropped (no bufs)"),
new FateMapping(
WifiLoggerHal.RX_PKT_FATE_FW_DROP_OTHER, "firmware dropped (other)"),
new FateMapping(WifiLoggerHal.RX_PKT_FATE_DRV_QUEUED, "driver queued"),
new FateMapping(
WifiLoggerHal.RX_PKT_FATE_DRV_DROP_FILTER, "driver dropped (filter)"),
new FateMapping(WifiLoggerHal.RX_PKT_FATE_DRV_DROP_INVALID,
"driver dropped (invalid frame)"),
new FateMapping(
WifiLoggerHal.RX_PKT_FATE_DRV_DROP_NOBUFS, "driver dropped (no bufs)"),
new FateMapping(WifiLoggerHal.RX_PKT_FATE_DRV_DROP_OTHER, "driver dropped (other)"),
new FateMapping((byte) 42, "42")
};
private static final WifiNative.SignalPollResult SIGNAL_POLL_RESULT =
new WifiNative.SignalPollResult() {{
currentRssi = -60;
txBitrate = 12;
associationFrequency = 5240;
}};
private static final WifiNative.TxPacketCounters PACKET_COUNTERS_RESULT =
new WifiNative.TxPacketCounters() {{
txSucceeded = 2000;
txFailed = 120;
}};
private static final Set<Integer> SCAN_FREQ_SET =
new HashSet<Integer>() {{
add(2410);
add(2450);
add(5050);
add(5200);
}};
private static final String TEST_QUOTED_SSID_1 = "\"testSsid1\"";
private static final String TEST_QUOTED_SSID_2 = "\"testSsid2\"";
private static final Set<String> SCAN_HIDDEN_NETWORK_SSID_SET =
new HashSet<String>() {{
add(TEST_QUOTED_SSID_1);
add(TEST_QUOTED_SSID_2);
}};
private static final WifiNative.PnoSettings TEST_PNO_SETTINGS =
new WifiNative.PnoSettings() {{
isConnected = false;
periodInMs = 6000;
networkList = new WifiNative.PnoNetwork[2];
networkList[0] = new WifiNative.PnoNetwork();
networkList[1] = new WifiNative.PnoNetwork();
networkList[0].ssid = TEST_QUOTED_SSID_1;
networkList[1].ssid = TEST_QUOTED_SSID_2;
}};
@Mock private WifiVendorHal mWifiVendorHal;
@Mock private WificondControl mWificondControl;
@Mock private SupplicantStaIfaceHal mStaIfaceHal;
private WifiNative mWifiNative;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(mWifiVendorHal.isVendorHalSupported()).thenReturn(true);
when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(true);
mWifiNative = new WifiNative("test0", mWifiVendorHal, mStaIfaceHal, mWificondControl);
}
/**
* Verifies that TxFateReport's constructor sets all of the TxFateReport fields.
*/
@Test
public void testTxFateReportCtorSetsFields() {
WifiNative.TxFateReport fateReport = new WifiNative.TxFateReport(
WifiLoggerHal.TX_PKT_FATE_SENT, // non-zero value
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_ETHERNET_II, // non-zero value
FATE_REPORT_FRAME_BYTES
);
assertEquals(WifiLoggerHal.TX_PKT_FATE_SENT, fateReport.mFate);
assertEquals(FATE_REPORT_DRIVER_TIMESTAMP_USEC, fateReport.mDriverTimestampUSec);
assertEquals(WifiLoggerHal.FRAME_TYPE_ETHERNET_II, fateReport.mFrameType);
assertArrayEquals(FATE_REPORT_FRAME_BYTES, fateReport.mFrameBytes);
}
/**
* Verifies that RxFateReport's constructor sets all of the RxFateReport fields.
*/
@Test
public void testRxFateReportCtorSetsFields() {
WifiNative.RxFateReport fateReport = new WifiNative.RxFateReport(
WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID, // non-zero value
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_ETHERNET_II, // non-zero value
FATE_REPORT_FRAME_BYTES
);
assertEquals(WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID, fateReport.mFate);
assertEquals(FATE_REPORT_DRIVER_TIMESTAMP_USEC, fateReport.mDriverTimestampUSec);
assertEquals(WifiLoggerHal.FRAME_TYPE_ETHERNET_II, fateReport.mFrameType);
assertArrayEquals(FATE_REPORT_FRAME_BYTES, fateReport.mFrameBytes);
}
/**
* Verifies the hashCode methods for HiddenNetwork and PnoNetwork classes
*/
@Test
public void testHashCode() {
WifiNative.HiddenNetwork hiddenNet1 = new WifiNative.HiddenNetwork();
hiddenNet1.ssid = new String("sametext");
WifiNative.HiddenNetwork hiddenNet2 = new WifiNative.HiddenNetwork();
hiddenNet2.ssid = new String("sametext");
assertTrue(hiddenNet1.equals(hiddenNet2));
assertEquals(hiddenNet1.hashCode(), hiddenNet2.hashCode());
WifiNative.PnoNetwork pnoNet1 = new WifiNative.PnoNetwork();
pnoNet1.ssid = new String("sametext");
pnoNet1.flags = 2;
pnoNet1.auth_bit_field = 4;
WifiNative.PnoNetwork pnoNet2 = new WifiNative.PnoNetwork();
pnoNet2.ssid = new String("sametext");
pnoNet2.flags = 2;
pnoNet2.auth_bit_field = 4;
assertTrue(pnoNet1.equals(pnoNet2));
assertEquals(pnoNet1.hashCode(), pnoNet2.hashCode());
}
// Support classes for test{Tx,Rx}FateReportToString.
private static class FrameTypeMapping {
byte mTypeNumber;
String mExpectedTypeText;
String mExpectedProtocolText;
FrameTypeMapping(byte typeNumber, String expectedTypeText, String expectedProtocolText) {
this.mTypeNumber = typeNumber;
this.mExpectedTypeText = expectedTypeText;
this.mExpectedProtocolText = expectedProtocolText;
}
}
private static class FateMapping {
byte mFateNumber;
String mExpectedText;
FateMapping(byte fateNumber, String expectedText) {
this.mFateNumber = fateNumber;
this.mExpectedText = expectedText;
}
}
/**
* Verifies that FateReport.getTableHeader() prints the right header.
*/
@Test
public void testFateReportTableHeader() {
final String header = WifiNative.FateReport.getTableHeader();
assertEquals(
"\nTime usec Walltime Direction Fate "
+ "Protocol Type Result\n"
+ "--------- -------- --------- ---- "
+ "-------- ---- ------\n", header);
}
/**
* Verifies that TxFateReport.toTableRowString() includes the information we care about.
*/
@Test
public void testTxFateReportToTableRowString() {
WifiNative.TxFateReport fateReport = TX_FATE_REPORT;
assertTrue(
fateReport.toTableRowString().replaceAll("\\s+", " ").trim().matches(
FATE_REPORT_DRIVER_TIMESTAMP_USEC + " " // timestamp
+ "\\d{2}:\\d{2}:\\d{2}\\.\\d{3} " // walltime
+ "TX " // direction
+ "sent " // fate
+ "Ethernet " // type
+ "N/A " // protocol
+ "N/A" // result
)
);
for (FrameTypeMapping frameTypeMapping : FRAME_TYPE_MAPPINGS) {
fateReport = new WifiNative.TxFateReport(
WifiLoggerHal.TX_PKT_FATE_SENT,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
frameTypeMapping.mTypeNumber,
FATE_REPORT_FRAME_BYTES
);
assertTrue(
fateReport.toTableRowString().replaceAll("\\s+", " ").trim().matches(
FATE_REPORT_DRIVER_TIMESTAMP_USEC + " " // timestamp
+ "\\d{2}:\\d{2}:\\d{2}\\.\\d{3} " // walltime
+ "TX " // direction
+ "sent " // fate
+ frameTypeMapping.mExpectedProtocolText + " " // type
+ "N/A " // protocol
+ "N/A" // result
)
);
}
for (FateMapping fateMapping : TX_FATE_MAPPINGS) {
fateReport = new WifiNative.TxFateReport(
fateMapping.mFateNumber,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_80211_MGMT,
FATE_REPORT_FRAME_BYTES
);
assertTrue(
fateReport.toTableRowString().replaceAll("\\s+", " ").trim().matches(
FATE_REPORT_DRIVER_TIMESTAMP_USEC + " " // timestamp
+ "\\d{2}:\\d{2}:\\d{2}\\.\\d{3} " // walltime
+ "TX " // direction
+ Pattern.quote(fateMapping.mExpectedText) + " " // fate
+ "802.11 Mgmt " // type
+ "N/A " // protocol
+ "N/A" // result
)
);
}
}
/**
* Verifies that TxFateReport.toVerboseStringWithPiiAllowed() includes the information we care
* about.
*/
@Test
public void testTxFateReportToVerboseStringWithPiiAllowed() {
WifiNative.TxFateReport fateReport = TX_FATE_REPORT;
String verboseFateString = fateReport.toVerboseStringWithPiiAllowed();
assertTrue(verboseFateString.contains("Frame direction: TX"));
assertTrue(verboseFateString.contains("Frame timestamp: 12345"));
assertTrue(verboseFateString.contains("Frame fate: sent"));
assertTrue(verboseFateString.contains("Frame type: data"));
assertTrue(verboseFateString.contains("Frame protocol: Ethernet"));
assertTrue(verboseFateString.contains("Frame protocol type: N/A"));
assertTrue(verboseFateString.contains("Frame length: 16"));
assertTrue(verboseFateString.contains(
"61 62 63 64 65 66 67 68 00 01 02 03 04 05 06 07")); // hex dump
// TODO(quiche): uncomment this, once b/27975149 is fixed.
// assertTrue(verboseFateString.contains("abcdefgh........")); // hex dump
for (FrameTypeMapping frameTypeMapping : FRAME_TYPE_MAPPINGS) {
fateReport = new WifiNative.TxFateReport(
WifiLoggerHal.TX_PKT_FATE_SENT,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
frameTypeMapping.mTypeNumber,
FATE_REPORT_FRAME_BYTES
);
verboseFateString = fateReport.toVerboseStringWithPiiAllowed();
assertTrue(verboseFateString.contains("Frame type: "
+ frameTypeMapping.mExpectedTypeText));
}
for (FateMapping fateMapping : TX_FATE_MAPPINGS) {
fateReport = new WifiNative.TxFateReport(
fateMapping.mFateNumber,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_80211_MGMT,
FATE_REPORT_FRAME_BYTES
);
verboseFateString = fateReport.toVerboseStringWithPiiAllowed();
assertTrue(verboseFateString.contains("Frame fate: " + fateMapping.mExpectedText));
}
}
/**
* Verifies that RxFateReport.toTableRowString() includes the information we care about.
*/
@Test
public void testRxFateReportToTableRowString() {
WifiNative.RxFateReport fateReport = RX_FATE_REPORT;
assertTrue(
fateReport.toTableRowString().replaceAll("\\s+", " ").trim().matches(
FATE_REPORT_DRIVER_TIMESTAMP_USEC + " " // timestamp
+ "\\d{2}:\\d{2}:\\d{2}\\.\\d{3} " // walltime
+ "RX " // direction
+ Pattern.quote("firmware dropped (invalid frame) ") // fate
+ "Ethernet " // type
+ "N/A " // protocol
+ "N/A" // result
)
);
// FrameTypeMappings omitted, as they're the same as for TX.
for (FateMapping fateMapping : RX_FATE_MAPPINGS) {
fateReport = new WifiNative.RxFateReport(
fateMapping.mFateNumber,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_80211_MGMT,
FATE_REPORT_FRAME_BYTES
);
assertTrue(
fateReport.toTableRowString().replaceAll("\\s+", " ").trim().matches(
FATE_REPORT_DRIVER_TIMESTAMP_USEC + " " // timestamp
+ "\\d{2}:\\d{2}:\\d{2}\\.\\d{3} " // walltime
+ "RX " // direction
+ Pattern.quote(fateMapping.mExpectedText) + " " // fate
+ "802.11 Mgmt " // type
+ "N/A " // protocol
+ "N/A" // result
)
);
}
}
/**
* Verifies that RxFateReport.toVerboseStringWithPiiAllowed() includes the information we care
* about.
*/
@Test
public void testRxFateReportToVerboseStringWithPiiAllowed() {
WifiNative.RxFateReport fateReport = RX_FATE_REPORT;
String verboseFateString = fateReport.toVerboseStringWithPiiAllowed();
assertTrue(verboseFateString.contains("Frame direction: RX"));
assertTrue(verboseFateString.contains("Frame timestamp: 12345"));
assertTrue(verboseFateString.contains("Frame fate: firmware dropped (invalid frame)"));
assertTrue(verboseFateString.contains("Frame type: data"));
assertTrue(verboseFateString.contains("Frame protocol: Ethernet"));
assertTrue(verboseFateString.contains("Frame protocol type: N/A"));
assertTrue(verboseFateString.contains("Frame length: 16"));
assertTrue(verboseFateString.contains(
"61 62 63 64 65 66 67 68 00 01 02 03 04 05 06 07")); // hex dump
// TODO(quiche): uncomment this, once b/27975149 is fixed.
// assertTrue(verboseFateString.contains("abcdefgh........")); // hex dump
// FrameTypeMappings omitted, as they're the same as for TX.
for (FateMapping fateMapping : RX_FATE_MAPPINGS) {
fateReport = new WifiNative.RxFateReport(
fateMapping.mFateNumber,
FATE_REPORT_DRIVER_TIMESTAMP_USEC,
WifiLoggerHal.FRAME_TYPE_80211_MGMT,
FATE_REPORT_FRAME_BYTES
);
verboseFateString = fateReport.toVerboseStringWithPiiAllowed();
assertTrue(verboseFateString.contains("Frame fate: " + fateMapping.mExpectedText));
}
}
/**
* Verifies that startPktFateMonitoring returns false when HAL is not started.
*/
@Test
public void testStartPktFateMonitoringReturnsFalseWhenHalIsNotStarted() {
assertFalse(mWifiNative.isHalStarted());
assertFalse(mWifiNative.startPktFateMonitoring());
}
/**
* Verifies that getTxPktFates returns error when HAL is not started.
*/
@Test
public void testGetTxPktFatesReturnsErrorWhenHalIsNotStarted() {
WifiNative.TxFateReport[] fateReports = null;
assertFalse(mWifiNative.isHalStarted());
assertFalse(mWifiNative.getTxPktFates(fateReports));
}
/**
* Verifies that getRxPktFates returns error when HAL is not started.
*/
@Test
public void testGetRxPktFatesReturnsErrorWhenHalIsNotStarted() {
WifiNative.RxFateReport[] fateReports = null;
assertFalse(mWifiNative.isHalStarted());
assertFalse(mWifiNative.getRxPktFates(fateReports));
}
// TODO(quiche): Add tests for the success cases (when HAL has been started). Specifically:
// - testStartPktFateMonitoringCallsHalIfHalIsStarted()
// - testGetTxPktFatesCallsHalIfHalIsStarted()
// - testGetRxPktFatesCallsHalIfHalIsStarted()
//
// Adding these tests is difficult to do at the moment, because we can't mock out the HAL
// itself. Also, we can't mock out the native methods, because those methods are private.
// b/28005116.
/** Verifies that getDriverStateDumpNative returns null when HAL is not started. */
@Test
public void testGetDriverStateDumpReturnsNullWhenHalIsNotStarted() {
assertEquals(null, mWifiNative.getDriverStateDump());
}
// TODO(b/28005116): Add test for the success case of getDriverStateDump().
/**
* Verifies that setupDriverForClientMode() calls underlying WificondControl.
*/
@Test
public void testSetupDriverForClientMode() {
IClientInterface clientInterface = mock(IClientInterface.class);
when(mWificondControl.setupDriverForClientMode()).thenReturn(clientInterface);
Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
assertEquals(clientInterface, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl).setupDriverForClientMode();
}
/**
* Verifies that setupDriverForClientMode() does not call start vendor HAL when it is not
* supported and calls underlying WificondControl setup.
*/
@Test
public void testSetupDriverForClientModeWithNoVendorHal() {
when(mWifiVendorHal.isVendorHalSupported()).thenReturn(false);
IClientInterface clientInterface = mock(IClientInterface.class);
when(mWificondControl.setupDriverForClientMode()).thenReturn(clientInterface);
Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
assertEquals(clientInterface, statusAndClientInterface.second);
verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
verify(mWificondControl).setupDriverForClientMode();
}
/**
* Verifies that setupDriverForClientMode() returns null when underlying WificondControl
* call fails.
*/
@Test
public void testSetupDriverForClientModeWificondError() {
when(mWificondControl.setupDriverForClientMode()).thenReturn(null);
Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndClientInterface.first);
assertEquals(null, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl).setupDriverForClientMode();
}
/**
* Verifies that setupDriverForClientMode() returns null when underlying Hal call fails.
*/
@Test
public void testSetupDriverForClientModeHalError() {
when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
Pair<Integer, IClientInterface> statusAndClientInterface = mWifiNative.setupForClientMode();
assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndClientInterface.first);
assertEquals(null, statusAndClientInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(true));
verify(mWificondControl, never()).setupDriverForClientMode();
}
/**
* Verifies that setupDriverForSoftApMode() calls underlying WificondControl.
*/
@Test
public void testSetupDriverForSoftApMode() {
IApInterface apInterface = mock(IApInterface.class);
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(apInterface);
Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
assertEquals(apInterface, statusAndApInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl).setupDriverForSoftApMode();
}
/**
* Verifies that setupDriverForClientMode() does not call start vendor HAL when it is not
* supported and calls underlying WificondControl setup.
*/
@Test
public void testSetupDriverForSoftApModeWithNoVendorHal() {
when(mWifiVendorHal.isVendorHalSupported()).thenReturn(false);
IApInterface apInterface = mock(IApInterface.class);
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(apInterface);
Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
assertEquals(apInterface, statusAndApInterface.second);
verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
verify(mWificondControl).setupDriverForSoftApMode();
}
/**
* Verifies that setupDriverForSoftApMode() returns null when underlying WificondControl
* call fails.
*/
@Test
public void testSetupDriverForSoftApModeWificondError() {
when(mWificondControl.setupDriverForSoftApMode()).thenReturn(null);
Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndApInterface.first);
assertEquals(null, statusAndApInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl).setupDriverForSoftApMode();
}
/**
* Verifies that setupDriverForSoftApMode() returns null when underlying Hal call fails.
*/
@Test
public void testSetupDriverForSoftApModeHalError() {
when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
Pair<Integer, IApInterface> statusAndApInterface = mWifiNative.setupForSoftApMode();
assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndApInterface.first);
assertEquals(null, statusAndApInterface.second);
verify(mWifiVendorHal).startVendorHal(eq(false));
verify(mWificondControl, never()).setupDriverForSoftApMode();
}
/**
* Verifies that enableSupplicant() calls underlying WificondControl.
*/
@Test
public void testEnableSupplicant() {
when(mWificondControl.enableSupplicant()).thenReturn(true);
mWifiNative.enableSupplicant();
verify(mWificondControl).enableSupplicant();
}
/**
* Verifies that disableSupplicant() calls underlying WificondControl.
*/
@Test
public void testDisableSupplicant() {
when(mWificondControl.disableSupplicant()).thenReturn(true);
mWifiNative.disableSupplicant();
verify(mWificondControl).disableSupplicant();
}
/**
* Verifies that tearDownInterfaces() calls underlying WificondControl and WifiVendorHal
* methods.
*/
@Test
public void testTearDown() {
when(mWificondControl.tearDownInterfaces()).thenReturn(true);
mWifiNative.tearDown();
verify(mWificondControl).tearDownInterfaces();
verify(mWifiVendorHal).stopVendorHal();
}
/**
* Verifies that tearDownInterfaces() calls underlying WificondControl and WifiVendorHal
* methods even if wificond returns an error.
*/
@Test
public void testTearDownWificondError() {
when(mWificondControl.tearDownInterfaces()).thenReturn(false);
mWifiNative.tearDown();
verify(mWificondControl).tearDownInterfaces();
verify(mWifiVendorHal).stopVendorHal();
}
/**
* Verifies that signalPoll() calls underlying WificondControl.
*/
@Test
public void testSignalPoll() throws Exception {
when(mWificondControl.signalPoll()).thenReturn(SIGNAL_POLL_RESULT);
assertEquals(SIGNAL_POLL_RESULT, mWifiNative.signalPoll());
verify(mWificondControl).signalPoll();
}
/**
* Verifies that getTxPacketCounters() calls underlying WificondControl.
*/
@Test
public void testGetTxPacketCounters() throws Exception {
when(mWificondControl.getTxPacketCounters()).thenReturn(PACKET_COUNTERS_RESULT);
assertEquals(PACKET_COUNTERS_RESULT, mWifiNative.getTxPacketCounters());
verify(mWificondControl).getTxPacketCounters();
}
/**
* Verifies that scan() calls underlying WificondControl.
*/
@Test
public void testScan() throws Exception {
mWifiNative.scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET);
verify(mWificondControl).scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET);
}
/**
* Verifies that startPnoscan() calls underlying WificondControl.
*/
@Test
public void testStartPnoScan() throws Exception {
mWifiNative.startPnoScan(TEST_PNO_SETTINGS);
verify(mWificondControl).startPnoScan(TEST_PNO_SETTINGS);
}
/**
* Verifies that stopPnoscan() calls underlying WificondControl.
*/
@Test
public void testStopPnoScan() throws Exception {
mWifiNative.stopPnoScan();
verify(mWificondControl).stopPnoScan();
}
/**
* Verifies that connectToNetwork() calls underlying WificondControl and SupplicantStaIfaceHal.
*/
@Test
public void testConnectToNetwork() throws Exception {
WifiConfiguration config = mock(WifiConfiguration.class);
mWifiNative.connectToNetwork(config);
// connectToNetwork() should abort ongoing scan before connection.
verify(mWificondControl).abortScan();
verify(mStaIfaceHal).connectToNetwork(config);
}
/**
* Verifies that roamToNetwork() calls underlying WificondControl and SupplicantStaIfaceHal.
*/
@Test
public void testRoamToNetwork() throws Exception {
WifiConfiguration config = mock(WifiConfiguration.class);
mWifiNative.roamToNetwork(config);
// roamToNetwork() should abort ongoing scan before connection.
verify(mWificondControl).abortScan();
verify(mStaIfaceHal).roamToNetwork(config);
}
}