From 0f37ecb31e0cc3367a897920ea121bc0870e5738 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Wed, 27 May 2020 12:17:52 -0700 Subject: [AWARE] Loop retry to get valid IPv6 address and verify usablity Bug: 155255680 Test: atest com.android.server.wifi Test: acts DataPathTest Change-Id: I20d62ac93298c1609a5edc18b369c31521076ccb --- .../aware/WifiAwareDataPathStateManagerTest.java | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index df7417338..f496b1c95 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -1394,9 +1394,15 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (2) get confirmation OR timeout + boolean timeout = false; if (getConfirmation) { + int numConfigureAgentPropertiesFail = 0; if (numAddrValidationRetries > 0) { when(mMockNetworkInterface.isAddressUsable(any())).thenReturn(false); + when(mMockNetworkInterface.configureAgentProperties(any(), any(), anyInt(), + any(), any())).thenReturn(false); + // First retry will be ConfigureAgentProperties failure. + numConfigureAgentPropertiesFail = 1; } when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); @@ -1406,35 +1412,41 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { inOrder.verify(mMockNetdWrapper).enableIpv6(anyString()); inOrder.verify(mMockNetworkInterface).configureAgentProperties(any(), any(), anyInt(), any(), any()); - inOrder.verify(mMockCm).registerNetworkAgent(messengerCaptor.capture(), any(), any(), - netCapCaptor.capture(), anyInt(), any(), anyInt()); - - inOrder.verify(mMockNetworkInterface).isAddressUsable(any()); - boolean timedout = false; + if (numAddrValidationRetries <= 0) { + inOrder.verify(mMockNetworkInterface).isAddressUsable(any()); + } for (int i = 0; i < numAddrValidationRetries; ++i) { + if (i == numConfigureAgentPropertiesFail) { + when(mMockNetworkInterface.configureAgentProperties(any(), any(), anyInt(), + any(), any())).thenReturn(true); + } if (i == numAddrValidationRetries - 1) { when(mMockNetworkInterface.isAddressUsable(any())).thenReturn(true); } - long currentTime = (i + 1L) * WifiAwareDataPathStateManager.ADDRESS_VALIDATION_RETRY_INTERVAL_MS; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime); mMockLooper.moveTimeForward( WifiAwareDataPathStateManager.ADDRESS_VALIDATION_RETRY_INTERVAL_MS + 1); mMockLooper.dispatchAll(); + inOrder.verify(mMockNetworkInterface).configureAgentProperties(any(), any(), + anyInt(), any(), any()); + if (i < numConfigureAgentPropertiesFail) { + continue; + } inOrder.verify(mMockNetworkInterface).isAddressUsable(any()); - if (currentTime > WifiAwareDataPathStateManager.ADDRESS_VALIDATION_TIMEOUT_MS) { - timedout = true; + timeout = true; break; } } - - if (timedout) { + if (timeout) { verifyRequestDeclaredUnfullfillable(nr); inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId)); mDut.onEndDataPathResponse(transactionId.getValue(), true, 0); } else { + inOrder.verify(mMockCm).registerNetworkAgent(messengerCaptor.capture(), any(), + any(), netCapCaptor.capture(), anyInt(), any(), anyInt()); inOrder.verify(mMockNetworkInterface).setConnected(any()); inOrderM.verify(mAwareMetricsMock).recordNdpStatus(eq(NanStatusType.SUCCESS), eq(useDirect), anyLong()); @@ -1458,7 +1470,7 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { } // (3) end data-path (unless didn't get confirmation) - if (getConfirmation) { + if (getConfirmation && !timeout) { Message endNetworkReqMsg = Message.obtain(); endNetworkReqMsg.what = NetworkFactory.CMD_CANCEL_REQUEST; endNetworkReqMsg.obj = nr; -- cgit v1.2.3