summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2018-01-13 17:39:51 +0900
committerLorenzo Colitti <lorenzo@google.com>2018-02-15 23:41:15 +0900
commite37079467e38c014ab89ce1196720060522edc30 (patch)
tree78891107b696e70f603c98a786598df7a469b8b8
parent54e55c9cf14adc6f777c9fbcfde1bec80651e050 (diff)
downloadtests-e37079467e38c014ab89ce1196720060522edc30.tar.gz
Don't require XFRM tests to flush all state on tearDown.
This will allow tests to set up XFRM state and policies in setUpClass instead of in setUp. This speeds up running the tests because setting up iptables rules can take a couple of seconds. This is also useful when running on device, where blowing away XFRM state in tests could be disruptive to other system functionality. Bug: 70371070 Test: xfrm tests pass on android-4.9 Change-Id: I6246c172368fd65a815175ecf58b53965de1bcfd
-rwxr-xr-xnet/test/xfrm_algorithm_test.py2
-rw-r--r--net/test/xfrm_base.py32
-rwxr-xr-xnet/test/xfrm_test.py4
-rwxr-xr-xnet/test/xfrm_tunnel_test.py5
4 files changed, 21 insertions, 22 deletions
diff --git a/net/test/xfrm_algorithm_test.py b/net/test/xfrm_algorithm_test.py
index aebd121..90e7ee0 100755
--- a/net/test/xfrm_algorithm_test.py
+++ b/net/test/xfrm_algorithm_test.py
@@ -74,7 +74,7 @@ AEAD_ALGOS = [
def InjectTests():
XfrmAlgorithmTest.InjectTests()
-class XfrmAlgorithmTest(xfrm_base.XfrmBaseTest):
+class XfrmAlgorithmTest(xfrm_base.XfrmLazyTest):
@classmethod
def InjectTests(cls):
"""Inject parameterized test cases into this class.
diff --git a/net/test/xfrm_base.py b/net/test/xfrm_base.py
index c9cfd49..1eaa302 100644
--- a/net/test/xfrm_base.py
+++ b/net/test/xfrm_base.py
@@ -268,22 +268,7 @@ def DecryptPacketWithNull(packet):
class XfrmBaseTest(multinetwork_base.MultiNetworkBaseTest):
- """Base test class for Xfrm tests
-
- Base test class for all XFRM-related testing. This class will clean
- up XFRM state before and after each test.
- """
- def setUp(self):
- # TODO: delete this when we're more diligent about deleting our SAs.
- super(XfrmBaseTest, self).setUp()
- self.xfrm = xfrm.Xfrm()
- self.xfrm.FlushSaInfo()
- self.xfrm.FlushPolicyInfo()
-
- def tearDown(self):
- super(XfrmBaseTest, self).tearDown()
- self.xfrm.FlushSaInfo()
- self.xfrm.FlushPolicyInfo()
+ """Base test class for all XFRM-related testing."""
def _ExpectEspPacketOn(self, netid, spi, seq, length, src_addr, dst_addr):
"""Read a packet from a netid and verify its properties.
@@ -312,3 +297,18 @@ class XfrmBaseTest(multinetwork_base.MultiNetworkBaseTest):
esp_hdr, _ = cstruct.Read(str(packet.payload), xfrm.EspHdr)
self.assertEquals(xfrm.EspHdr((spi, seq)), esp_hdr)
return packet
+
+
+# TODO: delete this when we're more diligent about deleting our SAs.
+class XfrmLazyTest(XfrmBaseTest):
+ """Base test class Xfrm tests that cleans XFRM state on teardown."""
+ def setUp(self):
+ super(XfrmBaseTest, self).setUp()
+ self.xfrm = xfrm.Xfrm()
+ self.xfrm.FlushSaInfo()
+ self.xfrm.FlushPolicyInfo()
+
+ def tearDown(self):
+ super(XfrmBaseTest, self).tearDown()
+ self.xfrm.FlushSaInfo()
+ self.xfrm.FlushPolicyInfo()
diff --git a/net/test/xfrm_test.py b/net/test/xfrm_test.py
index ace49be..93c66f4 100755
--- a/net/test/xfrm_test.py
+++ b/net/test/xfrm_test.py
@@ -47,7 +47,7 @@ TEST_SPI2 = 0x1235
-class XfrmFunctionalTest(xfrm_base.XfrmBaseTest):
+class XfrmFunctionalTest(xfrm_base.XfrmLazyTest):
def assertIsUdpEncapEsp(self, packet, spi, seq, length):
self.assertEquals(IPPROTO_UDP, packet.proto)
@@ -666,7 +666,7 @@ class XfrmFunctionalTest(xfrm_base.XfrmBaseTest):
def testPolicyDifferByDirectionV6(self):
self._CheckPolicyDifferByDirection(6)
-class XfrmOutputMarkTest(xfrm_base.XfrmBaseTest):
+class XfrmOutputMarkTest(xfrm_base.XfrmLazyTest):
def _CheckTunnelModeOutputMark(self, version, tunsrc, mark, expected_netid):
"""Tests sending UDP packets to tunnel mode SAs with output marks.
diff --git a/net/test/xfrm_tunnel_test.py b/net/test/xfrm_tunnel_test.py
index 6cb73c0..c687163 100755
--- a/net/test/xfrm_tunnel_test.py
+++ b/net/test/xfrm_tunnel_test.py
@@ -52,8 +52,7 @@ def _GetRemoteOuterAddress(version):
return {4: net_test.IPV4_ADDR, 6: net_test.IPV6_ADDR}[version]
-
-class XfrmTunnelTest(xfrm_base.XfrmBaseTest):
+class XfrmTunnelTest(xfrm_base.XfrmLazyTest):
def _CheckTunnelOutput(self, inner_version, outer_version):
"""Test a bi-directional XFRM Tunnel with explicit selectors"""
@@ -100,7 +99,7 @@ class XfrmTunnelTest(xfrm_base.XfrmBaseTest):
@unittest.skipUnless(net_test.LINUX_VERSION >= (3, 18, 0), "VTI Unsupported")
-class XfrmVtiTest(xfrm_base.XfrmBaseTest):
+class XfrmVtiTest(xfrm_base.XfrmLazyTest):
def setUp(self):
super(XfrmVtiTest, self).setUp()