-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-115773: Add tests to exercise the _Py_DebugOffsets structure #115774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a4ebf4e
bpo-115773: Add tests to exercise the _Py_DebugOffsets structure
pablogsal d3af59d
Apply suggestions from code review
pablogsal 18fb5aa
Update Modules/_testexternalinspection.c
pablogsal 11dc915
fixup! Update Modules/_testexternalinspection.c
pablogsal a12e9ae
fixup! fixup! Update Modules/_testexternalinspection.c
pablogsal 1d4c857
fixup! fixup! fixup! Update Modules/_testexternalinspection.c
pablogsal 2a9c43f
fixup! fixup! fixup! fixup! Update Modules/_testexternalinspection.c
pablogsal 55bf6ac
Update Modules/_testexternalinspection.c
pablogsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import unittest | ||
import os | ||
import textwrap | ||
import importlib | ||
import sys | ||
from test.support import os_helper, SHORT_TIMEOUT | ||
from test.support.script_helper import make_script | ||
|
||
import subprocess | ||
|
||
PROCESS_VM_READV_SUPPORTED = False | ||
|
||
try: | ||
from _testexternalinspection import PROCESS_VM_READV_SUPPORTED | ||
from _testexternalinspection import get_stack_trace | ||
except ImportError: | ||
unittest.skip("Test only runs when _testexternalinspection is available") | ||
|
||
def _make_test_script(script_dir, script_basename, source): | ||
to_return = make_script(script_dir, script_basename, source) | ||
importlib.invalidate_caches() | ||
return to_return | ||
|
||
class TestGetStackTrace(unittest.TestCase): | ||
|
||
@unittest.skipIf(sys.platform != "darwin" and sys.platform != "linux", "Test only runs on Linux and MacOS") | ||
@unittest.skipIf(sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED, "Test only runs on Linux with process_vm_readv support") | ||
def test_remote_stack_trace(self): | ||
# Spawn a process with some realistic Python code | ||
script = textwrap.dedent("""\ | ||
import time, sys, os | ||
def bar(): | ||
for x in range(100): | ||
if x == 50: | ||
baz() | ||
def baz(): | ||
foo() | ||
|
||
def foo(): | ||
fifo = sys.argv[1] | ||
with open(sys.argv[1], "w") as fifo: | ||
fifo.write("ready") | ||
time.sleep(1000) | ||
|
||
bar() | ||
""") | ||
stack_trace = None | ||
with os_helper.temp_dir() as work_dir: | ||
script_dir = os.path.join(work_dir, "script_pkg") | ||
os.mkdir(script_dir) | ||
fifo = f"{work_dir}/the_fifo" | ||
os.mkfifo(fifo) | ||
script_name = _make_test_script(script_dir, 'script', script) | ||
try: | ||
p = subprocess.Popen([sys.executable, script_name, str(fifo)]) | ||
with open(fifo, "r") as fifo_file: | ||
response = fifo_file.read() | ||
self.assertEqual(response, "ready") | ||
stack_trace = get_stack_trace(p.pid) | ||
except PermissionError: | ||
self.skipTest("Insufficient permissions to read the stack trace") | ||
finally: | ||
os.remove(fifo) | ||
p.kill() | ||
p.terminate() | ||
p.wait(timeout=SHORT_TIMEOUT) | ||
|
||
|
||
expected_stack_trace = [ | ||
'foo', | ||
'baz', | ||
'bar', | ||
'<module>' | ||
] | ||
self.assertEqual(stack_trace, expected_stack_trace) | ||
|
||
@unittest.skipIf(sys.platform != "darwin" and sys.platform != "linux", "Test only runs on Linux and MacOS") | ||
@unittest.skipIf(sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED, "Test only runs on Linux with process_vm_readv support") | ||
def test_self_trace(self): | ||
stack_trace = get_stack_trace(os.getpid()) | ||
self.assertEqual(stack_trace[0], "test_self_trace") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.