diff --git a/tests/integration/test_native_tracking.py b/tests/integration/test_native_tracking.py index fee47fe0e0..08cb939bc3 100644 --- a/tests/integration/test_native_tracking.py +++ b/tests/integration/test_native_tracking.py @@ -4,6 +4,7 @@ import subprocess import sys import textwrap +import threading from pathlib import Path import pytest @@ -476,6 +477,34 @@ def test_hybrid_stack_in_a_thread(tmpdir, monkeypatch): assert expected_symbols == [stack[0] for stack in valloc.hybrid_stack_trace()][:3] +def test_hybrid_stack_of_python_thread_starts_with_native_frames(tmp_path): + """Ensure there are native frames above a thread's first Python frame.""" + # GIVEN + allocator = MemoryAllocator() + output = tmp_path / "test.bin" + + def func(): + allocator.valloc(1234) + allocator.free() + + # WHEN + with Tracker(output, native_traces=True): + thread = threading.Thread(target=func) + thread.start() + thread.join() + + # THEN + allocations = list(FileReader(output).get_allocation_records()) + + vallocs = [ + event + for event in allocations + if event.size == 1234 and event.allocator == AllocatorType.VALLOC + ] + (valloc,) = vallocs + assert not valloc.hybrid_stack_trace()[-1][1].endswith(".py") + + @pytest.mark.parametrize("native_traces", [True, False]) def test_native_tracing_header(native_traces, tmpdir): # GIVEN