diff options
author | Nate(Qiang) Jiang <qiangjiang@google.com> | 2019-10-17 09:42:56 -0700 |
---|---|---|
committer | Nate(Qiang) Jiang <qiangjiang@google.com> | 2019-11-04 13:53:33 -0800 |
commit | 457bca47b5a8c6716744a58d1a3a189e711719f1 (patch) | |
tree | 3ce082d9fa0e85d0024a3320fac718cc307126d4 /tests | |
parent | 2b0d1a8a196d428bac014eb296f6230bfc9f3ccd (diff) |
clean up WifiRtt service dependency require under HIDL
Bug: 142898735
Test: atest android.net.wifi
Test: atest com.android.server.wifi
Change-Id: I44e10d2834c3925d88c6efcf4fd12c5850f7d281
Diffstat (limited to 'tests')
4 files changed, 150 insertions, 157 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttMetricsTest.java index 891fb4003..9dfd6586d 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttMetricsTest.java @@ -19,10 +19,9 @@ package com.android.server.wifi.rtt; import static org.hamcrest.core.IsEqual.equalTo; import static org.mockito.Mockito.when; -import android.hardware.wifi.V1_0.RttResult; -import android.hardware.wifi.V1_0.RttStatus; import android.net.MacAddress; import android.net.wifi.rtt.RangingRequest; +import android.net.wifi.rtt.RangingResult; import android.net.wifi.rtt.ResponderConfig; import android.os.WorkSource; import android.util.Log; @@ -217,10 +216,14 @@ public class RttMetricsTest extends WifiBaseTest { RangingRequest requestAp6 = getDummyRangingRequest(6, 0); mDut.clear(); - mDut.recordResult(requestAp1, getDummyRangingResults(requestAp1, 5, 0)); - mDut.recordResult(requestAp2, getDummyRangingResults(requestAp2, 10, 30)); - mDut.recordResult(requestAp5, getDummyRangingResults(requestAp5, 0.3, -0.2)); - mDut.recordResult(requestAp6, getDummyRangingResults(requestAp6, 40, 30)); + mDut.recordResult(requestAp1, getDummyRangingResults(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, + requestAp1, 5, 0)); + mDut.recordResult(requestAp2, getDummyRangingResults(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, + requestAp2, 10, 30)); + mDut.recordResult(requestAp5, getDummyRangingResults(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, + requestAp5, 0.3, -0.2)); + mDut.recordResult(requestAp6, getDummyRangingResults(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, + requestAp6, 40, 30)); log = mDut.consolidateProto(); checkMainStats("Sequence AP-only", log, 0, 0); @@ -253,10 +256,14 @@ public class RttMetricsTest extends WifiBaseTest { RangingRequest requestMixed08 = getDummyRangingRequest(0, 8); mDut.clear(); - mDut.recordResult(requestMixed03, getDummyRangingResults(requestMixed03, 5, 0)); - mDut.recordResult(requestMixed25, getDummyRangingResults(requestMixed25, 10, 30)); - mDut.recordResult(requestMixed50, getDummyRangingResults(requestMixed50, 0.3, -0.2)); - mDut.recordResult(requestMixed08, getDummyRangingResults(requestMixed08, 40, 30)); + mDut.recordResult(requestMixed03, getDummyRangingResults( + RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, requestMixed03, 5, 0)); + mDut.recordResult(requestMixed25, getDummyRangingResults( + RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, requestMixed25, 10, 30)); + mDut.recordResult(requestMixed50, getDummyRangingResults( + RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, requestMixed50, 0.3, -0.2)); + mDut.recordResult(requestMixed08, getDummyRangingResults( + RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, requestMixed08, 40, 30)); log = mDut.consolidateProto(); checkMainStats("Sequence Mixed AP/Aware", log, 0, 0); @@ -302,7 +309,8 @@ public class RttMetricsTest extends WifiBaseTest { mDut.clear(); RangingRequest requestMixed25 = getDummyRangingRequest(2, 5); - List<RttResult> resultMixed25 = getDummyRangingResults(requestMixed25, 10, 30); + List<RangingResult> resultMixed25 = getDummyRangingResults( + RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, requestMixed25, 10, 30); // remove some results resultMixed25.remove(3); // Second Aware result: distance = 100 resultMixed25.remove(0); // First AP result: distance = 10 @@ -382,22 +390,22 @@ public class RttMetricsTest extends WifiBaseTest { mDut.clear(); - recordResultNTimes(RttStatus.SUCCESS, 5); - recordResultNTimes(RttStatus.FAILURE, 6); - recordResultNTimes(RttStatus.FAIL_NO_RSP, 7); - recordResultNTimes(RttStatus.FAIL_REJECTED, 8); - recordResultNTimes(RttStatus.FAIL_NOT_SCHEDULED_YET, 9); - recordResultNTimes(RttStatus.FAIL_TM_TIMEOUT, 10); - recordResultNTimes(RttStatus.FAIL_AP_ON_DIFF_CHANNEL, 11); - recordResultNTimes(RttStatus.FAIL_NO_CAPABILITY, 12); - recordResultNTimes(RttStatus.ABORTED, 13); - recordResultNTimes(RttStatus.FAIL_INVALID_TS, 14); - recordResultNTimes(RttStatus.FAIL_PROTOCOL, 15); - recordResultNTimes(RttStatus.FAIL_SCHEDULE, 16); - recordResultNTimes(RttStatus.FAIL_BUSY_TRY_LATER, 17); - recordResultNTimes(RttStatus.INVALID_REQ, 18); - recordResultNTimes(RttStatus.NO_WIFI, 19); - recordResultNTimes(RttStatus.FAIL_FTM_PARAM_OVERRIDE, 20); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS, 5); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAILURE, 6); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_NO_RSP, 7); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_REJECTED, 8); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_NOT_SCHEDULED_YET, 9); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_TM_TIMEOUT, 10); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL, 11); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_NO_CAPABILITY, 12); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_ABORTED, 13); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_INVALID_TS, 14); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_PROTOCOL, 15); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_SCHEDULE, 16); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_BUSY_TRY_LATER, 17); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_INVALID_REQ, 18); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_NO_WIFI, 19); + recordResultNTimes(RttNative.FRAMEWORK_RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE, 20); log = mDut.consolidateProto(); @@ -576,28 +584,25 @@ public class RttMetricsTest extends WifiBaseTest { return builder.build(); } - private List<RttResult> getDummyRangingResults(RangingRequest request, double baseDistanceM, - double incrDistanceM) { - List<RttResult> halResults = new ArrayList<>(); + private List<RangingResult> getDummyRangingResults(int status, RangingRequest request, + double baseDistanceM, double incrDistanceM) { + List<RangingResult> rangingResults = new ArrayList<>(); double distance = baseDistanceM; for (ResponderConfig peer : request.mRttPeers) { - RttResult rttResult = new RttResult(); - rttResult.status = RttStatus.SUCCESS; - System.arraycopy(peer.macAddress.toByteArray(), 0, rttResult.addr, 0, 6); - rttResult.distanceInMm = (int) (distance * 1000); + + RangingResult rttResult = new RangingResult(status, peer.macAddress, + (int) (distance * 1000), 0, 0, 8, 8, null, null, null, 0); distance += incrDistanceM; - halResults.add(rttResult); + rangingResults.add(rttResult); } - return halResults; + return rangingResults; } private void recordResultNTimes(int status, int n) { RangingRequest request = getDummyRangingRequest(1, 0); - List<RttResult> results = getDummyRangingResults(request, 0, 0); - RttResult result = results.get(0); - result.status = status; + List<RangingResult> results = getDummyRangingResults(status, request, 0, 0); for (int i = 0; i < n; ++i) { mDut.recordResult(request, results); diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java index f6562fae7..036e4d070 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java @@ -18,6 +18,7 @@ package com.android.server.wifi.rtt; import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -29,6 +30,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.hardware.wifi.V1_0.IWifiRttController; +import android.hardware.wifi.V1_0.IWifiRttControllerEventCallback; import android.hardware.wifi.V1_0.RttBw; import android.hardware.wifi.V1_0.RttCapabilities; import android.hardware.wifi.V1_0.RttConfig; @@ -42,6 +44,7 @@ import android.hardware.wifi.V1_0.WifiStatus; import android.hardware.wifi.V1_0.WifiStatusCode; import android.net.MacAddress; import android.net.wifi.rtt.RangingRequest; +import android.net.wifi.rtt.RangingResult; import androidx.test.filters.SmallTest; @@ -77,6 +80,8 @@ public class RttNativeTest extends WifiBaseTest { HalDeviceManager.InterfaceRttControllerLifecycleCallback.class); private ArgumentCaptor<IWifiRttController.getCapabilitiesCallback> mGetCapCbCatpr = ArgumentCaptor.forClass(IWifiRttController.getCapabilitiesCallback.class); + private ArgumentCaptor<IWifiRttControllerEventCallback.Stub> mEventCallbackArgumentCaptor = + ArgumentCaptor.forClass(IWifiRttControllerEventCallback.Stub.class); @Rule public ErrorCollector collector = new ErrorCollector(); @@ -98,7 +103,8 @@ public class RttNativeTest extends WifiBaseTest { mStatusSuccess = new WifiStatus(); mStatusSuccess.code = WifiStatusCode.SUCCESS; - when(mockRttController.registerEventCallback(any())).thenReturn(mStatusSuccess); + when(mockRttController.registerEventCallback(mEventCallbackArgumentCaptor.capture())) + .thenReturn(mStatusSuccess); when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn( mStatusSuccess); when(mockRttController.rangeCancel(anyInt(), any(ArrayList.class))).thenReturn( @@ -239,7 +245,7 @@ public class RttNativeTest extends WifiBaseTest { // verify contents of HAL request (hard codes knowledge from getDummyRangingRequest()). ArrayList<RttConfig> halRequest = mRttConfigCaptor.getValue(); - collector.checkThat("number of entries", halRequest.size(), equalTo(2)); + assertEquals("number of entries", halRequest.size(), 2); RttConfig rttConfig = halRequest.get(0); collector.checkThat("entry 0: MAC", rttConfig.addr, @@ -403,27 +409,27 @@ public class RttNativeTest extends WifiBaseTest { res.addr[5] = 10; res.status = RttStatus.SUCCESS; res.distanceInMm = 1500; - res.timeStampInUs = 666; + res.timeStampInUs = 6000; results.add(res); // (1) have HAL call native with results - mDut.onResults(cmdId, results); + mEventCallbackArgumentCaptor.getValue().onResults(cmdId, results); // (2) verify call to framework verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture()); // verify contents of the framework results - List<RttResult> rttR = mRttResultCaptor.getValue(); + List<RangingResult> rttR = mRttResultCaptor.getValue(); collector.checkThat("number of entries", rttR.size(), equalTo(1)); - RttResult rttResult = rttR.get(0); - collector.checkThat("status", rttResult.status, - equalTo(RttStatus.SUCCESS)); - collector.checkThat("mac", rttResult.addr, + RangingResult rttResult = rttR.get(0); + collector.checkThat("status", rttResult.getStatus(), + equalTo(RttNative.FRAMEWORK_RTT_STATUS_SUCCESS)); + collector.checkThat("mac", rttResult.getMacAddress().toByteArray(), equalTo(MacAddress.fromString("05:06:07:08:09:0A").toByteArray())); - collector.checkThat("distanceCm", rttResult.distanceInMm, equalTo(1500)); - collector.checkThat("timestamp", rttResult.timeStampInUs, equalTo(666L)); + collector.checkThat("distanceCm", rttResult.getDistanceMm(), equalTo(1500)); + collector.checkThat("timestamp", rttResult.getRangingTimestampMillis(), equalTo(6L)); verifyNoMoreInteractions(mockRttController, mockRttServiceImpl); } @@ -432,10 +438,10 @@ public class RttNativeTest extends WifiBaseTest { * Validate correct cleanup when a null array of results is provided by HAL. */ @Test - public void testRangeResultsNullArray() { + public void testRangeResultsNullArray() throws Exception { int cmdId = 66; - mDut.onResults(cmdId, null); + mEventCallbackArgumentCaptor.getValue().onResults(cmdId, null); verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture()); collector.checkThat("number of entries", mRttResultCaptor.getValue().size(), equalTo(0)); @@ -445,7 +451,7 @@ public class RttNativeTest extends WifiBaseTest { * Validate correct cleanup when an array of results containing null entries is provided by HAL. */ @Test - public void testRangeResultsSomeNulls() { + public void testRangeResultsSomeNulls() throws Exception { int cmdId = 77; ArrayList<RttResult> results = new ArrayList<>(); @@ -456,7 +462,7 @@ public class RttNativeTest extends WifiBaseTest { results.add(new RttResult()); results.add(null); - mDut.onResults(cmdId, results); + mEventCallbackArgumentCaptor.getValue().onResults(cmdId, results); verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture()); List<RttResult> rttR = mRttResultCaptor.getValue(); diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java index 1156aa863..7f456482b 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java @@ -48,7 +48,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; -import android.hardware.wifi.V1_0.RttResult; import android.location.LocationManager; import android.net.MacAddress; import android.net.wifi.aware.IWifiAwareMacAddressProvider; @@ -253,7 +252,7 @@ public class RttServiceImplTest extends WifiBaseTest { public void testRangingFlow() throws Exception { int numIter = 10; RangingRequest[] requests = new RangingRequest[numIter]; - List<Pair<List<RttResult>, List<RangingResult>>> results = new ArrayList<>(); + List<Pair<List<RangingResult>, List<RangingResult>>> results = new ArrayList<>(); for (int i = 0; i < numIter; ++i) { // even: MC, non-MC, Aware, odd: MC only if (i % 2 == 0) { @@ -276,7 +275,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(i % 2 != 0, 0); // (3) native calls back with result - mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).first); + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).second); mMockLooper.dispatchAll(); // (4) verify that results dispatched @@ -284,14 +283,14 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupCancelled(); // (5) replicate results - shouldn't dispatch another callback - mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).first); + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).second); mMockLooper.dispatchAll(); } // verify metrics for (int i = 0; i < numIter; ++i) { verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(requests[i])); - verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).first)); + verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).second)); } verify(mockMetrics, times(numIter)).recordOverallStatus( WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); @@ -342,7 +341,7 @@ public class RttServiceImplTest extends WifiBaseTest { finalRequest.mRttPeers.get(finalRequest.mRttPeers.size() - 1).macAddress); // issue results - but remove the one for peer #2 - Pair<List<RttResult>, List<RangingResult>> results = + Pair<List<RangingResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults(mRequestCaptor.getValue()); results.first.remove(results.first.size() - 1); RangingResult removed = results.second.remove(results.second.size() - 1); @@ -357,6 +356,7 @@ public class RttServiceImplTest extends WifiBaseTest { verify(mockCallback).onRangingResults(mListCaptor.capture()); verifyWakeupCancelled(); + assertEquals(results.second, mListCaptor.getValue()); assertTrue(compareListContentsNoOrdering(results.second, mListCaptor.getValue())); // verify metrics @@ -376,7 +376,7 @@ public class RttServiceImplTest extends WifiBaseTest { public void testRangingFlowNativeFailure() throws Exception { int numIter = 10; RangingRequest[] requests = new RangingRequest[numIter]; - List<Pair<List<RttResult>, List<RangingResult>>> results = new ArrayList<>(); + List<Pair<List<RangingResult>, List<RangingResult>>> results = new ArrayList<>(); for (int i = 0; i < numIter; ++i) { requests[i] = RttTestUtils.getDummyRangingRequest((byte) i); @@ -409,7 +409,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (4) on failed HAL: even if native calls back with result we shouldn't dispatch // callback, otherwise expect result - mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).first); + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).second); mMockLooper.dispatchAll(); if (i != 0) { @@ -422,7 +422,7 @@ public class RttServiceImplTest extends WifiBaseTest { for (int i = 0; i < numIter; ++i) { verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(requests[i])); if (i != 0) { - verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).first)); + verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).second)); } } verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_HAL_FAILURE); @@ -440,8 +440,8 @@ public class RttServiceImplTest extends WifiBaseTest { @Test public void testRangingRequestWithoutRuntimePermission() throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); @@ -455,7 +455,7 @@ public class RttServiceImplTest extends WifiBaseTest { when(mockPermissionUtil.checkCallersLocationPermission(eq(mPackageName), anyInt(), anyBoolean())).thenReturn(false); - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); verify(mockCallback).onRangingFailure(eq(RangingResultCallback.STATUS_CODE_FAIL)); @@ -479,7 +479,7 @@ public class RttServiceImplTest extends WifiBaseTest { public void testBinderDeathOfRangingApp() throws Exception { int numIter = 10; RangingRequest[] requests = new RangingRequest[numIter]; - List<Pair<List<RttResult>, List<RangingResult>>> results = new ArrayList<>(); + List<Pair<List<RangingResult>, List<RangingResult>>> results = new ArrayList<>(); for (int i = 0; i < numIter; ++i) { requests[i] = RttTestUtils.getDummyRangingRequest((byte) i); @@ -523,7 +523,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (5) native calls back with all results - should get requests for the odd attempts and // should only get callbacks for the odd attempts (the non-dead UID), but this simulates // invalid results (or possibly the firmware not cancelling some requests) - mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).first); + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i).second); mMockLooper.dispatchAll(); if (i == 0) { verifyWakeupCancelled(); // as the first (dispatched) request is aborted @@ -540,7 +540,7 @@ public class RttServiceImplTest extends WifiBaseTest { verify(mockMetrics).recordRequest(eq((i % 2) == 0 ? mDefaultWs : oddWs), eq(requests[i])); if (i % 2 == 1) { - verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).first)); + verify(mockMetrics).recordResult(eq(requests[i]), eq(results.get(i).second)); } } verify(mockMetrics, times(numIter / 2)).recordOverallStatus( @@ -560,8 +560,8 @@ public class RttServiceImplTest extends WifiBaseTest { WorkSource ws = new WorkSource(100); RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation mDut.startRanging(mockIbinder, mPackageName, ws, request, mockCallback); @@ -579,7 +579,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupCancelled(); // (3) provide results back - should be ignored - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); // verify metrics @@ -610,8 +610,8 @@ public class RttServiceImplTest extends WifiBaseTest { worksourceCancel.createWorkChain().addNode(uid4, "foo"); RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation mDut.startRanging(mockIbinder, mPackageName, worksourceRequest, request, mockCallback); @@ -629,7 +629,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupCancelled(); // (4) send results back from native - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); // verify metrics @@ -656,8 +656,8 @@ public class RttServiceImplTest extends WifiBaseTest { worksourceCancel.add(uid2); RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation mDut.startRanging(mockIbinder, mPackageName, worksourceRequest, request, mockCallback); @@ -671,7 +671,7 @@ public class RttServiceImplTest extends WifiBaseTest { mDut.cancelRanging(worksourceCancel); // (4) send results back from native - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); verify(mockCallback).onRangingResults(results.second); @@ -679,7 +679,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(worksourceRequest), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(results.first)); + verify(mockMetrics).recordResult(eq(request), eq(results.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); verify(mockNative, atLeastOnce()).isReady(); @@ -694,8 +694,8 @@ public class RttServiceImplTest extends WifiBaseTest { @Test public void testUnexpectedResult() throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); @@ -707,11 +707,11 @@ public class RttServiceImplTest extends WifiBaseTest { // (3) native calls back with result - but wrong ID mDut.onRangingResults(mIntCaptor.getValue() + 1, - RttTestUtils.getDummyRangingResults(null).first); + RttTestUtils.getDummyRangingResults(null).second); mMockLooper.dispatchAll(); // (4) now send results with correct ID (different set of results to differentiate) - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); // (5) verify that results dispatched @@ -720,7 +720,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(results.first)); + verify(mockMetrics).recordResult(eq(request), eq(results.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); verify(mockNative, atLeastOnce()).isReady(); @@ -735,10 +735,10 @@ public class RttServiceImplTest extends WifiBaseTest { @Test public void testMissingResults() throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); - results.first.remove(2); // remove a direct AWARE request - RangingResult removed = results.second.remove(2); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); + results.first.remove(1); // remove a direct AWARE request + RangingResult removed = results.second.remove(1); results.second.add( new RangingResult(RangingResult.STATUS_FAIL, removed.getMacAddress(), 0, 0, 0, 0, 0, null, null, null, 0)); @@ -757,7 +757,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, 0); // (3) return results with missing entries - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); // (5) verify that (full) results dispatched @@ -767,7 +767,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(results.first)); + verify(mockMetrics).recordResult(eq(request), eq(results.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); verify(mockNative, atLeastOnce()).isReady(); @@ -782,8 +782,8 @@ public class RttServiceImplTest extends WifiBaseTest { @Test public void testMissingAllResults() throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); List<RangingResult> allFailResults = new ArrayList<>(); for (RangingResult result : results.second) { allFailResults.add( @@ -810,7 +810,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(new ArrayList<RttResult>())); + verify(mockMetrics).recordResult(eq(request), eq(new ArrayList<>())); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); verify(mockNative, atLeastOnce()).isReady(); @@ -826,8 +826,8 @@ public class RttServiceImplTest extends WifiBaseTest { @Test public void testMissingResultsForNonSupportOf80211mc() throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); - Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> results = + RttTestUtils.getDummyRangingResults(request); results.first.remove(1); // remove the entry which doesn't support 802.11mc RangingResult removed = results.second.remove(1); results.second.add( @@ -853,7 +853,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, 0); // (3) return results with missing entries - mDut.onRangingResults(mIntCaptor.getValue(), results.first); + mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); // (5) verify that (full) results dispatched @@ -863,7 +863,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(results.first)); + verify(mockMetrics).recordResult(eq(request), eq(results.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); verify(mockNative, atLeastOnce()).isReady(); @@ -879,10 +879,10 @@ public class RttServiceImplTest extends WifiBaseTest { public void testRangingTimeout() throws Exception { RangingRequest request1 = RttTestUtils.getDummyRangingRequest((byte) 1); RangingRequest request2 = RttTestUtils.getDummyRangingRequest((byte) 2); - Pair<List<RttResult>, List<RangingResult>> result1 = RttTestUtils.getDummyRangingResults( - request1); - Pair<List<RttResult>, List<RangingResult>> result2 = RttTestUtils.getDummyRangingResults( - request2); + Pair<List<RangingResult>, List<RangingResult>> result1 = + RttTestUtils.getDummyRangingResults(request1); + Pair<List<RangingResult>, List<RangingResult>> result2 = + RttTestUtils.getDummyRangingResults(request2); // (1) request 2 ranging operation mDut.startRanging(mockIbinder, mPackageName, null, request1, mockCallback); @@ -905,8 +905,8 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, 0); // (3) send both result 1 and result 2 - mDut.onRangingResults(cmdId1, result1.first); - mDut.onRangingResults(mIntCaptor.getValue(), result2.first); + mDut.onRangingResults(cmdId1, result1.second); + mDut.onRangingResults(mIntCaptor.getValue(), result2.second); mMockLooper.dispatchAll(); // verify that only result 2 is forwarded to client @@ -916,7 +916,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request1)); verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request2)); - verify(mockMetrics).recordResult(eq(request2), eq(result2.first)); + verify(mockMetrics).recordResult(eq(request2), eq(result2.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_TIMEOUT); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); @@ -941,12 +941,12 @@ public class RttServiceImplTest extends WifiBaseTest { RangingRequest request4 = RttTestUtils.getDummyRangingRequest((byte) 4); RangingRequest request5 = RttTestUtils.getDummyRangingRequest((byte) 5); - Pair<List<RttResult>, List<RangingResult>> result1 = RttTestUtils.getDummyRangingResults( - request1); - Pair<List<RttResult>, List<RangingResult>> result3 = RttTestUtils.getDummyRangingResults( - request3); - Pair<List<RttResult>, List<RangingResult>> result4 = RttTestUtils.getDummyRangingResults( - request4); + Pair<List<RangingResult>, List<RangingResult>> result1 = + RttTestUtils.getDummyRangingResults(request1); + Pair<List<RangingResult>, List<RangingResult>> result3 = + RttTestUtils.getDummyRangingResults(request3); + Pair<List<RangingResult>, List<RangingResult>> result4 = + RttTestUtils.getDummyRangingResults(request4); InOrder cbInorder = inOrder(mockCallback); @@ -964,7 +964,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, clock.time); // (1.1) get result - mDut.onRangingResults(mIntCaptor.getValue(), result1.first); + mDut.onRangingResults(mIntCaptor.getValue(), result1.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result1.second); @@ -986,7 +986,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, clock.time); // (3.1) get result - mDut.onRangingResults(mIntCaptor.getValue(), result3.first); + mDut.onRangingResults(mIntCaptor.getValue(), result3.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result3.second); @@ -1004,7 +1004,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, clock.time); // (4.1) get result - mDut.onRangingResults(mIntCaptor.getValue(), result4.first); + mDut.onRangingResults(mIntCaptor.getValue(), result4.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result4.second); @@ -1026,9 +1026,9 @@ public class RttServiceImplTest extends WifiBaseTest { verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request3)); verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request4)); verify(mockMetrics).recordRequest(eq(mDefaultWs), eq(request5)); - verify(mockMetrics).recordResult(eq(request1), eq(result1.first)); - verify(mockMetrics).recordResult(eq(request3), eq(result3.first)); - verify(mockMetrics).recordResult(eq(request4), eq(result4.first)); + verify(mockMetrics).recordResult(eq(request1), eq(result1.second)); + verify(mockMetrics).recordResult(eq(request3), eq(result3.second)); + verify(mockMetrics).recordResult(eq(request4), eq(result4.second)); verify(mockMetrics, times(2)).recordOverallStatus( WifiMetricsProto.WifiRttLog.OVERALL_THROTTLE); verify(mockMetrics, times(3)).recordOverallStatus( @@ -1074,10 +1074,10 @@ public class RttServiceImplTest extends WifiBaseTest { RangingRequest request2 = RttTestUtils.getDummyRangingRequest((byte) 2); RangingRequest request3 = RttTestUtils.getDummyRangingRequest((byte) 3); - Pair<List<RttResult>, List<RangingResult>> result1 = RttTestUtils.getDummyRangingResults( - request1); - Pair<List<RttResult>, List<RangingResult>> result2 = RttTestUtils.getDummyRangingResults( - request2); + Pair<List<RangingResult>, List<RangingResult>> result1 = + RttTestUtils.getDummyRangingResults(request1); + Pair<List<RangingResult>, List<RangingResult>> result2 = + RttTestUtils.getDummyRangingResults(request2); InOrder cbInorder = inOrder(mockCallback); @@ -1095,7 +1095,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, clock.time); // (1.1) get result - mDut.onRangingResults(mIntCaptor.getValue(), result1.first); + mDut.onRangingResults(mIntCaptor.getValue(), result1.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result1.second); @@ -1111,7 +1111,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, clock.time); // (2.1) get result - mDut.onRangingResults(mIntCaptor.getValue(), result2.first); + mDut.onRangingResults(mIntCaptor.getValue(), result2.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result2.second); @@ -1128,8 +1128,8 @@ public class RttServiceImplTest extends WifiBaseTest { verify(mockMetrics).recordRequest(eq(wsReq1), eq(request1)); verify(mockMetrics).recordRequest(eq(wsReq2), eq(request2)); verify(mockMetrics).recordRequest(eq(wsReq1), eq(request3)); - verify(mockMetrics).recordResult(eq(request1), eq(result1.first)); - verify(mockMetrics).recordResult(eq(request2), eq(result2.first)); + verify(mockMetrics).recordResult(eq(request1), eq(result1.second)); + verify(mockMetrics).recordResult(eq(request2), eq(result2.second)); verify(mockMetrics).recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_THROTTLE); verify(mockMetrics, times(2)).recordOverallStatus( WifiMetricsProto.WifiRttLog.OVERALL_SUCCESS); @@ -1193,8 +1193,8 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupCancelled(); verify(mockNative).rangeCancel(eq(mIntCaptor.getValue()), any()); - verify(mockCallback, times(RttServiceImpl.MAX_QUEUED_PER_UID + 11)).onRangingFailure( - RangingResultCallback.STATUS_CODE_FAIL_RTT_NOT_AVAILABLE); + verify(mockCallback, times(RttServiceImpl.MAX_QUEUED_PER_UID + 11)) + .onRangingFailure(RangingResultCallback.STATUS_CODE_FAIL_RTT_NOT_AVAILABLE); // verify metrics for (int i = 0; i < RttServiceImpl.MAX_QUEUED_PER_UID + 11; ++i) { @@ -1204,8 +1204,8 @@ public class RttServiceImplTest extends WifiBaseTest { } verify(mockMetrics).recordRequest(eq(wsExtra), eq(request)); } - verify(mockMetrics, times(RttServiceImpl.MAX_QUEUED_PER_UID + 11)).recordOverallStatus( - WifiMetricsProto.WifiRttLog.OVERALL_RTT_NOT_AVAILABLE); + verify(mockMetrics, times(RttServiceImpl.MAX_QUEUED_PER_UID + 11)) + .recordOverallStatus(WifiMetricsProto.WifiRttLog.OVERALL_RTT_NOT_AVAILABLE); verify(mockNative, atLeastOnce()).isReady(); verifyNoMoreInteractions(mockNative, mockMetrics, mockCallback, @@ -1221,8 +1221,8 @@ public class RttServiceImplTest extends WifiBaseTest { private void runFloodRequestsTest(boolean useUids, boolean useChainedWorkSources) throws Exception { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 1); - Pair<List<RttResult>, List<RangingResult>> result = RttTestUtils.getDummyRangingResults( - request); + Pair<List<RangingResult>, List<RangingResult>> result = + RttTestUtils.getDummyRangingResults(request); WorkSource ws = new WorkSource(); if (useChainedWorkSources) { @@ -1256,7 +1256,7 @@ public class RttServiceImplTest extends WifiBaseTest { RangingResultCallback.STATUS_CODE_FAIL); // 3. provide results - mDut.onRangingResults(mIntCaptor.getValue(), result.first); + mDut.onRangingResults(mIntCaptor.getValue(), result.second); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingResults(result.second); @@ -1281,7 +1281,7 @@ public class RttServiceImplTest extends WifiBaseTest { // verify metrics verify(mockMetrics, times(RttServiceImpl.MAX_QUEUED_PER_UID + 12)).recordRequest( eq(useUids ? mDefaultWs : ws), eq(request)); - verify(mockMetrics).recordResult(eq(request), eq(result.first)); + verify(mockMetrics).recordResult(eq(request), eq(result.second)); verify(mockMetrics, times(11)).recordOverallStatus( WifiMetricsProto.WifiRttLog.OVERALL_THROTTLE); verify(mockMetrics, times(RttServiceImpl.MAX_QUEUED_PER_UID)).recordOverallStatus( diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java index c5385eb94..a112a7c17 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java @@ -16,8 +16,6 @@ package com.android.server.wifi.rtt; -import android.hardware.wifi.V1_0.RttResult; -import android.hardware.wifi.V1_0.RttStatus; import android.net.MacAddress; import android.net.wifi.ScanResult; import android.net.wifi.rtt.RangingRequest; @@ -117,18 +115,21 @@ public class RttTestUtils { * * @param request If non-null will be used as a template (BSSID) for the range results. */ - public static Pair<List<RttResult>, List<RangingResult>> getDummyRangingResults( + public static Pair<List<RangingResult>, List<RangingResult>> getDummyRangingResults( RangingRequest request) { int rangeCmBase = 15; int rangeStdDevCmBase = 3; int rssiBase = -20; long rangeTimestampBase = 666; - List<RttResult> halResults = new ArrayList<>(); + List<RangingResult> halResults = new ArrayList<>(); List<RangingResult> results = new ArrayList<>(); if (request != null) { for (ResponderConfig peer: request.mRttPeers) { RangingResult rangingResult; + halResults.add(new RangingResult(RangingResult.STATUS_SUCCESS, + peer.macAddress, rangeCmBase, rangeStdDevCmBase, rssiBase, + 8, 5, null, null, null, rangeTimestampBase)); if (peer.peerHandle == null) { rangingResult = new RangingResult(RangingResult.STATUS_SUCCESS, peer.macAddress, rangeCmBase++, rangeStdDevCmBase++, rssiBase++, @@ -139,7 +140,7 @@ public class RttTestUtils { 8, 5, null, null, null, rangeTimestampBase++); } results.add(rangingResult); - halResults.add(getMatchingRttResult(rangingResult, peer.macAddress)); + } } else { results.add(new RangingResult(RangingResult.STATUS_SUCCESS, @@ -154,28 +155,9 @@ public class RttTestUtils { MacAddress.fromString("08:09:08:07:06:05"), rangeCmBase++, rangeStdDevCmBase++, rssiBase++, 10, 2, null, null, null, rangeTimestampBase++)); - halResults.add(getMatchingRttResult(results.get(0), null)); - halResults.add(getMatchingRttResult(results.get(1), null)); - halResults.add(getMatchingRttResult(results.get(2), null)); + halResults.addAll(results); } return new Pair<>(halResults, results); } - - private static RttResult getMatchingRttResult(RangingResult rangingResult, - MacAddress overrideMac) { - RttResult rttResult = new RttResult(); - rttResult.status = rangingResult.getStatus() == RangingResult.STATUS_SUCCESS - ? RttStatus.SUCCESS : RttStatus.FAILURE; - System.arraycopy(overrideMac == null ? rangingResult.getMacAddress().toByteArray() - : overrideMac.toByteArray(), 0, rttResult.addr, 0, 6); - rttResult.distanceInMm = rangingResult.getDistanceMm(); - rttResult.distanceSdInMm = rangingResult.getDistanceStdDevMm(); - rttResult.rssi = rangingResult.getRssi() * -2; - rttResult.numberPerBurstPeer = (byte) rangingResult.getNumAttemptedMeasurements(); - rttResult.successNumber = rangingResult.getNumSuccessfulMeasurements(); - rttResult.timeStampInUs = rangingResult.getRangingTimestampMillis() * 1000; - - return rttResult; - } } |