OSDN Git Service

Clean up code in preparation for AOSP.
authorLorenzo Colitti <lorenzo@google.com>
Wed, 17 Dec 2014 06:14:56 +0000 (15:14 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Mon, 2 Feb 2015 08:47:30 +0000 (17:47 +0900)
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

tests/net_test/cstruct.py
tests/net_test/iproute.py
tests/net_test/multinetwork_base.py
tests/net_test/multinetwork_test.py
tests/net_test/net_test.py
tests/net_test/ping6_test.py
tests/net_test/sendmsg.py
tests/net_test/srcaddr_selection_test.py

index 36de22a..266a5a0 100644 (file)
@@ -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:
index dec59d4..ca05193 100644 (file)
@@ -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."""
 
index 2bd2740..54934d3 100644 (file)
@@ -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
index 63c0e46..b66d765 100755 (executable)
@@ -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
index f4d077c..a87b71b 100755 (executable)
@@ -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
index 3587167..ff680b8 100755 (executable)
@@ -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()
-
index bbc46ec..422a16a 100644 (file)
@@ -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."""
 
index adce733..f6df603 100755 (executable)
@@ -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