mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Test fixes.
This commit is contained in:
parent
af768a7611
commit
746bda561e
21 changed files with 385 additions and 387 deletions
|
|
@ -1,10 +0,0 @@
|
|||
This is not a subpackage!
|
||||
|
||||
PYTHONPATH has an entry for this directory automatically appended for all Python code
|
||||
that is executed via tests.debug.Session.
|
||||
|
||||
Thus, it should be used for modules that are meant to be importable by such debugged
|
||||
code, and that are not test-specific - for example, backchannel.
|
||||
|
||||
Because this code runs in the debuggee process, it cannot import anything from the
|
||||
top-level tests package. It can, however, import ptvsd and pydevd.
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See LICENSE in the project root
|
||||
# for license information.
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
"""Imported from test code that runs under ptvsd, and allows that code
|
||||
to communcate back to the test. Works in conjunction with debug_session
|
||||
fixture and its backchannel method."""
|
||||
|
||||
__all__ = ["port", "receive", "send"]
|
||||
|
||||
import atexit
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
assert "debug_me" in sys.modules
|
||||
import debug_me
|
||||
|
||||
from ptvsd.common import fmt, log, messaging
|
||||
|
||||
|
||||
name = fmt("backchannel-{0}", debug_me.session_id)
|
||||
port = os.getenv("PTVSD_BACKCHANNEL_PORT")
|
||||
if port is not None:
|
||||
port = int(port)
|
||||
# Remove it, so that child processes don't try to use the same backchannel.
|
||||
del os.environ["PTVSD_BACKCHANNEL_PORT"]
|
||||
|
||||
|
||||
if port:
|
||||
log.info('Connecting {0} to port {1}...', name, port)
|
||||
|
||||
_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
_socket.connect(('localhost', port))
|
||||
_stream = messaging.JsonIOStream.from_socket(_socket, name='backchannel')
|
||||
|
||||
@atexit.register
|
||||
def _atexit_handler():
|
||||
log.info('Shutting down {0}...', name)
|
||||
try:
|
||||
_socket.shutdown(socket.SHUT_RDWR)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
_socket.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
else:
|
||||
class _stream:
|
||||
def _error(*_):
|
||||
raise AssertionError("Backchannel is not set up for this process")
|
||||
|
||||
read_json = write_json = _error
|
||||
|
||||
|
||||
def send(value):
|
||||
_stream.write_json(value)
|
||||
|
||||
|
||||
def receive():
|
||||
return _stream.read_json()
|
||||
|
||||
|
||||
def wait_for(value):
|
||||
assert receive() == value
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See LICENSE in the project root
|
||||
# for license information.
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
"""Makes sure that the code is run under debugger, using the appropriate method
|
||||
to establish connection back to DebugSession in the test process, depending on
|
||||
DebugSession.start_method used by the test.
|
||||
|
||||
This module MUST be imported by all code that is executed via DebugSession, unless
|
||||
it is launched with start_method="custom_client", for tests that need to set up
|
||||
ptvsd and establish the connection themselves in some special manner.
|
||||
|
||||
If the code needs to access ptvsd and/or pydevd, this module additionally exports
|
||||
both as global variables, specifically so that it is possible to write::
|
||||
|
||||
from debug_me import ptvsd, pydevd, backchannel
|
||||
"""
|
||||
|
||||
__all__ = ["backchannel", "ptvsd", "pydevd", "session_id"]
|
||||
|
||||
import os
|
||||
|
||||
# Needs to be set before backchannel can set things up.
|
||||
session_id = int(os.getenv('PTVSD_SESSION_ID'))
|
||||
name = "ptvsd-" + str(session_id)
|
||||
|
||||
# For `from debug_me import ...`.
|
||||
import backchannel # noqa
|
||||
import ptvsd # noqa
|
||||
import pydevd # noqa
|
||||
|
||||
|
||||
# For all start methods except for "attach_socket_import", DebugSession itself
|
||||
# will take care of starting the debuggee process correctly.
|
||||
|
||||
# For "attach_socket_import", DebugSession will supply the code that needs to
|
||||
# be executed in the debuggee to enable debugging and establish connection back
|
||||
# to DebugSession - the debuggee simply needs to execute it as is.
|
||||
_code = os.getenv("PTVSD_DEBUG_ME")
|
||||
if _code:
|
||||
_code = compile(_code, "<ptvsd-setup>", "exec")
|
||||
eval(_code, {})
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from debug_me import backchannel, ptvsd
|
||||
|
||||
import os
|
||||
import ptvsd
|
||||
import time
|
||||
import backchannel
|
||||
|
||||
|
||||
host = os.getenv('PTVSD_TEST_HOST', 'localhost')
|
||||
|
|
@ -9,21 +9,21 @@ port = os.getenv('PTVSD_TEST_PORT', '5678')
|
|||
ptvsd.enable_attach((host, port))
|
||||
|
||||
if os.getenv('PTVSD_WAIT_FOR_ATTACH', None) is not None:
|
||||
backchannel.write_json('wait_for_attach')
|
||||
backchannel.send('wait_for_attach')
|
||||
ptvsd.wait_for_attach()
|
||||
|
||||
if os.getenv('PTVSD_IS_ATTACHED', None) is not None:
|
||||
backchannel.write_json('is_attached')
|
||||
backchannel.send('is_attached')
|
||||
while not ptvsd.is_attached():
|
||||
time.sleep(0.1)
|
||||
|
||||
pause_test = True
|
||||
if os.getenv('PTVSD_BREAK_INTO_DBG', None) is not None:
|
||||
backchannel.write_json('break_into_debugger')
|
||||
backchannel.send('break_into_debugger')
|
||||
pause_test = False
|
||||
|
||||
if pause_test:
|
||||
assert backchannel.read_json() == 'pause_test'
|
||||
backchannel.wait_for('pause_test')
|
||||
for _ in range(0, 20):
|
||||
time.sleep(0.1)
|
||||
print('looping')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue