Skip to content

Commit 27185f9

Browse files
authored
gh-92031, test_embed: Improve test for unquickening static code (#92440)
1 parent 6de78ef commit 27185f9

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

Lib/test/test_embed.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -343,19 +343,39 @@ def test_finalize_structseq(self):
343343
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
344344
self.assertEqual(out, 'Tests passed\n' * INIT_LOOPS)
345345

346-
@support.skip_if_pgo_task
347346
def test_quickened_static_code_gets_unquickened_at_Py_FINALIZE(self):
348347
# https://github.com/python/cpython/issues/92031
349-
code = """if 1:
350-
from importlib._bootstrap import _handle_fromlist
351-
import dis
352-
for name in dis.opmap:
353-
# quicken this frozen code object.
354-
_handle_fromlist(dis, [name], lambda *args: None)
355-
"""
348+
349+
# Do these imports outside of the code string to avoid using
350+
# importlib too much from within the code string, so that
351+
# _handle_fromlist doesn't get quickened until we intend it to.
352+
from dis import _all_opmap
353+
resume = _all_opmap["RESUME"]
354+
resume_quick = _all_opmap["RESUME_QUICK"]
355+
from test.test_dis import QUICKENING_WARMUP_DELAY
356+
357+
code = textwrap.dedent(f"""\
358+
import importlib._bootstrap
359+
func = importlib._bootstrap._handle_fromlist
360+
code = func.__code__
361+
362+
# Assert initially unquickened.
363+
# Use sets to account for byte order.
364+
if set(code._co_code_adaptive[:2]) != set([{resume}, 0]):
365+
raise AssertionError()
366+
367+
for i in range({QUICKENING_WARMUP_DELAY}):
368+
func(importlib._bootstrap, ["x"], lambda *args: None)
369+
370+
# Assert quickening worked
371+
if set(code._co_code_adaptive[:2]) != set([{resume_quick}, 0]):
372+
raise AssertionError()
373+
374+
print("Tests passed")
375+
""")
356376
run = self.run_embedded_interpreter
357-
for i in range(50):
358-
out, err = run("test_repeated_init_exec", code, timeout=60)
377+
out, err = run("test_repeated_init_exec", code)
378+
self.assertEqual(out, 'Tests passed\n' * INIT_LOOPS)
359379

360380
def test_ucnhash_capi_reset(self):
361381
# bpo-47182: unicodeobject.c:ucnhash_capi was not reset on shutdown.

0 commit comments

Comments
 (0)