summaryrefslogtreecommitdiff
path: root/tests/net/java/com/android/server/IpSecServiceTest.java
diff options
context:
space:
mode:
authorBenedict Wong <benedictwong@google.com>2018-01-18 18:31:45 -0800
committerBenedict Wong <benedictwong@google.com>2018-01-24 07:24:27 +0000
commit8149f6eb6c0280078dc41d72027d1241e875ea02 (patch)
treeedaf414a9ea4cf098e1d91c0d941f7f5b9f2dbd8 /tests/net/java/com/android/server/IpSecServiceTest.java
parent73f79ceae991d4e8b8d28c464fcf11a296877a68 (diff)
Add TunnelInterface API and KernelResourceRecords
This change adds one KernelResourceRecord type (TunnelInterfaceRecord), and adds methods for the creation of TunnelInterfaces, as well as the application of Transforms to the given TunnelInterfaces As part of the generation of ikeys/okeys, a ReserveKeyTracker manages a java bitset to avoid collisions and reserve/release keys. Bug: 63588681 Test: Compiles, CTS, unit tests all pass on AOSP_marlin Change-Id: I9e9b6455e27073acd4491eae666aa966b3b10e0f
Diffstat (limited to 'tests/net/java/com/android/server/IpSecServiceTest.java')
-rw-r--r--tests/net/java/com/android/server/IpSecServiceTest.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/net/java/com/android/server/IpSecServiceTest.java b/tests/net/java/com/android/server/IpSecServiceTest.java
index a375b600ca60..2c94a601fbf6 100644
--- a/tests/net/java/com/android/server/IpSecServiceTest.java
+++ b/tests/net/java/com/android/server/IpSecServiceTest.java
@@ -635,4 +635,25 @@ public class IpSecServiceTest {
verify(mMockNetd).ipSecSetEncapSocketOwner(argThat(fdMatcher), eq(Os.getuid()));
mIpSecService.closeUdpEncapsulationSocket(udpEncapResp.resourceId);
}
+
+ @Test
+ public void testReserveNetId() {
+ int start = mIpSecService.TUN_INTF_NETID_START;
+ for (int i = 0; i < mIpSecService.TUN_INTF_NETID_RANGE; i++) {
+ assertEquals(start + i, mIpSecService.reserveNetId());
+ }
+
+ // Check that resource exhaustion triggers an exception
+ try {
+ mIpSecService.reserveNetId();
+ fail("Did not throw error for all netIds reserved");
+ } catch (IllegalStateException expected) {
+ }
+
+ // Now release one and try again
+ int releasedNetId =
+ mIpSecService.TUN_INTF_NETID_START + mIpSecService.TUN_INTF_NETID_RANGE / 2;
+ mIpSecService.releaseNetId(releasedNetId);
+ assertEquals(releasedNetId, mIpSecService.reserveNetId());
+ }
}