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