summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPier-Yves Lessard <py.lessard@gmail.com>2017-08-28 08:32:44 (GMT)
committerChristian Heimes <christian@python.org>2017-08-28 08:32:44 (GMT)
commita30f6d45ac3e72761b96a8df0527182029eaee24 (patch)
tree78979f1ea774a03b5f895f4a661a829a247f3a83 /Lib
parented94a8b2851914bcda3a77b28b25517b8baa91e6 (diff)
downloadcpython-a30f6d45ac3e72761b96a8df0527182029eaee24.zip
cpython-a30f6d45ac3e72761b96a8df0527182029eaee24.tar.gz
cpython-a30f6d45ac3e72761b96a8df0527182029eaee24.tar.bz2
bpo-30987 - Support for ISO-TP protocol in SocketCAN (#2956)
* Added support for CAN_ISOTP protocol * Added unit tests for CAN ISOTP * Updated documentation for ISO-TP protocol * Removed trailing whitespace in documentation * Added blurb NEWS.d file * updated Misc/ACKS * Fixed broken unit test that was using isotp const outside of skippable section * Removed dependecy over third party project * Added implementation for getsockname + unit tests * Missing newline at end of ACKS file * Accidentally inserted a type in ACKS file * Followed tiran changes review #1 recommendations * Added spaces after comma
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index f28f7d6..8423488 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -55,6 +55,16 @@ def _have_socket_can():
s.close()
return True
+def _have_socket_can_isotp():
+ """Check whether CAN ISOTP sockets are supported on this host."""
+ try:
+ s = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP)
+ except (AttributeError, OSError):
+ return False
+ else:
+ s.close()
+ return True
+
def _have_socket_rds():
"""Check whether RDS sockets are supported on this host."""
try:
@@ -77,6 +87,8 @@ def _have_socket_alg():
HAVE_SOCKET_CAN = _have_socket_can()
+HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
+
HAVE_SOCKET_RDS = _have_socket_rds()
HAVE_SOCKET_ALG = _have_socket_alg()
@@ -1709,6 +1721,49 @@ class CANTest(ThreadedCANSocketTest):
self.assertEqual(bytes_sent, len(header_plus_frame))
+@unittest.skipUnless(HAVE_SOCKET_CAN_ISOTP, 'CAN ISOTP required for this test.')
+class ISOTPTest(unittest.TestCase):
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.interface = "vcan0"
+
+ def testCrucialConstants(self):
+ socket.AF_CAN
+ socket.PF_CAN
+ socket.CAN_ISOTP
+ socket.SOCK_DGRAM
+
+ def testCreateSocket(self):
+ with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
+ pass
+
+ @unittest.skipUnless(hasattr(socket, "CAN_ISOTP"),
+ 'socket.CAN_ISOTP required for this test.')
+ def testCreateISOTPSocket(self):
+ with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as s:
+ pass
+
+ def testTooLongInterfaceName(self):
+ # most systems limit IFNAMSIZ to 16, take 1024 to be sure
+ with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as s:
+ with self.assertRaisesRegex(OSError, 'interface name too long'):
+ s.bind(('x' * 1024, 1, 2))
+
+ def testBind(self):
+ try:
+ with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as s:
+ addr = self.interface, 0x123, 0x456
+ s.bind(addr)
+ self.assertEqual(s.getsockname(), addr)
+ except OSError as e:
+ if e.errno == errno.ENODEV:
+ self.skipTest('network interface `%s` does not exist' %
+ self.interface)
+ else:
+ raise
+
+
@unittest.skipUnless(HAVE_SOCKET_RDS, 'RDS sockets required for this test.')
class BasicRDSTest(unittest.TestCase):