From ab31d4c995e83b0bf6020958d2a12903d2b322db Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Thu, 27 Oct 2022 21:38:26 -0400 Subject: [PATCH] tests: Ensure threads' hybrid stacks are complete Ensure that the hybrid stack of an allocation performed in a Python thread does not terminate at the first Python frame, but rather continues and captures the native calls above it. Signed-off-by: Matt Wozniski --- tests/integration/test_native_tracking.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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