diff options
| author | 2017-02-13 17:12:02 +0900 | |
|---|---|---|
| committer | 2017-02-13 17:38:34 +0900 | |
| commit | a954be956315e6d25a63e961fc9befe9916e1cbd (patch) | |
| tree | 24dc642ec9f2d43b813ccb735129f975c592b0cf | |
| parent | e690e0178caa4d352694f1b3bab303e67126fb04 (diff) | |
Add test coverage for cleanup bug to be fixed.
The test calls that need to pass but do not currently are commented out.
Test: as follows
- built (bullhead)
- flashed
- booted
- runtest -x .../tethering/TetherInterfaceStateMachineTest.java passes
Bug: 32031803
Bug: 32163131
Change-Id: I68ed476920bef882f353d8e8a54c72120bc27002
| -rw-r--r-- | tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java b/tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java index 9f7261dc6019..0fa45454fa70 100644 --- a/tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java +++ b/tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java @@ -28,6 +28,9 @@ import static android.net.ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; +import static android.net.ConnectivityManager.TETHERING_BLUETOOTH; +import static android.net.ConnectivityManager.TETHERING_USB; +import static android.net.ConnectivityManager.TETHERING_WIFI; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_AVAILABLE; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE; @@ -92,7 +95,7 @@ public class TetherInterfaceStateMachineTest { @Test public void startsOutAvailable() { mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), - ConnectivityManager.TETHERING_BLUETOOTH, mNMService, mStatsService, mTetherHelper, + TETHERING_BLUETOOTH, mNMService, mStatsService, mTetherHelper, mIPv6TetheringInterfaceServices); mTestedSm.start(); mLooper.dispatchAll(); @@ -103,7 +106,7 @@ public class TetherInterfaceStateMachineTest { @Test public void shouldDoNothingUntilRequested() throws Exception { - initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH); + initStateMachine(TETHERING_BLUETOOTH); final int [] NOOP_COMMANDS = { TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED, TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR, @@ -123,7 +126,7 @@ public class TetherInterfaceStateMachineTest { @Test public void handlesImmediateInterfaceDown() throws Exception { - initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH); + initStateMachine(TETHERING_BLUETOOTH); dispatchCommand(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); verify(mTetherHelper).notifyInterfaceStateChange( @@ -133,7 +136,7 @@ public class TetherInterfaceStateMachineTest { @Test public void canBeTethered() throws Exception { - initStateMachine(ConnectivityManager.TETHERING_BLUETOOTH); + initStateMachine(TETHERING_BLUETOOTH); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); @@ -145,7 +148,7 @@ public class TetherInterfaceStateMachineTest { @Test public void canUnrequestTethering() throws Exception { - initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, null); + initTetheredStateMachine(TETHERING_BLUETOOTH, null); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); @@ -157,7 +160,7 @@ public class TetherInterfaceStateMachineTest { @Test public void canBeTetheredAsUsb() throws Exception { - initStateMachine(ConnectivityManager.TETHERING_USB); + initStateMachine(TETHERING_USB); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); @@ -171,7 +174,7 @@ public class TetherInterfaceStateMachineTest { @Test public void handlesFirstUpstreamChange() throws Exception { - initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, null); + initTetheredStateMachine(TETHERING_BLUETOOTH, null); // Telling the state machine about its upstream interface triggers a little more configuration. dispatchTetherConnectionChanged(UPSTREAM_IFACE); @@ -183,7 +186,7 @@ public class TetherInterfaceStateMachineTest { @Test public void handlesChangingUpstream() throws Exception { - initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, UPSTREAM_IFACE); + initTetheredStateMachine(TETHERING_BLUETOOTH, UPSTREAM_IFACE); dispatchTetherConnectionChanged(UPSTREAM_IFACE2); InOrder inOrder = inOrder(mNMService, mStatsService); @@ -196,8 +199,46 @@ public class TetherInterfaceStateMachineTest { } @Test + public void handlesChangingUpstreamNatFailure() throws Exception { + initTetheredStateMachine(TETHERING_WIFI, UPSTREAM_IFACE); + + doThrow(RemoteException.class).when(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2); + + dispatchTetherConnectionChanged(UPSTREAM_IFACE2); + InOrder inOrder = inOrder(mNMService, mStatsService); + inOrder.verify(mStatsService).forceUpdate(); + inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE); + inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE); + inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2); + // TODO: Verify proper cleanup is performed: + // inOrder.verify(mStatsService).forceUpdate(); + // inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); + // inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2); + } + + @Test + public void handlesChangingUpstreamInterfaceForwardingFailure() throws Exception { + initTetheredStateMachine(TETHERING_WIFI, UPSTREAM_IFACE); + + doThrow(RemoteException.class).when(mNMService).startInterfaceForwarding( + IFACE_NAME, UPSTREAM_IFACE2); + + dispatchTetherConnectionChanged(UPSTREAM_IFACE2); + InOrder inOrder = inOrder(mNMService, mStatsService); + inOrder.verify(mStatsService).forceUpdate(); + inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE); + inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE); + inOrder.verify(mNMService).enableNat(IFACE_NAME, UPSTREAM_IFACE2); + inOrder.verify(mNMService).startInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); + // TODO: Verify proper cleanup is performed: + // inOrder.verify(mStatsService).forceUpdate(); + // inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE2); + // inOrder.verify(mNMService).disableNat(IFACE_NAME, UPSTREAM_IFACE2); + } + + @Test public void canUnrequestTetheringWithUpstream() throws Exception { - initTetheredStateMachine(ConnectivityManager.TETHERING_BLUETOOTH, UPSTREAM_IFACE); + initTetheredStateMachine(TETHERING_BLUETOOTH, UPSTREAM_IFACE); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); @@ -213,7 +254,7 @@ public class TetherInterfaceStateMachineTest { @Test public void interfaceDownLeadsToUnavailable() throws Exception { for (boolean shouldThrow : new boolean[]{true, false}) { - initTetheredStateMachine(ConnectivityManager.TETHERING_USB, null); + initTetheredStateMachine(TETHERING_USB, null); if (shouldThrow) { doThrow(RemoteException.class).when(mNMService).untetherInterface(IFACE_NAME); @@ -230,7 +271,7 @@ public class TetherInterfaceStateMachineTest { @Test public void usbShouldBeTornDownOnTetherError() throws Exception { - initStateMachine(ConnectivityManager.TETHERING_USB); + initStateMachine(TETHERING_USB); doThrow(RemoteException.class).when(mNMService).tetherInterface(IFACE_NAME); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); @@ -244,7 +285,7 @@ public class TetherInterfaceStateMachineTest { @Test public void shouldTearDownUsbOnUpstreamError() throws Exception { - initTetheredStateMachine(ConnectivityManager.TETHERING_USB, null); + initTetheredStateMachine(TETHERING_USB, null); doThrow(RemoteException.class).when(mNMService).enableNat(anyString(), anyString()); dispatchTetherConnectionChanged(UPSTREAM_IFACE); |