diff options
author | Oscar Shu <xshu@google.com> | 2018-10-02 17:22:39 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-02 17:22:39 +0000 |
commit | 666a511081fd80908ab7ce437d35a48a07791df5 (patch) | |
tree | e8f8f17950c0120e11a549108c1d4373791f2219 /tests | |
parent | 1dc689ff02436bdb7649c237cec59eb94a006e8c (diff) | |
parent | 85bd09a1ac7271581330c64be285d139070777c8 (diff) |
Merge "Plumb some fields up from legacy hal"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java | 200 |
1 files changed, 173 insertions, 27 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index c0a9cf252..d5259c710 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -61,6 +61,7 @@ import android.hardware.wifi.V1_0.StaApfPacketFilterCapabilities; import android.hardware.wifi.V1_0.StaBackgroundScanCapabilities; import android.hardware.wifi.V1_0.StaBackgroundScanParameters; import android.hardware.wifi.V1_0.StaLinkLayerIfacePacketStats; +import android.hardware.wifi.V1_0.StaLinkLayerIfaceStats; import android.hardware.wifi.V1_0.StaLinkLayerRadioStats; import android.hardware.wifi.V1_0.StaLinkLayerStats; import android.hardware.wifi.V1_0.StaRoamingCapabilities; @@ -152,6 +153,8 @@ public class WifiVendorHalTest { @Mock private android.hardware.wifi.V1_2.IWifiStaIface mIWifiStaIfaceV12; @Mock + private android.hardware.wifi.V1_3.IWifiStaIface mIWifiStaIfaceV13; + @Mock private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; @@ -185,6 +188,12 @@ public class WifiVendorHalTest { String ifaceName) { return null; } + + @Override + protected android.hardware.wifi.V1_3.IWifiStaIface getWifiStaIfaceForV1_3Mockable( + String ifaceName) { + return null; + } } /** @@ -211,6 +220,44 @@ public class WifiVendorHalTest { String ifaceName) { return mIWifiStaIfaceV12; } + + @Override + protected android.hardware.wifi.V1_3.IWifiStaIface getWifiStaIfaceForV1_3Mockable( + String ifaceName) { + return null; + } + } + + /** + * Spy used to return the V1_2 IWifiChip and V1_3 IWifiStaIface mock objects to simulate + * the 1.3 HAL running on the device. + */ + private class WifiVendorHalSpyV1_3 extends WifiVendorHal { + WifiVendorHalSpyV1_3(HalDeviceManager halDeviceManager, Looper looper) { + super(halDeviceManager, looper); + } + + @Override + protected android.hardware.wifi.V1_1.IWifiChip getWifiChipForV1_1Mockable() { + return null; + } + + @Override + protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { + return mIWifiChipV12; + } + + @Override + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + String ifaceName) { + return mIWifiStaIfaceV12; + } + + @Override + protected android.hardware.wifi.V1_3.IWifiStaIface getWifiStaIfaceForV1_3Mockable( + String ifaceName) { + return mIWifiStaIfaceV13; + } } /** @@ -797,6 +844,16 @@ public class WifiVendorHalTest { } /** + * Test getLinkLayerStats_1_3 gets called when the hal version is V1_3. + */ + @Test + public void testLinkLayerStatsCorrectVersionWithHalV1_3() throws Exception { + mWifiVendorHal = new WifiVendorHalSpyV1_3(mHalDeviceManager, mLooper.getLooper()); + mWifiVendorHal.getWifiLinkLayerStats(TEST_IFACE_NAME); + verify(mIWifiStaIfaceV13).getLinkLayerStats_1_3(any()); + } + + /** * Test that link layer stats are not enabled and harmless in AP mode * * Start the HAL in AP mode @@ -821,11 +878,9 @@ public class WifiVendorHalTest { /** * Test that the link layer stats fields are populated correctly. * - * This is done by filling with random values and then using toString on the - * original and converted values, comparing just the numerics in the result. - * This makes the assumption that the fields are in the same order in both string - * representations, which is not quite true. So apply some fixups before the final - * comparison. + * This is done by filling Hal LinkLayerStats (V1_0) with random values, converting it to + * WifiLinkLayerStats and then asserting the values in the original structure are equal to the + * values in the converted structure. */ @Test public void testLinkLayerStatsAssignment() throws Exception { @@ -836,37 +891,105 @@ public class WifiVendorHalTest { randomizePacketStats(r, stats.iface.wmeViPktStats); randomizePacketStats(r, stats.iface.wmeVoPktStats); randomizeRadioStats(r, stats.radios); - stats.timeStampInMs = r.nextLong() & 0xFFFFFFFFFFL; - String expected = numbersOnly(stats.toString() + " "); - WifiLinkLayerStats converted = WifiVendorHal.frameworkFromHalLinkLayerStats(stats); - String actual = numbersOnly(converted.toString() + " "); - - // Do the required fixups to the both expected and actual - expected = rmValue(expected, stats.radios.get(0).rxTimeInMs); - expected = rmValue(expected, stats.radios.get(0).onTimeInMsForScan); + verifyIFaceStats(stats.iface, converted); + verifyRadioStats(stats.radios, converted); + assertEquals(stats.timeStampInMs, converted.timeStampInMs); + assertEquals(WifiLinkLayerStats.V1_0, converted.version); + } - actual = rmValue(actual, stats.radios.get(0).rxTimeInMs); - actual = rmValue(actual, stats.radios.get(0).onTimeInMsForScan); + /** + * Test that the link layer stats V1_3 fields are populated correctly. + * + * This is done by filling Hal LinkLayerStats (V1_3) with random values, converting it to + * WifiLinkLayerStats and then asserting the values in the original structure are equal to the + * values in the converted structure. + */ + @Test + public void testLinkLayerStatsAssignment_1_3() throws Exception { + Random r = new Random(1775968256); + android.hardware.wifi.V1_3.StaLinkLayerStats stats = + new android.hardware.wifi.V1_3.StaLinkLayerStats(); + randomizePacketStats(r, stats.iface.wmeBePktStats); + randomizePacketStats(r, stats.iface.wmeBkPktStats); + randomizePacketStats(r, stats.iface.wmeViPktStats); + randomizePacketStats(r, stats.iface.wmeVoPktStats); + randomizeRadioStats_1_3(r, stats.radios); + stats.timeStampInMs = r.nextLong() & 0xFFFFFFFFFFL; - // The remaining fields should agree - assertEquals(expected, actual); + WifiLinkLayerStats converted = WifiVendorHal.frameworkFromHalLinkLayerStats_1_3(stats); + + verifyIFaceStats(stats.iface, converted); + verifyRadioStats_1_3(stats.radios, converted); + assertEquals(stats.timeStampInMs, converted.timeStampInMs); + assertEquals(WifiLinkLayerStats.V1_3, converted.version); + } + + private void verifyIFaceStats(StaLinkLayerIfaceStats iface, + WifiLinkLayerStats wifiLinkLayerStats) { + assertEquals(iface.beaconRx, wifiLinkLayerStats.beacon_rx); + assertEquals(iface.avgRssiMgmt, wifiLinkLayerStats.rssi_mgmt); + + assertEquals(iface.wmeBePktStats.rxMpdu, wifiLinkLayerStats.rxmpdu_be); + assertEquals(iface.wmeBePktStats.txMpdu, wifiLinkLayerStats.txmpdu_be); + assertEquals(iface.wmeBePktStats.lostMpdu, wifiLinkLayerStats.lostmpdu_be); + assertEquals(iface.wmeBePktStats.retries, wifiLinkLayerStats.retries_be); + + assertEquals(iface.wmeBkPktStats.rxMpdu, wifiLinkLayerStats.rxmpdu_bk); + assertEquals(iface.wmeBkPktStats.txMpdu, wifiLinkLayerStats.txmpdu_bk); + assertEquals(iface.wmeBkPktStats.lostMpdu, wifiLinkLayerStats.lostmpdu_bk); + assertEquals(iface.wmeBkPktStats.retries, wifiLinkLayerStats.retries_bk); + + assertEquals(iface.wmeViPktStats.rxMpdu, wifiLinkLayerStats.rxmpdu_vi); + assertEquals(iface.wmeViPktStats.txMpdu, wifiLinkLayerStats.txmpdu_vi); + assertEquals(iface.wmeViPktStats.lostMpdu, wifiLinkLayerStats.lostmpdu_vi); + assertEquals(iface.wmeViPktStats.retries, wifiLinkLayerStats.retries_vi); + + assertEquals(iface.wmeVoPktStats.rxMpdu, wifiLinkLayerStats.rxmpdu_vo); + assertEquals(iface.wmeVoPktStats.txMpdu, wifiLinkLayerStats.txmpdu_vo); + assertEquals(iface.wmeVoPktStats.lostMpdu, wifiLinkLayerStats.lostmpdu_vo); + assertEquals(iface.wmeVoPktStats.retries, wifiLinkLayerStats.retries_vo); + } + + private void verifyRadioStats(List<StaLinkLayerRadioStats> radios, + WifiLinkLayerStats wifiLinkLayerStats) { + StaLinkLayerRadioStats radio = radios.get(0); + assertEquals(radio.onTimeInMs, wifiLinkLayerStats.on_time); + assertEquals(radio.txTimeInMs, wifiLinkLayerStats.tx_time); + assertEquals(radio.rxTimeInMs, wifiLinkLayerStats.rx_time); + assertEquals(radio.onTimeInMsForScan, wifiLinkLayerStats.on_time_scan); + assertEquals(radio.txTimeInMsPerLevel.size(), + wifiLinkLayerStats.tx_time_per_level.length); + for (int i = 0; i < radio.txTimeInMsPerLevel.size(); i++) { + assertEquals((int) radio.txTimeInMsPerLevel.get(i), + wifiLinkLayerStats.tx_time_per_level[i]); + } } - /** Just the digits with delimiting spaces, please */ - private static String numbersOnly(String s) { - return s.replaceAll("[^0-9]+", " "); + private void verifyRadioStats_1_3( + List<android.hardware.wifi.V1_3.StaLinkLayerRadioStats> radios, + WifiLinkLayerStats wifiLinkLayerStats) { + android.hardware.wifi.V1_3.StaLinkLayerRadioStats radio = radios.get(0); + assertEquals(radio.V1_0.onTimeInMs, wifiLinkLayerStats.on_time); + assertEquals(radio.V1_0.txTimeInMs, wifiLinkLayerStats.tx_time); + assertEquals(radio.V1_0.rxTimeInMs, wifiLinkLayerStats.rx_time); + assertEquals(radio.V1_0.onTimeInMsForScan, wifiLinkLayerStats.on_time_scan); + assertEquals(radio.V1_0.txTimeInMsPerLevel.size(), + wifiLinkLayerStats.tx_time_per_level.length); + for (int i = 0; i < radio.V1_0.txTimeInMsPerLevel.size(); i++) { + assertEquals((int) radio.V1_0.txTimeInMsPerLevel.get(i), + wifiLinkLayerStats.tx_time_per_level[i]); + } + assertEquals(radio.onTimeInMsForNanScan, wifiLinkLayerStats.on_time_nan_scan); + assertEquals(radio.onTimeInMsForBgScan, wifiLinkLayerStats.on_time_background_scan); + assertEquals(radio.onTimeInMsForRoamScan, wifiLinkLayerStats.on_time_roam_scan); + assertEquals(radio.onTimeInMsForPnoScan, wifiLinkLayerStats.on_time_pno_scan); + assertEquals(radio.onTimeInMsForHs20Scan, wifiLinkLayerStats.on_time_hs20_scan); } - /** Remove the given value from the space-delimited string, or die trying. */ - private static String rmValue(String s, long value) throws Exception { - String ans = s.replaceAll(" " + value + " ", " "); - assertNotEquals(s, ans); - return ans; - } /** * Populate packet stats with non-negative random values @@ -878,7 +1001,7 @@ public class WifiVendorHalTest { pstats.retries = r.nextLong() & 0xFFFFFFFFFFL; } - /** + /** * Populate radio stats with non-negative random values */ private static void randomizeRadioStats(Random r, ArrayList<StaLinkLayerRadioStats> rstats) { @@ -895,6 +1018,29 @@ public class WifiVendorHalTest { } /** + * Populate radio stats with non-negative random values + */ + private static void randomizeRadioStats_1_3(Random r, + ArrayList<android.hardware.wifi.V1_3.StaLinkLayerRadioStats> rstats) { + android.hardware.wifi.V1_3.StaLinkLayerRadioStats rstat = + new android.hardware.wifi.V1_3.StaLinkLayerRadioStats(); + rstat.V1_0.onTimeInMs = r.nextInt() & 0xFFFFFF; + rstat.V1_0.txTimeInMs = r.nextInt() & 0xFFFFFF; + for (int i = 0; i < 4; i++) { + Integer v = r.nextInt() & 0xFFFFFF; + rstat.V1_0.txTimeInMsPerLevel.add(v); + } + rstat.V1_0.rxTimeInMs = r.nextInt() & 0xFFFFFF; + rstat.V1_0.onTimeInMsForScan = r.nextInt() & 0xFFFFFF; + rstat.onTimeInMsForNanScan = r.nextInt() & 0xFFFFFF; + rstat.onTimeInMsForBgScan = r.nextInt() & 0xFFFFFF; + rstat.onTimeInMsForRoamScan = r.nextInt() & 0xFFFFFF; + rstat.onTimeInMsForPnoScan = r.nextInt() & 0xFFFFFF; + rstat.onTimeInMsForHs20Scan = r.nextInt() & 0xFFFFFF; + rstats.add(rstat); + } + + /** * Test that getFirmwareVersion() and getDriverVersion() work * * Calls before the STA is started are expected to return null. |