summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-12-17 15:14:56 +0900
committerLorenzo Colitti <lorenzo@google.com>2015-02-02 17:47:30 +0900
commit334a05a24a5e4c27d9318967987fb181530deaff (patch)
treedba1cc59ae196d64c85f6aba915f520b3d103328 /tests
parent105bda9ccf001b11ca15ea48863df44ace2f5ba4 (diff)
downloadextras-334a05a24a5e4c27d9318967987fb181530deaff.tar.gz
Clean up code in preparation for AOSP.
1. Include copyright headers in all files. 2. Clean up all lint messages except "bad header", which doesn't like our copyright statement, but which I do not seem to be able to disable. Change-Id: I33b44eb7f942f0ce03c001e674377f193fb66def
Diffstat (limited to 'tests')
-rw-r--r--tests/net_test/cstruct.py14
-rw-r--r--tests/net_test/iproute.py14
-rw-r--r--tests/net_test/multinetwork_base.py32
-rwxr-xr-xtests/net_test/multinetwork_test.py14
-rwxr-xr-xtests/net_test/net_test.py14
-rwxr-xr-xtests/net_test/ping6_test.py29
-rw-r--r--tests/net_test/sendmsg.py14
-rwxr-xr-xtests/net_test/srcaddr_selection_test.py14
8 files changed, 136 insertions, 9 deletions
diff --git a/tests/net_test/cstruct.py b/tests/net_test/cstruct.py
index 36de22a6..266a5a08 100644
--- a/tests/net_test/cstruct.py
+++ b/tests/net_test/cstruct.py
@@ -1,3 +1,17 @@
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
"""A simple module for declaring C-like structures.
Example usage:
diff --git a/tests/net_test/iproute.py b/tests/net_test/iproute.py
index dec59d47..ca05193f 100644
--- a/tests/net_test/iproute.py
+++ b/tests/net_test/iproute.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
"""Partial Python implementation of iproute functionality."""
diff --git a/tests/net_test/multinetwork_base.py b/tests/net_test/multinetwork_base.py
index 2bd2740c..54934d3e 100644
--- a/tests/net_test/multinetwork_base.py
+++ b/tests/net_test/multinetwork_base.py
@@ -1,4 +1,20 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Base module for multinetwork tests."""
import errno
import fcntl
@@ -42,8 +58,8 @@ InPktinfo = cstruct.Struct("in_pktinfo", "@i4s4s", "ifindex spec_dst addr")
In6Pktinfo = cstruct.Struct("in6_pktinfo", "@16si", "addr ifindex")
-# Check to see if the kernel supports UID routing.
def HaveUidRouting():
+ """Checks whether the kernel supports UID routing."""
# Create a rule with the UID range selector. If the kernel doesn't understand
# the selector, it will create a rule with no selectors.
try:
@@ -84,6 +100,18 @@ def MakePktInfo(version, addr, ifindex):
class MultiNetworkBaseTest(net_test.NetworkTest):
+ """Base class for all multinetwork tests.
+
+ This class does not contain any test code, but contains code to set up and
+ tear a multi-network environment using multiple tun interfaces. The
+ environment is designed to be similar to a real Android device in terms of
+ rules and routes, and supports IPv4 and IPv6.
+
+ Tests wishing to use this environment should inherit from this class and
+ ensure that any setupClass, tearDownClass, setUp, and tearDown methods they
+ implement also call the superclass versions.
+ """
+
# Must be between 1 and 256, since we put them in MAC addresses and IIDs.
NETIDS = [100, 150, 200, 250]
@@ -415,7 +443,7 @@ class MultiNetworkBaseTest(net_test.NetworkTest):
while True:
try:
packet = posix.read(self.tuns[netid].fileno(), 4096)
- if len(packet) == 0:
+ if not packet:
break
ether = scapy.Ether(packet)
# Multicast frames are frames where the first byte of the destination
diff --git a/tests/net_test/multinetwork_test.py b/tests/net_test/multinetwork_test.py
index 63c0e468..b66d765d 100755
--- a/tests/net_test/multinetwork_test.py
+++ b/tests/net_test/multinetwork_test.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import errno
import os
diff --git a/tests/net_test/net_test.py b/tests/net_test/net_test.py
index f4d077c7..a87b71ba 100755
--- a/tests/net_test/net_test.py
+++ b/tests/net_test/net_test.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import fcntl
import os
diff --git a/tests/net_test/ping6_test.py b/tests/net_test/ping6_test.py
index 35871676..ff680b8f 100755
--- a/tests/net_test/ping6_test.py
+++ b/tests/net_test/ping6_test.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# pylint: disable=g-bad-todo
@@ -169,8 +183,14 @@ class Ping6Test(net_test.NetworkTest):
self.assertEquals(written, len(reply))
def testCrossProtocolCrash(self):
-
- def GetIPv4Unreachable(port):
+ # Checks that an ICMP error containing a ping packet that matches the ID
+ # of a socket of the wrong protocol (which can happen when using 464xlat)
+ # doesn't crash the kernel.
+
+ # We can only test this using IPv6 unreachables and IPv4 ping sockets,
+ # because IPv4 packets sent by scapy.send() on loopback are not received by
+ # the kernel. So we don't actually use this function yet.
+ def GetIPv4Unreachable(port): # pylint: disable=unused-variable
return (scapy.IP(src="192.0.2.1", dst="127.0.0.1") /
scapy.ICMP(type=3, code=0) /
scapy.IP(src="127.0.0.1", dst="127.0.0.1") /
@@ -183,9 +203,7 @@ class Ping6Test(net_test.NetworkTest):
scapy.ICMPv6EchoRequest(id=port, seq=1, data="foobarbaz"))
# An unreachable matching the ID of a socket of the wrong protocol
- # shouldn't crash. We can only test this using IPv6 unreachables and IPv4
- # ping sockets, because IPv4 packets sent by scapy.send() on loopback don't
- # appear to be received by the kernel.)
+ # shouldn't crash.
s = net_test.IPv4PingSocket()
s.connect(("127.0.0.1", 12345))
_, port = s.getsockname()
@@ -506,4 +524,3 @@ class Ping6Test(net_test.NetworkTest):
if __name__ == "__main__":
unittest.main()
-
diff --git a/tests/net_test/sendmsg.py b/tests/net_test/sendmsg.py
index bbc46ec3..422a16a1 100644
--- a/tests/net_test/sendmsg.py
+++ b/tests/net_test/sendmsg.py
@@ -1,4 +1,16 @@
-#!/usr/bin/python
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
"""Python wrapper for sendmsg."""
diff --git a/tests/net_test/srcaddr_selection_test.py b/tests/net_test/srcaddr_selection_test.py
index adce7336..f6df603a 100755
--- a/tests/net_test/srcaddr_selection_test.py
+++ b/tests/net_test/srcaddr_selection_test.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import errno
import os