Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test_huntrleaks under -Xuops
This time by disabling the optimizer.
  • Loading branch information
gvanrossum committed Sep 8, 2023
commit 4f1684c65ca1a91d98af8c052247f8141f2d32ff
17 changes: 17 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
"Py_DEBUG", "EXCEEDS_RECURSION_LIMIT", "C_RECURSION_LIMIT",
"skip_on_s390x",
"without_optimizer",
]


Expand Down Expand Up @@ -2538,3 +2539,19 @@ def adjust_int_max_str_digits(max_digits):
'skipped on s390x')

Py_TRACE_REFS = hasattr(sys, 'getobjects')

# Decorator to disable optimizer while a function run
def without_optimizer(func):
try:
import _testinternalcapi
except ImportError:
return func
@functools.wraps(func)
def wrapper(*args, **kwargs):
save_opt = _testinternalcapi.get_optimizer()
try:
_testinternalcapi.set_optimizer(None)
return func(*args, **kwargs)
finally:
_testinternalcapi.set_optimizer(save_opt)
return wrapper
7 changes: 4 additions & 3 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import unittest
from test import libregrtest
from test import support
from test.support import os_helper, TestStats
from test.support import os_helper, TestStats, without_optimizer
from test.libregrtest import utils, setup
from test.libregrtest.runtest import normalize_test_name

Expand Down Expand Up @@ -1018,17 +1018,18 @@ def test_run(self):
stats=TestStats(4, 1),
forever=True)

@without_optimizer
def check_leak(self, code, what):
test = self.create_test('huntrleaks', code=code)

filename = 'reflog.txt'
self.addCleanup(os_helper.unlink, filename)
output = self.run_tests('--huntrleaks', '6:3:', test,
output = self.run_tests('--huntrleaks', '3:3:', test,
exitcode=EXITCODE_BAD_TEST,
stderr=subprocess.STDOUT)
self.check_executed_tests(output, [test], failed=test, stats=1)

line = 'beginning 9 repetitions\n123456789\n.........\n'
line = 'beginning 6 repetitions\n123456\n......\n'
self.check_line(output, re.escape(line))

line2 = '%s leaked [1, 1, 1] %s, sum=3\n' % (test, what)
Expand Down