Skip to content

Commit

Permalink
pythongh-80931: Skip some socket tests while hunting for refleaks on …
Browse files Browse the repository at this point in the history
…macOS
  • Loading branch information
ronaldoussoren committed Jan 14, 2024
1 parent c6ca562 commit 87330e7
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
except ImportError:
_socket = None

_hunting_for_refleaks = None
def hunting_for_refleaks():
"""
Return true iff running tests while hunting for refleaks
"""
from test.libregrtest.runtests import RunTests
import gc

global _hunting_for_refleaks

if _hunting_for_refleaks is None:
for value in gc.get_objects():
if isinstance(value, RunTests):
_hunting_for_refleaks = (value.hunt_refleak is not None)
break
else:
_hunting_for_refleaks = False

return _hunting_for_refleaks



def get_cid():
if fcntl is None:
return None
Expand Down Expand Up @@ -3817,47 +3839,77 @@ def checkTruncatedHeader(self, result, ignoreflags=0):
def testCmsgTruncNoBufSize(self):
# Check that no ancillary data is received when no buffer size
# is specified.
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG)),
# BSD seems to set MSG_CTRUNC only
# if an item has been partially
# received.
ignoreflags=socket.MSG_CTRUNC)

def _testCmsgTruncNoBufSize(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

def testCmsgTrunc0(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

# Check that no ancillary data is received when buffer size is 0.
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 0),
ignoreflags=socket.MSG_CTRUNC)

def _testCmsgTrunc0(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

# Check that no ancillary data is returned for various non-zero
# (but still too small) buffer sizes.

def testCmsgTrunc1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 1))

def _testCmsgTrunc1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

def testCmsgTrunc2Int(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

# The cmsghdr structure has at least three members, two of
# which are ints, so we still shouldn't see any ancillary
# data.
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
SIZEOF_INT * 2))

def _testCmsgTrunc2Int(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

def testCmsgTruncLen0Minus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
socket.CMSG_LEN(0) - 1))

def _testCmsgTruncLen0Minus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

# The following tests try to truncate the control message in the
Expand Down Expand Up @@ -3888,29 +3940,53 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
self.checkFDs(fds)

def testCmsgTruncLen0(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0), maxdata=0)

def _testCmsgTruncLen0(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

def testCmsgTruncLen0Plus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0) + 1, maxdata=1)

def _testCmsgTruncLen0Plus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(2)

def testCmsgTruncLen1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(SIZEOF_INT),
maxdata=SIZEOF_INT)

def _testCmsgTruncLen1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(2)

def testCmsgTruncLen2Minus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(2 * SIZEOF_INT) - 1,
maxdata=(2 * SIZEOF_INT) - 1)

def _testCmsgTruncLen2Minus1(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(2)


Expand Down

0 comments on commit 87330e7

Please sign in to comment.