[pypy-commit] pypy test-AF_NETLINK: Add a test for AF_NETLINK sockets

Vincent Legoll pypy.commits at gmail.com
Wed Dec 16 10:20:27 EST 2015


Author: Vincent Legoll <vincent.legoll at idgrilles.fr>
Branch: test-AF_NETLINK
Changeset: r81351:ddec8c4b70b1
Date: 2015-12-16 13:41 +0100
http://bitbucket.org/pypy/pypy/changeset/ddec8c4b70b1/

Log:	Add a test for AF_NETLINK sockets

	This was asked for by Armin Rigo in Issue #1942

diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -627,6 +627,26 @@
         self.foo = _socket.socket()
 
 
+class AppTestNetlink:
+    def setup_class(cls):
+        if not hasattr(os, 'getpid'):
+            py.test.skip("AF_NETLINK needs os.getpid()")
+        w_ok = space.appexec([], "(): import _socket; " +
+                                 "return hasattr(_socket, 'AF_NETLINK')")
+        if not space.is_true(w_ok):
+            py.test.skip("no AF_NETLINK on this platform")
+        cls.space = space
+
+    def test_connect_to_kernel_netlink_routing_socket(self):
+        import _socket, os
+        s = _socket.socket(_socket.AF_NETLINK, _socket.SOCK_DGRAM, _socket.NETLINK_ROUTE)
+        assert s.getsockname() == (0L, 0L)
+        s.bind((0, 0))
+        a, b = s.getsockname()
+        assert a == os.getpid()
+        assert b == 0
+ 
+
 class AppTestPacket:
     def setup_class(cls):
         if not hasattr(os, 'getuid') or os.getuid() != 0:


More information about the pypy-commit mailing list