1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.wifi; 18 19 import static org.junit.Assert.assertArrayEquals; 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertThrows; 22 import static org.junit.Assert.fail; 23 import static org.mockito.Mockito.validateMockitoUsage; 24 25 import android.net.wifi.WifiUsabilityStatsEntry.ContentionTimeStats; 26 import android.net.wifi.WifiUsabilityStatsEntry.RadioStats; 27 import android.net.wifi.WifiUsabilityStatsEntry.RateStats; 28 import android.os.Parcel; 29 import android.util.SparseArray; 30 31 import androidx.test.filters.SmallTest; 32 33 import org.junit.After; 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.mockito.MockitoAnnotations; 37 38 import java.util.NoSuchElementException; 39 40 41 /** 42 * Unit tests for {@link android.net.wifi.WifiUsabilityStatsEntry}. 43 */ 44 @SmallTest 45 public class WifiUsabilityStatsEntryTest { 46 47 /** 48 * Setup before tests. 49 */ 50 @Before setUp()51 public void setUp() throws Exception { 52 MockitoAnnotations.initMocks(this); 53 } 54 55 /** 56 * Clean up after tests. 57 */ 58 @After cleanup()59 public void cleanup() { 60 validateMockitoUsage(); 61 } 62 63 /** 64 * Verify parcel read/write for Wifi usability stats result. 65 */ 66 @Test verifyStatsResultWriteAndThenRead()67 public void verifyStatsResultWriteAndThenRead() throws Exception { 68 WifiUsabilityStatsEntry writeResult = createResult(); 69 WifiUsabilityStatsEntry readResult = parcelWriteRead(writeResult); 70 assertWifiUsabilityStatsEntryEquals(writeResult, readResult); 71 } 72 73 /** 74 * Verify WifiUsabilityStatsEntry#TimeSliceDutyCycleInPercent. 75 */ 76 @Test getTimeSliceDutyCycleInPercent()77 public void getTimeSliceDutyCycleInPercent() throws Exception { 78 ContentionTimeStats[] contentionTimeStats = new ContentionTimeStats[4]; 79 contentionTimeStats[0] = new ContentionTimeStats(1, 2, 3, 4); 80 contentionTimeStats[1] = new ContentionTimeStats(5, 6, 7, 8); 81 contentionTimeStats[2] = new ContentionTimeStats(9, 10, 11, 12); 82 contentionTimeStats[3] = new ContentionTimeStats(13, 14, 15, 16); 83 RateStats[] rateStats = new RateStats[2]; 84 rateStats[0] = new RateStats(1, 3, 4, 7, 9, 11, 13, 15, 17); 85 rateStats[1] = new RateStats(2, 2, 3, 8, 10, 12, 14, 16, 18); 86 87 RadioStats[] radioStats = new RadioStats[2]; 88 radioStats[0] = new RadioStats(0, 10, 11, 12, 13, 14, 15, 16, 17, 18); 89 radioStats[1] = new RadioStats(1, 20, 21, 22, 23, 24, 25, 26, 27, 28); 90 91 SparseArray<WifiUsabilityStatsEntry.LinkStats> linkStats = new SparseArray<>(); 92 linkStats.put(0, new WifiUsabilityStatsEntry.LinkStats(0, 93 WifiUsabilityStatsEntry.LINK_STATE_UNKNOWN, 0, -50, 300, 200, 188, 2, 2, 94 100, 95 300, 100, 100, 200, 96 contentionTimeStats, rateStats)); 97 linkStats.put(1, new WifiUsabilityStatsEntry.LinkStats(1, 98 WifiUsabilityStatsEntry.LINK_STATE_UNKNOWN, 0, -40, 860, 600, 388, 2, 2, 99 200, 100 400, 100, 150, 300, 101 contentionTimeStats, rateStats)); 102 103 WifiUsabilityStatsEntry usabilityStatsEntry = new WifiUsabilityStatsEntry( 104 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 105 32, contentionTimeStats, rateStats, radioStats, 100, true, 106 true, true, 23, 24, 25, true, linkStats); 107 assertEquals(32, usabilityStatsEntry.getTimeSliceDutyCycleInPercent()); 108 109 WifiUsabilityStatsEntry usabilityStatsEntryWithInvalidDutyCycleValue = 110 new WifiUsabilityStatsEntry( 111 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 112 21, 22, -1, contentionTimeStats, rateStats, radioStats, 101, true, true, 113 true, 23, 24, 25, true, linkStats); 114 try { 115 usabilityStatsEntryWithInvalidDutyCycleValue.getTimeSliceDutyCycleInPercent(); 116 fail(); 117 } catch (NoSuchElementException e) { 118 // pass 119 } 120 } 121 122 /** 123 * Write the provided {@link WifiUsabilityStatsEntry} to a parcel and deserialize it. 124 */ parcelWriteRead( WifiUsabilityStatsEntry writeResult)125 private static WifiUsabilityStatsEntry parcelWriteRead( 126 WifiUsabilityStatsEntry writeResult) throws Exception { 127 Parcel parcel = Parcel.obtain(); 128 writeResult.writeToParcel(parcel, 0); 129 parcel.setDataPosition(0); // Rewind data position back to the beginning for read. 130 return WifiUsabilityStatsEntry.CREATOR.createFromParcel(parcel); 131 } 132 createResult()133 private static WifiUsabilityStatsEntry createResult() { 134 ContentionTimeStats[] contentionTimeStats = new ContentionTimeStats[4]; 135 contentionTimeStats[0] = new ContentionTimeStats(1, 2, 3, 4); 136 contentionTimeStats[1] = new ContentionTimeStats(5, 6, 7, 8); 137 contentionTimeStats[2] = new ContentionTimeStats(9, 10, 11, 12); 138 contentionTimeStats[3] = new ContentionTimeStats(13, 14, 15, 16); 139 RateStats[] rateStats = new RateStats[2]; 140 rateStats[0] = new RateStats(1, 3, 4, 7, 9, 11, 13, 15, 17); 141 rateStats[1] = new RateStats(2, 2, 3, 8, 10, 12, 14, 16, 18); 142 143 RadioStats[] radioStats = new RadioStats[2]; 144 radioStats[0] = new RadioStats(0, 10, 11, 12, 13, 14, 15, 16, 17, 18); 145 radioStats[1] = new RadioStats(1, 20, 21, 22, 23, 24, 25, 26, 27, 28); 146 SparseArray<WifiUsabilityStatsEntry.LinkStats> linkStats = new SparseArray<>(); 147 linkStats.put(0, new WifiUsabilityStatsEntry.LinkStats(3, 148 WifiUsabilityStatsEntry.LINK_STATE_IN_USE, 0, -50, 300, 200, 188, 2, 2, 100, 149 300, 100, 100, 200, 150 contentionTimeStats, rateStats)); 151 linkStats.put(1, new WifiUsabilityStatsEntry.LinkStats(8, 152 WifiUsabilityStatsEntry.LINK_STATE_IN_USE, 0, -40, 860, 600, 388, 2, 2, 200, 153 400, 100, 150, 300, 154 contentionTimeStats, rateStats)); 155 156 return new WifiUsabilityStatsEntry( 157 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 158 50, contentionTimeStats, rateStats, radioStats, 102, true, 159 true, true, 23, 24, 25, true, linkStats 160 ); 161 } 162 assertWifiUsabilityStatsEntryEquals( WifiUsabilityStatsEntry expected, WifiUsabilityStatsEntry actual)163 private static void assertWifiUsabilityStatsEntryEquals( 164 WifiUsabilityStatsEntry expected, 165 WifiUsabilityStatsEntry actual) { 166 assertEquals(expected.getTimeStampMillis(), actual.getTimeStampMillis()); 167 assertEquals(expected.getRssi(), actual.getRssi()); 168 assertEquals(expected.getLinkSpeedMbps(), actual.getLinkSpeedMbps()); 169 assertEquals(expected.getTotalTxSuccess(), actual.getTotalTxSuccess()); 170 assertEquals(expected.getTotalTxRetries(), actual.getTotalTxRetries()); 171 assertEquals(expected.getTotalTxBad(), actual.getTotalTxBad()); 172 assertEquals(expected.getTotalRxSuccess(), actual.getTotalRxSuccess()); 173 assertEquals(expected.getTotalCcaBusyFreqTimeMillis(), 174 actual.getTotalCcaBusyFreqTimeMillis()); 175 assertEquals(expected.getTotalRadioOnFreqTimeMillis(), 176 actual.getTotalRadioOnFreqTimeMillis()); 177 assertEquals(expected.getWifiLinkLayerRadioStats().size(), 178 actual.getWifiLinkLayerRadioStats().size()); 179 for (int i = 0; i < expected.getWifiLinkLayerRadioStats().size(); i++) { 180 RadioStats expectedRadioStats = expected.getWifiLinkLayerRadioStats().get(i); 181 RadioStats actualRadioStats = actual.getWifiLinkLayerRadioStats().get(i); 182 assertEquals(expectedRadioStats.getRadioId(), 183 actualRadioStats.getRadioId()); 184 assertEquals(expectedRadioStats.getTotalRadioOnTimeMillis(), 185 actualRadioStats.getTotalRadioOnTimeMillis()); 186 assertEquals(expectedRadioStats.getTotalRadioTxTimeMillis(), 187 actualRadioStats.getTotalRadioTxTimeMillis()); 188 assertEquals(expectedRadioStats.getTotalRadioRxTimeMillis(), 189 actualRadioStats.getTotalRadioRxTimeMillis()); 190 assertEquals(expectedRadioStats.getTotalScanTimeMillis(), 191 actualRadioStats.getTotalScanTimeMillis()); 192 assertEquals(expectedRadioStats.getTotalNanScanTimeMillis(), 193 actualRadioStats.getTotalNanScanTimeMillis()); 194 assertEquals(expectedRadioStats.getTotalBackgroundScanTimeMillis(), 195 actualRadioStats.getTotalBackgroundScanTimeMillis()); 196 assertEquals(expectedRadioStats.getTotalRoamScanTimeMillis(), 197 actualRadioStats.getTotalRoamScanTimeMillis()); 198 assertEquals(expectedRadioStats.getTotalPnoScanTimeMillis(), 199 actualRadioStats.getTotalPnoScanTimeMillis()); 200 assertEquals(expectedRadioStats.getTotalHotspot2ScanTimeMillis(), 201 actualRadioStats.getTotalHotspot2ScanTimeMillis()); 202 } 203 assertEquals(expected.getTotalRadioOnTimeMillis(), actual.getTotalRadioOnTimeMillis()); 204 assertEquals(expected.getTotalRadioTxTimeMillis(), actual.getTotalRadioTxTimeMillis()); 205 assertEquals(expected.getTotalRadioRxTimeMillis(), actual.getTotalRadioRxTimeMillis()); 206 assertEquals(expected.getTotalScanTimeMillis(), actual.getTotalScanTimeMillis()); 207 assertEquals(expected.getTotalNanScanTimeMillis(), actual.getTotalNanScanTimeMillis()); 208 assertEquals(expected.getTotalBackgroundScanTimeMillis(), 209 actual.getTotalBackgroundScanTimeMillis()); 210 assertEquals(expected.getTotalRoamScanTimeMillis(), actual.getTotalRoamScanTimeMillis()); 211 assertEquals(expected.getTotalPnoScanTimeMillis(), actual.getTotalPnoScanTimeMillis()); 212 assertEquals(expected.getTotalHotspot2ScanTimeMillis(), 213 actual.getTotalHotspot2ScanTimeMillis()); 214 assertEquals(expected.getTotalCcaBusyFreqTimeMillis(), 215 actual.getTotalCcaBusyFreqTimeMillis()); 216 assertEquals(expected.getTotalRadioOnFreqTimeMillis(), 217 actual.getTotalRadioOnFreqTimeMillis()); 218 assertEquals(expected.getTotalBeaconRx(), actual.getTotalBeaconRx()); 219 assertEquals(expected.getProbeStatusSinceLastUpdate(), 220 actual.getProbeStatusSinceLastUpdate()); 221 assertEquals(expected.getProbeElapsedTimeSinceLastUpdateMillis(), 222 actual.getProbeElapsedTimeSinceLastUpdateMillis()); 223 assertEquals(expected.getProbeMcsRateSinceLastUpdate(), 224 actual.getProbeMcsRateSinceLastUpdate()); 225 assertEquals(expected.getRxLinkSpeedMbps(), actual.getRxLinkSpeedMbps()); 226 assertEquals(expected.getTimeSliceDutyCycleInPercent(), 227 actual.getTimeSliceDutyCycleInPercent()); 228 assertEquals( 229 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 230 .getContentionTimeMinMicros(), 231 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 232 .getContentionTimeMinMicros()); 233 assertEquals( 234 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 235 .getContentionTimeMaxMicros(), 236 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 237 .getContentionTimeMaxMicros()); 238 assertEquals( 239 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 240 .getContentionTimeAvgMicros(), 241 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 242 .getContentionTimeAvgMicros()); 243 assertEquals( 244 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 245 .getContentionNumSamples(), 246 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 247 .getContentionNumSamples()); 248 assertEquals( 249 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 250 .getContentionTimeMinMicros(), 251 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 252 .getContentionTimeMinMicros()); 253 assertEquals( 254 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 255 .getContentionTimeMaxMicros(), 256 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 257 .getContentionTimeMaxMicros()); 258 assertEquals( 259 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 260 .getContentionTimeAvgMicros(), 261 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 262 .getContentionTimeAvgMicros()); 263 assertEquals( 264 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 265 .getContentionNumSamples(), 266 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 267 .getContentionNumSamples()); 268 assertEquals( 269 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 270 .getContentionTimeMinMicros(), 271 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 272 .getContentionTimeMinMicros()); 273 assertEquals( 274 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 275 .getContentionTimeMaxMicros(), 276 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 277 .getContentionTimeMaxMicros()); 278 assertEquals( 279 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 280 .getContentionTimeAvgMicros(), 281 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 282 .getContentionTimeAvgMicros()); 283 assertEquals( 284 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 285 .getContentionNumSamples(), 286 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 287 .getContentionNumSamples()); 288 assertEquals( 289 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 290 .getContentionTimeMinMicros(), 291 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 292 .getContentionTimeMinMicros()); 293 assertEquals( 294 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 295 .getContentionTimeMaxMicros(), 296 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 297 .getContentionTimeMaxMicros()); 298 assertEquals( 299 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 300 .getContentionTimeAvgMicros(), 301 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 302 .getContentionTimeAvgMicros()); 303 assertEquals( 304 expected.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 305 .getContentionNumSamples(), 306 actual.getContentionTimeStats(WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 307 .getContentionNumSamples()); 308 for (int i = 0; i < expected.getRateStats().size(); i++) { 309 RateStats expectedStats = expected.getRateStats().get(i); 310 RateStats actualStats = actual.getRateStats().get(i); 311 assertEquals(expectedStats.getPreamble(), actualStats.getPreamble()); 312 assertEquals(expectedStats.getNumberOfSpatialStreams(), 313 actualStats.getNumberOfSpatialStreams()); 314 assertEquals(expectedStats.getBandwidthInMhz(), actualStats.getBandwidthInMhz()); 315 assertEquals(expectedStats.getRateMcsIdx(), actualStats.getRateMcsIdx()); 316 assertEquals(expectedStats.getBitRateInKbps(), actualStats.getBitRateInKbps()); 317 assertEquals(expectedStats.getTxMpdu(), actualStats.getTxMpdu()); 318 assertEquals(expectedStats.getRxMpdu(), actualStats.getRxMpdu()); 319 assertEquals(expectedStats.getMpduLost(), actualStats.getMpduLost()); 320 assertEquals(expectedStats.getRetries(), actualStats.getRetries()); 321 } 322 assertEquals(expected.getChannelUtilizationRatio(), actual.getChannelUtilizationRatio()); 323 assertEquals(expected.isThroughputSufficient(), actual.isThroughputSufficient()); 324 assertEquals(expected.isWifiScoringEnabled(), actual.isWifiScoringEnabled()); 325 assertEquals(expected.isCellularDataAvailable(), actual.isCellularDataAvailable()); 326 assertEquals(expected.getCellularDataNetworkType(), actual.getCellularDataNetworkType()); 327 assertEquals(expected.getCellularSignalStrengthDbm(), 328 actual.getCellularSignalStrengthDbm()); 329 assertEquals(expected.getCellularSignalStrengthDb(), actual.getCellularSignalStrengthDb()); 330 assertEquals(expected.isSameRegisteredCell(), actual.isSameRegisteredCell()); 331 332 // validate link specific stats 333 assertArrayEquals(expected.getLinkIds(), actual.getLinkIds()); 334 int[] links = actual.getLinkIds(); 335 if (links != null) { 336 for (int link : links) { 337 assertEquals(expected.getRssi(link), actual.getRssi(link)); 338 assertEquals(expected.getRadioId(link), actual.getRadioId(link)); 339 assertEquals(expected.getTxLinkSpeedMbps(link), 340 actual.getTxLinkSpeedMbps(link)); 341 assertEquals(expected.getRxLinkSpeedMbps(link), 342 actual.getRxLinkSpeedMbps(link)); 343 assertEquals(expected.getTotalBeaconRx(link), 344 actual.getTotalBeaconRx(link)); 345 assertEquals(expected.getTimeSliceDutyCycleInPercent(link), 346 actual.getTimeSliceDutyCycleInPercent(link)); 347 assertEquals(expected.getTotalRxSuccess(link), 348 actual.getTotalRxSuccess(link)); 349 assertEquals(expected.getTotalTxSuccess(link), 350 actual.getTotalTxSuccess(link)); 351 assertEquals(expected.getTotalTxBad(link), actual.getTotalTxBad(link)); 352 assertEquals(expected.getTotalTxRetries(link), 353 actual.getTotalTxRetries(link)); 354 assertEquals(expected.getTotalCcaBusyFreqTimeMillis(link), 355 actual.getTotalCcaBusyFreqTimeMillis(link)); 356 assertEquals(expected.getTotalRadioOnFreqTimeMillis(link), 357 actual.getTotalRadioOnFreqTimeMillis(link)); 358 assertEquals( 359 expected.getContentionTimeStats(link, 360 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 361 .getContentionTimeMinMicros(), 362 actual.getContentionTimeStats(link, 363 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 364 .getContentionTimeMinMicros()); 365 assertEquals( 366 expected.getContentionTimeStats(link, 367 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 368 .getContentionTimeMaxMicros(), 369 actual.getContentionTimeStats(link, 370 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 371 .getContentionTimeMaxMicros()); 372 assertEquals( 373 expected.getContentionTimeStats(link, 374 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 375 .getContentionTimeAvgMicros(), 376 actual.getContentionTimeStats(link, 377 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 378 .getContentionTimeAvgMicros()); 379 assertEquals( 380 expected.getContentionTimeStats(link, 381 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 382 .getContentionNumSamples(), 383 actual.getContentionTimeStats(link, 384 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE) 385 .getContentionNumSamples()); 386 assertEquals( 387 expected.getContentionTimeStats(link, 388 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 389 .getContentionTimeMinMicros(), 390 actual.getContentionTimeStats(link, 391 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 392 .getContentionTimeMinMicros()); 393 assertEquals( 394 expected.getContentionTimeStats(link, 395 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 396 .getContentionTimeMaxMicros(), 397 actual.getContentionTimeStats(link, 398 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 399 .getContentionTimeMaxMicros()); 400 assertEquals( 401 expected.getContentionTimeStats(link, 402 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 403 .getContentionTimeAvgMicros(), 404 actual.getContentionTimeStats(link, 405 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 406 .getContentionTimeAvgMicros()); 407 assertEquals( 408 expected.getContentionTimeStats(link, 409 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 410 .getContentionNumSamples(), 411 actual.getContentionTimeStats(link, 412 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BK) 413 .getContentionNumSamples()); 414 assertEquals( 415 expected.getContentionTimeStats(link, 416 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 417 .getContentionTimeMinMicros(), 418 actual.getContentionTimeStats(link, 419 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 420 .getContentionTimeMinMicros()); 421 assertEquals( 422 expected.getContentionTimeStats(link, 423 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 424 .getContentionTimeMaxMicros(), 425 actual.getContentionTimeStats(link, 426 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 427 .getContentionTimeMaxMicros()); 428 assertEquals( 429 expected.getContentionTimeStats(link, 430 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 431 .getContentionTimeAvgMicros(), 432 actual.getContentionTimeStats(link, 433 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 434 .getContentionTimeAvgMicros()); 435 assertEquals( 436 expected.getContentionTimeStats(link, 437 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 438 .getContentionNumSamples(), 439 actual.getContentionTimeStats(link, 440 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VI) 441 .getContentionNumSamples()); 442 assertEquals( 443 expected.getContentionTimeStats(link, 444 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 445 .getContentionTimeMinMicros(), 446 actual.getContentionTimeStats(link, 447 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 448 .getContentionTimeMinMicros()); 449 assertEquals( 450 expected.getContentionTimeStats(link, 451 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 452 .getContentionTimeMaxMicros(), 453 actual.getContentionTimeStats(link, 454 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 455 .getContentionTimeMaxMicros()); 456 assertEquals( 457 expected.getContentionTimeStats(link, 458 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 459 .getContentionTimeAvgMicros(), 460 actual.getContentionTimeStats(link, 461 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 462 .getContentionTimeAvgMicros()); 463 assertEquals( 464 expected.getContentionTimeStats(link, 465 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 466 .getContentionNumSamples(), 467 actual.getContentionTimeStats(link, 468 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_VO) 469 .getContentionNumSamples()); 470 471 for (int j = 0; j < expected.getRateStats(link).size(); j++) { 472 RateStats expectedStats = expected.getRateStats(link).get(j); 473 RateStats actualStats = actual.getRateStats(link).get(j); 474 assertEquals(expectedStats.getPreamble(), actualStats.getPreamble()); 475 assertEquals(expectedStats.getNumberOfSpatialStreams(), 476 actualStats.getNumberOfSpatialStreams()); 477 assertEquals(expectedStats.getBandwidthInMhz(), 478 actualStats.getBandwidthInMhz()); 479 assertEquals(expectedStats.getRateMcsIdx(), actualStats.getRateMcsIdx()); 480 assertEquals(expectedStats.getBitRateInKbps(), actualStats.getBitRateInKbps()); 481 assertEquals(expectedStats.getTxMpdu(), actualStats.getTxMpdu()); 482 assertEquals(expectedStats.getRxMpdu(), actualStats.getRxMpdu()); 483 assertEquals(expectedStats.getMpduLost(), actualStats.getMpduLost()); 484 assertEquals(expectedStats.getRetries(), actualStats.getRetries()); 485 } 486 487 } 488 } 489 } 490 491 /** 492 * Verify invalid linkId for WifiUsabilityStatsEntry.getXX(linkId) API's. 493 */ 494 @Test verifyInvalidLinkIdForGetApis()495 public void verifyInvalidLinkIdForGetApis() throws Exception { 496 497 SparseArray<WifiUsabilityStatsEntry.LinkStats> linkStats = new SparseArray<>(); 498 linkStats.put(0, new WifiUsabilityStatsEntry.LinkStats(0, 499 WifiUsabilityStatsEntry.LINK_STATE_IN_USE, 0, -50, 300, 200, 188, 2, 2, 100, 500 300, 100, 100, 200, 501 null, null)); 502 503 WifiUsabilityStatsEntry usabilityStatsEntry = new WifiUsabilityStatsEntry( 504 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 505 32, null, null, null, 100, true, 506 true, true, 23, 24, 25, true, linkStats); 507 508 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 509 NoSuchElementException.class, 510 () -> usabilityStatsEntry.getLinkState(MloLink.INVALID_MLO_LINK_ID)); 511 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 512 NoSuchElementException.class, 513 () -> usabilityStatsEntry.getRssi(MloLink.INVALID_MLO_LINK_ID)); 514 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 515 NoSuchElementException.class, 516 () -> usabilityStatsEntry.getTxLinkSpeedMbps(MloLink.INVALID_MLO_LINK_ID)); 517 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 518 NoSuchElementException.class, 519 () -> usabilityStatsEntry.getContentionTimeStats(MloLink.INVALID_MLO_LINK_ID, 520 WifiUsabilityStatsEntry.WME_ACCESS_CATEGORY_BE)); 521 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 522 NoSuchElementException.class, 523 () -> usabilityStatsEntry.getRateStats(MloLink.INVALID_MLO_LINK_ID)); 524 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 525 NoSuchElementException.class, 526 () -> usabilityStatsEntry.getRadioId(MloLink.INVALID_MLO_LINK_ID)); 527 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 528 NoSuchElementException.class, 529 () -> usabilityStatsEntry.getRxLinkSpeedMbps(MloLink.INVALID_MLO_LINK_ID)); 530 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 531 NoSuchElementException.class, 532 () -> usabilityStatsEntry.getTotalTxBad(MloLink.INVALID_MLO_LINK_ID)); 533 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 534 NoSuchElementException.class, 535 () -> usabilityStatsEntry.getTotalBeaconRx(MloLink.INVALID_MLO_LINK_ID)); 536 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 537 NoSuchElementException.class, 538 () -> usabilityStatsEntry.getTotalRxSuccess(MloLink.INVALID_MLO_LINK_ID)); 539 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 540 NoSuchElementException.class, 541 () -> usabilityStatsEntry.getTotalTxSuccess(MloLink.INVALID_MLO_LINK_ID)); 542 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 543 NoSuchElementException.class, 544 () -> usabilityStatsEntry.getTotalTxRetries(MloLink.INVALID_MLO_LINK_ID)); 545 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 546 NoSuchElementException.class, 547 () -> usabilityStatsEntry.getTimeSliceDutyCycleInPercent( 548 MloLink.INVALID_MLO_LINK_ID)); 549 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 550 NoSuchElementException.class, 551 () -> usabilityStatsEntry.getTotalCcaBusyFreqTimeMillis( 552 MloLink.INVALID_MLO_LINK_ID)); 553 assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, 554 NoSuchElementException.class, 555 () -> usabilityStatsEntry.getTotalRadioOnFreqTimeMillis( 556 MloLink.INVALID_MLO_LINK_ID)); 557 } 558 } 559