GH-129386: Use symbolic constants for specialization tests (GH-129415)

This commit is contained in:
Brandt Bucher 2025-01-29 10:49:58 -08:00 committed by GitHub
parent 99ed3025fe
commit 002c4e2982
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 152 additions and 132 deletions

View file

@ -14,6 +14,7 @@ import test.support
from test.support import requires_specialization_ft, script_helper
_testcapi = test.support.import_helper.import_module("_testcapi")
_testinternalcapi = test.support.import_helper.import_module("_testinternalcapi")
PAIR = (0,1)
@ -897,13 +898,13 @@ class ExceptionMonitoringTest(CheckEvents):
# re-specialize immediately, so that we can we can test the
# unspecialized version of the loop first.
# Note: this assumes that we don't specialize loops over sets.
implicit_stop_iteration(set(range(100)))
implicit_stop_iteration(set(range(_testinternalcapi.SPECIALIZATION_THRESHOLD)))
# This will record a RAISE event for the StopIteration.
self.check_events(implicit_stop_iteration, expected, recorders=recorders)
# Now specialize, so that we see a STOP_ITERATION event.
for _ in range(100):
for _ in range(_testinternalcapi.SPECIALIZATION_COOLDOWN):
implicit_stop_iteration()
# This will record a STOP_ITERATION event for the StopIteration.
@ -1057,7 +1058,7 @@ class ExceptionMonitoringTest(CheckEvents):
except ValueError:
pass
for _ in range(100):
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
f()
recorders = (
ReturnRecorder,
@ -2033,8 +2034,8 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
sys.monitoring.set_events(TEST_TOOL, E.PY_RESUME)
def make_foo_optimized_then_set_event():
for i in range(100):
Foo(i == 99)
for i in range(_testinternalcapi.SPECIALIZATION_THRESHOLD + 1):
Foo(i == _testinternalcapi.SPECIALIZATION_THRESHOLD)
try:
make_foo_optimized_then_set_event()
@ -2106,9 +2107,9 @@ class TestTier2Optimizer(CheckEvents):
set_events = sys.monitoring.set_events
line = E.LINE
i = 0
for i in range(551):
# Turn on events without branching once i reaches 500.
set_events(TEST_TOOL, line * int(i >= 500))
for i in range(_testinternalcapi.SPECIALIZATION_THRESHOLD + 51):
# Turn on events without branching once i reaches _testinternalcapi.SPECIALIZATION_THRESHOLD.
set_events(TEST_TOOL, line * int(i >= _testinternalcapi.SPECIALIZATION_THRESHOLD))
pass
pass
pass