Skip to content

Commit 305bae6

Browse files
godlygeekpablogsal
authored andcommitted
tests: Exercise fallback to /proc/PID/mem
Add an environment variable to force reads from `/proc/PID/mem` instead of using `process_vm_readv` in order to give us a way to exercise both paths on the same kernel. Signed-off-by: Matt Wozniski <[email protected]>
1 parent 166b4d2 commit 305bae6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/pystack/_pystack/mem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ ProcessMemoryManager::ProcessMemoryManager(pid_t pid)
228228
ssize_t
229229
ProcessMemoryManager::readChunk(remote_addr_t addr, size_t len, char* dst) const
230230
{
231-
if (d_memfile) {
231+
if (d_memfile || getenv("_PYSTACK_NO_PROCESS_VM_READV") != nullptr) {
232232
return readChunkThroughMemFile(addr, len, dst);
233233
} else {
234234
return readChunkDirect(addr, len, dst);

tests/integration/test_smoke.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@
3838

3939
@pytest.mark.parametrize("method", STACK_METHODS)
4040
@pytest.mark.parametrize("blocking", [True, False], ids=["blocking", "non-blocking"])
41-
def test_simple_execution(method, blocking, tmpdir):
41+
@pytest.mark.parametrize(
42+
"use_process_vm_readv", [True, False], ids=["process_vm_readv", "/proc/PID/mem"]
43+
)
44+
def test_simple_execution(method, blocking, use_process_vm_readv, tmpdir, monkeypatch):
4245
"""Test that we can retrieve the thread state of a single process.
4346
4447
This test is specially useful to run under valgrind or similar tools and to
4548
quickly check that the very basic functionality works as expected.
4649
"""
4750

51+
# GIVEN
52+
env_var = "_PYSTACK_NO_PROCESS_VM_READV"
53+
if use_process_vm_readv:
54+
monkeypatch.delenv(env_var, raising=False)
55+
else:
56+
monkeypatch.setenv(env_var, "1")
57+
4858
# WHEN
4959
with spawn_child_process(
5060
sys.executable, TEST_SINGLE_THREAD_FILE, tmpdir

0 commit comments

Comments
 (0)