Skip to content

Commit 5d53a15

Browse files
committed
Fix test when the JIT is enabled only with the interpreter
1 parent 769400b commit 5d53a15

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

Lib/test/test_frame_pointer_unwind.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def _classify_stack(stack, jit_enabled):
8686
def _annotate_unwind():
8787
stack = _build_stack_and_unwind()
8888
jit_enabled = hasattr(sys, "_jit") and sys._jit.is_enabled()
89+
jit_backend = _testinternalcapi.get_jit_backend()
8990
ranges = _testinternalcapi.get_jit_code_ranges() if jit_enabled else []
91+
jit_code_ranges = len(ranges)
9092
if jit_enabled and ranges:
9193
print("JIT ranges:")
9294
for start, end in ranges:
@@ -101,6 +103,8 @@ def _annotate_unwind():
101103
"python_frames": python_frames,
102104
"jit_frames": jit_frames,
103105
"other_frames": other_frames,
106+
"jit_code_ranges": jit_code_ranges,
107+
"jit_backend": jit_backend,
104108
})
105109

106110

@@ -163,18 +167,27 @@ def test_manual_unwind_respects_frame_pointers(self):
163167
result = _manual_unwind_length(**env)
164168
jit_frames = result["jit_frames"]
165169
python_frames = result.get("python_frames", 0)
170+
jit_backend = result.get("jit_backend")
166171
if self.frame_pointers_expected:
167172
self.assertGreater(
168173
python_frames,
169174
0,
170175
f"expected to find Python frames on {self.machine} with env {env}",
171176
)
172177
if using_jit:
173-
self.assertGreater(
174-
jit_frames,
175-
0,
176-
f"expected to find JIT frames on {self.machine} with env {env}",
177-
)
178+
if jit_backend == "jit":
179+
self.assertGreater(
180+
jit_frames,
181+
0,
182+
f"expected to find JIT frames on {self.machine} with env {env}",
183+
)
184+
else:
185+
# jit_backend is "interpreter" or not present
186+
self.assertEqual(
187+
jit_frames,
188+
0,
189+
f"unexpected JIT frames counted on {self.machine} with env {env}",
190+
)
178191
else:
179192
self.assertEqual(
180193
jit_frames,

Modules/_testinternalcapi.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ get_jit_code_ranges(PyObject *self, PyObject *Py_UNUSED(args))
306306
return ranges;
307307
}
308308

309+
static PyObject *
310+
get_jit_backend(PyObject *self, PyObject *Py_UNUSED(args))
311+
{
312+
#ifdef _Py_JIT
313+
return PyUnicode_FromString("jit");
314+
#elif defined(_Py_TIER2)
315+
return PyUnicode_FromString("interpreter");
316+
#else
317+
Py_RETURN_NONE;
318+
#endif
319+
}
320+
309321
static PyObject *
310322
manual_unwind_from_fp(uintptr_t *frame_pointer)
311323
{
@@ -2828,6 +2840,7 @@ static PyMethodDef module_functions[] = {
28282840
{"get_stack_margin", get_stack_margin, METH_NOARGS},
28292841
{"classify_stack_addresses", classify_stack_addresses, METH_VARARGS},
28302842
{"get_jit_code_ranges", get_jit_code_ranges, METH_NOARGS},
2843+
{"get_jit_backend", get_jit_backend, METH_NOARGS},
28312844
{"manual_frame_pointer_unwind", manual_frame_pointer_unwind, METH_NOARGS},
28322845
{"test_bswap", test_bswap, METH_NOARGS},
28332846
{"test_popcount", test_popcount, METH_NOARGS},

0 commit comments

Comments
 (0)