Skip to content

Commit

Permalink
tests: Ensure threads' hybrid stacks are complete
Browse files Browse the repository at this point in the history
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 <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and pablogsal committed Oct 28, 2022
1 parent 771baac commit ab31d4c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/integration/test_native_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys
import textwrap
import threading
from pathlib import Path

import pytest
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab31d4c

Please sign in to comment.