blob: 4d6a0221d3ed4dbee731a20e379bcb497f5168c1 [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
10 mydir = os.path.join("python_api", "process", "io")
11
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
38 self.dbg.SetAsync(True)
39 process = target.LaunchSimple(None, None, os.getcwd())
40 if self.TraceOn():
41 print "process launched."
42
43 self.assertTrue(process, PROCESS_IS_VALID)
44
45 process.PutSTDIN("Line 1 Entered.\n")
46 process.PutSTDIN("Line 2 Entered.\n")
47 process.PutSTDIN("Line 3 Entered.\n")
48
49 for i in range(5):
50 output = process.GetSTDOUT(500)
51 error = process.GetSTDERR(500)
52 if self.TraceOn():
53 print "output->|%s|" % output
Johnny Chen5886fb52012-01-12 00:29:46 +000054 # Since we launched the process without specifying stdin/out/err,
55 # a pseudo terminal is used for stdout/err, and we are satisfied
56 # once "input line=>1" appears in stdout.
Johnny Chen49cb85d2011-11-28 21:39:07 +000057 # See also main.c.
Johnny Chen49cb85d2011-11-28 21:39:07 +000058 if "input line=>1" in output:
59 return
60 time.sleep(5)
61
62 self.fail("Expected output form launched process did not appear?")
63
64if __name__ == '__main__':
65 import atexit
66 lldb.SBDebugger.Initialize()
67 atexit.register(lambda: lldb.SBDebugger.Terminate())
68 unittest2.main()