1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
"""Test Python APIs for process IO."""
import os, sys, time
import unittest2
import lldb
from lldbtest import *
class ProcessIOTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@python_api_test
@dsym_test
def test_put_stdin_with_dsym(self):
"""Exercise SBProcess.PutSTDIN()."""
self.buildDsym()
self.put_stdin()
@python_api_test
@dwarf_test
def test_put_stdin_with_dwarf(self):
"""Exercise SBProcess.PutSTDIN()."""
self.buildDwarf()
self.put_stdin()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Get the full path to our executable to be debugged.
self.exe = os.path.join(os.getcwd(), "process_io")
def put_stdin(self):
"""Launch a process and use SBProcess.PutSTDIN() to write data to it."""
target = self.dbg.CreateTarget(self.exe)
# Perform synchronous interaction with the debugger.
self.setAsync(True)
process = target.LaunchSimple (None, None, self.get_process_working_directory())
if self.TraceOn():
print "process launched."
self.assertTrue(process, PROCESS_IS_VALID)
process.PutSTDIN("Line 1 Entered.\n")
process.PutSTDIN("Line 2 Entered.\n")
process.PutSTDIN("Line 3 Entered.\n")
for i in range(5):
output = process.GetSTDOUT(500)
error = process.GetSTDERR(500)
if self.TraceOn():
print "output->|%s|" % output
# Since we launched the process without specifying stdin/out/err,
# a pseudo terminal is used for stdout/err, and we are satisfied
# once "input line=>1" appears in stdout.
# See also main.c.
if "input line=>1" in output:
return
time.sleep(5)
self.fail("Expected output form launched process did not appear?")
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()
|