blob: 8c494d151746f86227670a2b28fbb9ea88f900ac [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
14 def test_put_stdin_with_dsym(self):
15 """Exercise SBProcess.PutSTDIN()."""
16 self.buildDsym()
17 self.put_stdin()
18
19 @python_api_test
20 def test_put_stdin_with_dwarf(self):
21 """Exercise SBProcess.PutSTDIN()."""
22 self.buildDwarf()
23 self.put_stdin()
24
25 def setUp(self):
26 # Call super's setUp().
27 TestBase.setUp(self)
28 # Get the full path to our executable to be debugged.
29 self.exe = os.path.join(os.getcwd(), "process_io")
30
31 def put_stdin(self):
32 """Launch a process and use SBProcess.PutSTDIN() to write data to it."""
33
34 target = self.dbg.CreateTarget(self.exe)
35
36 self.dbg.SetAsync(True)
37 process = target.LaunchSimple(None, None, os.getcwd())
38 if self.TraceOn():
39 print "process launched."
40
41 self.assertTrue(process, PROCESS_IS_VALID)
42
43 process.PutSTDIN("Line 1 Entered.\n")
44 process.PutSTDIN("Line 2 Entered.\n")
45 process.PutSTDIN("Line 3 Entered.\n")
46
47 for i in range(5):
48 output = process.GetSTDOUT(500)
49 error = process.GetSTDERR(500)
50 if self.TraceOn():
51 print "output->|%s|" % output
52 print "error->|%s|" % error
53 # We are satisfied once "input line=>1" appears in stderr.
54 # See also main.c.
55 #if "input line=>1" in error:
56 if "input line=>1" in output:
57 return
58 time.sleep(5)
59
60 self.fail("Expected output form launched process did not appear?")
61
62if __name__ == '__main__':
63 import atexit
64 lldb.SBDebugger.Initialize()
65 atexit.register(lambda: lldb.SBDebugger.Terminate())
66 unittest2.main()