Skip to content

Commit 87330e7

Browse files
gh-80931: Skip some socket tests while hunting for refleaks on macOS
1 parent c6ca562 commit 87330e7

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Lib/test/test_socket.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@
5252
except ImportError:
5353
_socket = None
5454

55+
_hunting_for_refleaks = None
56+
def hunting_for_refleaks():
57+
"""
58+
Return true iff running tests while hunting for refleaks
59+
"""
60+
from test.libregrtest.runtests import RunTests
61+
import gc
62+
63+
global _hunting_for_refleaks
64+
65+
if _hunting_for_refleaks is None:
66+
for value in gc.get_objects():
67+
if isinstance(value, RunTests):
68+
_hunting_for_refleaks = (value.hunt_refleak is not None)
69+
break
70+
else:
71+
_hunting_for_refleaks = False
72+
73+
return _hunting_for_refleaks
74+
75+
76+
5577
def get_cid():
5678
if fcntl is None:
5779
return None
@@ -3817,47 +3839,77 @@ def checkTruncatedHeader(self, result, ignoreflags=0):
38173839
def testCmsgTruncNoBufSize(self):
38183840
# Check that no ancillary data is received when no buffer size
38193841
# is specified.
3842+
if sys.platform == "darwin" and hunting_for_refleaks():
3843+
return
3844+
38203845
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG)),
38213846
# BSD seems to set MSG_CTRUNC only
38223847
# if an item has been partially
38233848
# received.
38243849
ignoreflags=socket.MSG_CTRUNC)
38253850

38263851
def _testCmsgTruncNoBufSize(self):
3852+
if sys.platform == "darwin" and hunting_for_refleaks():
3853+
return
3854+
38273855
self.createAndSendFDs(1)
38283856

38293857
def testCmsgTrunc0(self):
3858+
if sys.platform == "darwin" and hunting_for_refleaks():
3859+
return
3860+
38303861
# Check that no ancillary data is received when buffer size is 0.
38313862
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 0),
38323863
ignoreflags=socket.MSG_CTRUNC)
38333864

38343865
def _testCmsgTrunc0(self):
3866+
if sys.platform == "darwin" and hunting_for_refleaks():
3867+
return
3868+
38353869
self.createAndSendFDs(1)
38363870

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

38403874
def testCmsgTrunc1(self):
3875+
if sys.platform == "darwin" and hunting_for_refleaks():
3876+
return
3877+
38413878
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 1))
38423879

38433880
def _testCmsgTrunc1(self):
3881+
if sys.platform == "darwin" and hunting_for_refleaks():
3882+
return
3883+
38443884
self.createAndSendFDs(1)
38453885

38463886
def testCmsgTrunc2Int(self):
3887+
if sys.platform == "darwin" and hunting_for_refleaks():
3888+
return
3889+
38473890
# The cmsghdr structure has at least three members, two of
38483891
# which are ints, so we still shouldn't see any ancillary
38493892
# data.
38503893
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
38513894
SIZEOF_INT * 2))
38523895

38533896
def _testCmsgTrunc2Int(self):
3897+
if sys.platform == "darwin" and hunting_for_refleaks():
3898+
return
3899+
38543900
self.createAndSendFDs(1)
38553901

38563902
def testCmsgTruncLen0Minus1(self):
3903+
if sys.platform == "darwin" and hunting_for_refleaks():
3904+
return
3905+
38573906
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
38583907
socket.CMSG_LEN(0) - 1))
38593908

38603909
def _testCmsgTruncLen0Minus1(self):
3910+
if sys.platform == "darwin" and hunting_for_refleaks():
3911+
return
3912+
38613913
self.createAndSendFDs(1)
38623914

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

38903942
def testCmsgTruncLen0(self):
3943+
if sys.platform == "darwin" and hunting_for_refleaks():
3944+
return
3945+
38913946
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0), maxdata=0)
38923947

38933948
def _testCmsgTruncLen0(self):
3949+
if sys.platform == "darwin" and hunting_for_refleaks():
3950+
return
3951+
38943952
self.createAndSendFDs(1)
38953953

38963954
def testCmsgTruncLen0Plus1(self):
3955+
if sys.platform == "darwin" and hunting_for_refleaks():
3956+
return
3957+
38973958
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0) + 1, maxdata=1)
38983959

38993960
def _testCmsgTruncLen0Plus1(self):
3961+
if sys.platform == "darwin" and hunting_for_refleaks():
3962+
return
3963+
39003964
self.createAndSendFDs(2)
39013965

39023966
def testCmsgTruncLen1(self):
3967+
if sys.platform == "darwin" and hunting_for_refleaks():
3968+
return
3969+
39033970
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(SIZEOF_INT),
39043971
maxdata=SIZEOF_INT)
39053972

39063973
def _testCmsgTruncLen1(self):
3974+
if sys.platform == "darwin" and hunting_for_refleaks():
3975+
return
3976+
39073977
self.createAndSendFDs(2)
39083978

39093979
def testCmsgTruncLen2Minus1(self):
3980+
if sys.platform == "darwin" and hunting_for_refleaks():
3981+
return
3982+
39103983
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(2 * SIZEOF_INT) - 1,
39113984
maxdata=(2 * SIZEOF_INT) - 1)
39123985

39133986
def _testCmsgTruncLen2Minus1(self):
3987+
if sys.platform == "darwin" and hunting_for_refleaks():
3988+
return
3989+
39143990
self.createAndSendFDs(2)
39153991

39163992

0 commit comments

Comments
 (0)