Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
gh-151029: Tidy deleted mapping remote exec tests
  • Loading branch information
pablogsal committed Jun 27, 2026
commit 89525a1f131bae79f1822663ed545f0769b7a4b8
43 changes: 18 additions & 25 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,19 @@ def _run_remote_exec_test(self, script_code, python_args=None, env=None,
proc.terminate()
proc.wait(timeout=SHORT_TIMEOUT)

def _run_remote_exec_with_deleted_mapping(self, deleted_path, **kwargs):
def delete_loaded_mapping(proc):
os_helper.unlink(deleted_path)
with open(f'/proc/{proc.pid}/maps', encoding='utf-8') as maps:
self.assertIn(f'{deleted_path} (deleted)', maps.read())

script = 'print("Remote script executed successfully!")'
returncode, stdout, stderr = self._run_remote_exec_test(
script, after_ready=delete_loaded_mapping, **kwargs)
self.assertEqual(returncode, 0)
self.assertIn(b"Remote script executed successfully!", stdout)
self.assertEqual(stderr, b"")

def test_remote_exec(self):
"""Test basic remote exec functionality"""
script = 'print("Remote script executed successfully!")'
Expand Down Expand Up @@ -2239,18 +2252,8 @@ def test_remote_exec_deleted_libpython(self):
env['LD_LIBRARY_PATH'] = lib_dir if not ld_library_path else (
lib_dir + os.pathsep + ld_library_path)

def delete_loaded_libpython(proc):
os_helper.unlink(copied_libpython)
with open(f'/proc/{proc.pid}/maps', encoding='utf-8') as maps:
self.assertIn(f'{copied_libpython} (deleted)',
maps.read())

script = 'print("Remote script executed successfully!")'
returncode, stdout, stderr = self._run_remote_exec_test(
script, env=env, after_ready=delete_loaded_libpython)
self.assertEqual(returncode, 0)
self.assertIn(b"Remote script executed successfully!", stdout)
self.assertEqual(stderr, b"")
self._run_remote_exec_with_deleted_mapping(copied_libpython,
env=env)

@unittest.skipUnless(sys.platform == 'linux', 'Linux-only regression test')
@unittest.skipUnless(
Expand Down Expand Up @@ -2287,19 +2290,9 @@ def test_remote_exec_deleted_static_executable(self):
os.path.basename(sys.executable))
shutil.copy2(sys.executable, copied_python)

def delete_loaded_executable(proc):
os_helper.unlink(copied_python)
with open(f'/proc/{proc.pid}/maps', encoding='utf-8') as maps:
self.assertIn(f'{copied_python} (deleted)',
maps.read())

script = 'print("Remote script executed successfully!")'
returncode, stdout, stderr = self._run_remote_exec_test(
script, python_args=['-S'], python_executable=copied_python,
after_ready=delete_loaded_executable)
self.assertEqual(returncode, 0)
self.assertIn(b"Remote script executed successfully!", stdout)
self.assertEqual(stderr, b"")
self._run_remote_exec_with_deleted_mapping(
copied_python, python_args=['-S'],
python_executable=copied_python)

def test_remote_exec_in_process_without_debug_fails_envvar(self):
"""Test remote exec in a process without remote debugging enabled"""
Expand Down
3 changes: 3 additions & 0 deletions Python/remote_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,9 @@ scan_linux_mapping_for_pyruntime_cookie(
if (_Py_RemoteDebug_HasPermissionError()) {
goto exit;
}
// A candidate mapping can disappear or contain unreadable holes while
// the target process keeps running. Treat those as non-matches and
// keep scanning other candidate mappings.
PyErr_Clear();
}
else {
Expand Down
Loading