diff options
author | Etan Cohen <etancohen@google.com> | 2017-09-15 17:33:07 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2017-09-26 16:56:38 -0700 |
commit | f95290d23bce73c4ad2efefce196c043b11df8b3 (patch) | |
tree | 243a72950817f2615e78f659df5889cac6e545a8 /tests/wifitests/src/com/android/server/wifi/rtt | |
parent | 6e0141700e5fee870c84359ddde6ee71c16fee19 (diff) | |
download | android_frameworks_opt_net_wifi-f95290d23bce73c4ad2efefce196c043b11df8b3.tar.gz android_frameworks_opt_net_wifi-f95290d23bce73c4ad2efefce196c043b11df8b3.tar.bz2 android_frameworks_opt_net_wifi-f95290d23bce73c4ad2efefce196c043b11df8b3.zip |
[RTT2] Add support for queueing ranging requets
Sequential ranging requests will be queued and executed in order.
Bug: 65014772
Test: new unit tests + integration tests pass
Change-Id: I54344da12c02170cf43991ec1b0b6caecb6b8243
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/rtt')
3 files changed, 109 insertions, 48 deletions
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 99fa24745..b4fe76503 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java @@ -101,7 +101,7 @@ public class RttNativeTest { @Test public void testRangeRequest() throws Exception { int cmdId = 55; - RangingRequest request = RttTestUtils.getDummyRangingRequest(); + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); // (1) issue range request mDut.rangeRequest(cmdId, request); @@ -117,13 +117,13 @@ public class RttNativeTest { RttConfig rttConfig = halRequest.get(0); collector.checkThat("entry 0: MAC", rttConfig.addr, - equalTo(HexEncoding.decode("000102030405".toCharArray(), false))); + equalTo(HexEncoding.decode("000102030400".toCharArray(), false))); collector.checkThat("entry 0: MAC", rttConfig.type, equalTo(RttType.TWO_SIDED)); collector.checkThat("entry 0: MAC", rttConfig.peer, equalTo(RttPeerType.AP)); rttConfig = halRequest.get(1); collector.checkThat("entry 0: MAC", rttConfig.addr, - equalTo(HexEncoding.decode("0A0B0C0D0E0F".toCharArray(), false))); + equalTo(HexEncoding.decode("0A0B0C0D0E00".toCharArray(), false))); collector.checkThat("entry 0: MAC", rttConfig.type, equalTo(RttType.ONE_SIDED)); collector.checkThat("entry 0: MAC", rttConfig.peer, equalTo(RttPeerType.AP)); } 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 84d8e7858..43bf5d087 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java @@ -20,6 +20,7 @@ package com.android.server.wifi.rtt; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -113,26 +114,37 @@ public class RttServiceImplTest { */ @Test public void testRangingFlow() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); - List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); + int numIter = 10; + RangingRequest[] requests = new RangingRequest[numIter]; + List<List<RangingResult>> results = new ArrayList<>(); - // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, request, mockCallback); + for (int i = 0; i < numIter; ++i) { + requests[i] = RttTestUtils.getDummyRangingRequest((byte) i); + results.add(RttTestUtils.getDummyRangingResults(requests[i])); + } + + // (1) request 10 ranging operations + for (int i = 0; i < numIter; ++i) { + mDut.startRanging(mockIbinder, mPackageName, requests[i], mockCallback); + } mMockLooper.dispatchAll(); - // (2) verify that request issued to native - verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request)); + for (int i = 0; i < numIter; ++i) { + // (2) verify that request issued to native + verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(requests[i])); - // (3) native calls back with result - mDut.onRangingResults(mIntCaptor.getValue(), results); - mMockLooper.dispatchAll(); + // (3) native calls back with result + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i)); + mMockLooper.dispatchAll(); - // (4) verify that results dispatched - verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_SUCCESS, results); + // (4) verify that results dispatched + verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_SUCCESS, + results.get(i)); - // (5) replicate results - shouldn't dispatch another callback - mDut.onRangingResults(mIntCaptor.getValue(), results); - mMockLooper.dispatchAll(); + // (5) replicate results - shouldn't dispatch another callback + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i)); + mMockLooper.dispatchAll(); + } verifyNoMoreInteractions(mockNative, mockCallback); } @@ -142,24 +154,46 @@ public class RttServiceImplTest { */ @Test public void testRangingFlowNativeFailure() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); - List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); + int numIter = 10; + RangingRequest[] requests = new RangingRequest[numIter]; + List<List<RangingResult>> results = new ArrayList<>(); + for (int i = 0; i < numIter; ++i) { + requests[i] = RttTestUtils.getDummyRangingRequest((byte) i); + results.add(RttTestUtils.getDummyRangingResults(requests[i])); + } + + + // (1) request 10 ranging operations: fail the first one when(mockNative.rangeRequest(anyInt(), any(RangingRequest.class))).thenReturn(false); + mDut.startRanging(mockIbinder, mPackageName, requests[0], mockCallback); + mMockLooper.dispatchAll(); - // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, request, mockCallback); + when(mockNative.rangeRequest(anyInt(), any(RangingRequest.class))).thenReturn(true); + for (int i = 1; i < numIter; ++i) { + mDut.startRanging(mockIbinder, mPackageName, requests[i], mockCallback); + } mMockLooper.dispatchAll(); - // (2) verify that request issued to native - verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request)); + for (int i = 0; i < numIter; ++i) { + // (2) verify that request issued to native + verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(requests[i])); - // (3) verify that failure callback dispatched - verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_FAIL, null); + // (3) verify that failure callback dispatched (for the HAL failure) + if (i == 0) { + verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_FAIL, null); + } - // (4) even if native calls back with result we shouldn't dispatch callback - mDut.onRangingResults(mIntCaptor.getValue(), results); - mMockLooper.dispatchAll(); + // (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)); + mMockLooper.dispatchAll(); + + if (i != 0) { + verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_SUCCESS, + results.get(i)); + } + } verifyNoMoreInteractions(mockNative, mockCallback); } @@ -169,7 +203,7 @@ public class RttServiceImplTest { */ @Test public void testRangingRequestWithoutRuntimePermission() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation @@ -197,24 +231,51 @@ public class RttServiceImplTest { */ @Test public void testBinderDeathOfRangingApp() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); - List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); + int numIter = 10; + RangingRequest[] requests = new RangingRequest[numIter]; + List<List<RangingResult>> results = new ArrayList<>(); - // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, request, mockCallback); - mMockLooper.dispatchAll(); - - // (2) verify that request issued to native & capture death listener - verify(mockIbinder).linkToDeath(mDeathRecipientCaptor.capture(), anyInt()); - verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request)); + for (int i = 0; i < numIter; ++i) { + requests[i] = RttTestUtils.getDummyRangingRequest((byte) i); + results.add(RttTestUtils.getDummyRangingResults(requests[i])); + } - // (3) trigger death recipient - mDeathRecipientCaptor.getValue().binderDied(); + // (1) request 10 ranging operations: even/odd with different UIDs + for (int i = 0; i < numIter; ++i) { + mDut.fakeUid = mDefaultUid + i % 2; + mDut.startRanging(mockIbinder, mPackageName, requests[i], mockCallback); + } mMockLooper.dispatchAll(); - // (4) native calls back with result - shouldn't dispatch a callback - mDut.onRangingResults(mIntCaptor.getValue(), results); - mMockLooper.dispatchAll(); + // (2) capture death listeners + verify(mockIbinder, times(numIter)).linkToDeath(mDeathRecipientCaptor.capture(), anyInt()); + + for (int i = 0; i < numIter; ++i) { + // (3) verify first request and all odd requests issued to HAL + if (i == 0 || i % 2 == 1) { + verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(requests[i])); + } + + // (4) trigger first death recipient (which will map to the even UID) + if (i == 0) { + mDeathRecipientCaptor.getAllValues().get(0).binderDied(); + mMockLooper.dispatchAll(); + } + + // (5) native calls back with results - should get requests for the odd attempts and + // should only get callbacks for the odd attempts (the non-dead UID) + if (i == 0 || i % 2 == 1) { + mDut.onRangingResults(mIntCaptor.getValue(), results.get(i)); + mMockLooper.dispatchAll(); + + // note that we are getting a callback for the first operation - it was dispatched + // before the binder death. The callback is called from the service - the app is + // dead so in reality this will throw a RemoteException which the service will + // handle correctly. + verify(mockCallback).onRangingResults(RangingResultCallback.STATUS_SUCCESS, + results.get(i)); + } + } verifyNoMoreInteractions(mockNative, mockCallback); } @@ -225,7 +286,7 @@ public class RttServiceImplTest { */ @Test public void testUnexpectedResult() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation @@ -255,7 +316,7 @@ public class RttServiceImplTest { */ @Test public void testMissingResults() throws Exception { - RangingRequest request = RttTestUtils.getDummyRangingRequest(); + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); List<RangingResult> results = RttTestUtils.getDummyRangingResults(request); List<RangingResult> resultsMissing = new ArrayList<>(results); resultsMissing.remove(0); 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 d01c964cb..9512b2ac8 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java @@ -37,14 +37,14 @@ public class RttTestUtils { * - First: 802.11mc capable * - Second: 802.11mc not capable */ - public static RangingRequest getDummyRangingRequest() { + public static RangingRequest getDummyRangingRequest(byte lastMacByte) { RangingRequest.Builder builder = new RangingRequest.Builder(); ScanResult scan1 = new ScanResult(); - scan1.BSSID = "00:01:02:03:04:05"; + scan1.BSSID = "00:01:02:03:04:" + String.format("%02d", lastMacByte); scan1.setFlag(ScanResult.FLAG_80211mc_RESPONDER); ScanResult scan2 = new ScanResult(); - scan2.BSSID = "0A:0B:0C:0D:0E:0F"; + scan2.BSSID = "0A:0B:0C:0D:0E:" + String.format("%02d", lastMacByte); builder.addAp(scan1); builder.addAp(scan2); |