Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
network - It is okay to run tests that use external network
resource, e.g. testing SSL support for sockets.

netraw - It is okay to run tests that create raw sockets. These
tests may require elevated privileges.

decimal - Test the decimal module against a large suite that
verifies compliance with standards.

Expand Down
5 changes: 4 additions & 1 deletion Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@
#
# - extralagefile (ex: test_zipfile64): really too slow to be enabled
# "by default"
# - netraw: raw sockets may require elevated privileges and can trigger
# behavior monitoring systems.
# - tzdata: while needed to validate fully test_datetime, it makes
# test_datetime too slow (15-20 min on some buildbots) and so is disabled by
# default (see bpo-30822).
RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata', 'xpickle', 'wantobjects')
RESOURCE_NAMES = ALL_RESOURCES + (
'extralargefile', 'netraw', 'tzdata', 'xpickle', 'wantobjects')


# Types for types hints
Expand Down
26 changes: 26 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ def connection_lost(self, exc):
self.done.set_result(None)


class FakeRawSocket(socket.socket):

@property
def type(self):
return socket.SOCK_RAW


class MyReadPipeProto(asyncio.Protocol):
done = None

Expand Down Expand Up @@ -1496,6 +1503,25 @@ def test_create_datagram_endpoint_sock(self):
tr.close()
self.loop.run_until_complete(pr.done)

def test_create_datagram_endpoint_sock_raw(self):
if support.is_resource_enabled('netraw'):
sock = socket.socket(
socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
else:
sock = FakeRawSocket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('127.0.0.1', 0))

self.assertEqual(sock.type, socket.SOCK_RAW)
with sock:
f = self.loop.create_datagram_endpoint(
lambda: MyDatagramProto(loop=self.loop), sock=sock)
tr, pr = self.loop.run_until_complete(f)
self.assertIsInstance(tr, asyncio.Transport)
self.assertIsInstance(pr, MyDatagramProto)
tr.close()
self.loop.run_until_complete(pr.done)
self.assertEqual(sock.fileno(), -1)

def test_datagram_send_to_non_listening_address(self):
# see:
# https://github.com/python/cpython/issues/91227
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ def test_use(self):
# test another resource which is not part of "all"
ns = self.parse_args([opt, 'extralargefile'])
self.assertEqual(ns.use_resources, {'extralargefile': None})
ns = self.parse_args([opt, 'netraw'])
self.assertEqual(ns.use_resources, {'netraw': None})
self.assertNotIn('netraw', cmdline.ALL_RESOURCES)

# test resource with value
ns = self.parse_args([opt, 'xpickle=2.7'])
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,13 @@ def requireSocket(*args):

class GeneralModuleTests(unittest.TestCase):

def test_create_raw_socket(self):
support.requires('netraw')
sock = socket.socket(
socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
with sock:
self.assertEqual(sock.type, socket.SOCK_RAW)

@unittest.skipUnless(_socket is not None, 'need _socket module')
def test_socket_type(self):
self.assertTrue(gc.is_tracked(_socket.socket))
Expand Down
Loading