blob: 9a2d2f8dd058e650741d7af91ae97132584b9e58 [file] [log] [blame]
Johnny Chen49cb85d2011-11-28 21:39:07 +00001"""Test Python APIs for process IO."""
2
3import os, sys, time
4import unittest2
5import lldb
6from lldbtest import *
7
8class ProcessIOTestCase(TestBase):
9
Greg Clayton4570d3e2013-12-10 23:19:29 +000010 mydir = TestBase.compute_mydir(__file__)
Johnny Chen49cb85d2011-11-28 21:39:07 +000011
12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
13 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000014 @dsym_test
Johnny Chen49cb85d2011-11-28 21:39:07 +000015 def test_put_stdin_with_dsym(self):
16 """Exercise SBProcess.PutSTDIN()."""
17 self.buildDsym()
18 self.put_stdin()
19
20 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000021 @dwarf_test
Johnny Chen49cb85d2011-11-28 21:39:07 +000022 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
Daniel Malea249287a2013-02-19 16:08:57 +000038 # Perform synchronous interaction with the debugger.
39 self.setAsync(True)
40
Greg Claytonc6947512013-12-13 19:18:59 +000041 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Johnny Chen49cb85d2011-11-28 21:39:07 +000042 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
Johnny Chen5886fb52012-01-12 00:29:46 +000056 # 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.
Johnny Chen49cb85d2011-11-28 21:39:07 +000059 # See also main.c.
Johnny Chen49cb85d2011-11-28 21:39:07 +000060 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()