Files
clang-p2996/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
John Harrison c2e96778e0 [lldb-dap] Ensure we do not print the close sentinel when closing stdout. (#126833)
If you have an lldb-dap log file you'll almost always see a final
message like:

```
<-- 
Content-Length: 94

{
  "body": {
    "category": "stdout",
    "output": "\u0000\u0000"
  },
  "event": "output",
  "seq": 0,
  "type": "event"
}
<-- 
Content-Length: 94

{
  "body": {
    "category": "stderr",
    "output": "\u0000\u0000"
  },
  "event": "output",
  "seq": 0,
  "type": "event"
}
```

The OutputRedirect is always writing the `"\0"` byte as a final stdout
message during shutdown. Instead, I adjusted this to detect the sentinel
value and break out of the read loop as if we detected EOF.

---------

Co-authored-by: Pavel Labath <pavel@labath.sk>
2025-02-13 10:35:50 -08:00

43 lines
1.5 KiB
Python

"""
Test lldb-dap output events
"""
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbdap_testcase
class TestDAP_output(lldbdap_testcase.DAPTestCaseBase):
@skipIfWindows
def test_output(self):
"""
Test output handling for the running process.
"""
program = self.getBuildArtifact("a.out")
self.build_and_launch(
program,
exitCommands=[
# Ensure that output produced by lldb itself is not consumed by the OutputRedirector.
"?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
"?script print('err\\0\\0', end='\\r\\n', file=sys.stderr)",
],
)
source = "main.c"
lines = [line_number(source, "// breakpoint 1")]
breakpoint_ids = self.set_source_breakpoints(source, lines)
self.continue_to_breakpoints(breakpoint_ids)
# Ensure partial messages are still sent.
output = self.collect_stdout(timeout_secs=1.0, pattern="abcdef")
self.assertTrue(output and len(output) > 0, "expect program stdout")
self.continue_to_exit()
output += self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
self.assertTrue(output and len(output) > 0, "expect program stdout")
self.assertIn(
"abcdefghi\r\nhello world\r\nfinally\0\0out\0\0\r\nerr\0\0",
output,
"full stdout not found in: " + repr(output),
)