SBProcess.PutSTDIN() needs to be properly typemapped when swigging,
so that we can do Python scripting like this:
target = self.dbg.CreateTarget(self.exe)
self.dbg.SetAsync(True)
process = target.LaunchSimple(None, None, os.getcwd())
process.PutSTDIN("Line 1 Entered.\n")
process.PutSTDIN("Line 2 Entered.\n")
process.PutSTDIN("Line 3 Entered.\n")
Add TestProcessIO.py to exercise the process IO API: PutSTDIN()/GetSTDOUT()/GetSTDERR().
llvm-svn: 145282
This commit is contained in:
6
lldb/test/python_api/process/io/Makefile
Normal file
6
lldb/test/python_api/process/io/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
LEVEL = ../../../make
|
||||
|
||||
C_SOURCES := main.c
|
||||
EXE := process_io
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
||||
66
lldb/test/python_api/process/io/TestProcessIO.py
Normal file
66
lldb/test/python_api/process/io/TestProcessIO.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""Test Python APIs for process IO."""
|
||||
|
||||
import os, sys, time
|
||||
import unittest2
|
||||
import lldb
|
||||
from lldbtest import *
|
||||
|
||||
class ProcessIOTestCase(TestBase):
|
||||
|
||||
mydir = os.path.join("python_api", "process", "io")
|
||||
|
||||
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
||||
@python_api_test
|
||||
def test_put_stdin_with_dsym(self):
|
||||
"""Exercise SBProcess.PutSTDIN()."""
|
||||
self.buildDsym()
|
||||
self.put_stdin()
|
||||
|
||||
@python_api_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)
|
||||
|
||||
self.dbg.SetAsync(True)
|
||||
process = target.LaunchSimple(None, None, os.getcwd())
|
||||
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
|
||||
print "error->|%s|" % error
|
||||
# We are satisfied once "input line=>1" appears in stderr.
|
||||
# See also main.c.
|
||||
#if "input line=>1" in error:
|
||||
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()
|
||||
12
lldb/test/python_api/process/io/main.c
Normal file
12
lldb/test/python_api/process/io/main.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
printf("Hello world.\n");
|
||||
char line[100];
|
||||
int count = 1;
|
||||
while (fgets(line, sizeof(line), stdin)) { // Reading from stdin...
|
||||
fprintf(stderr, "input line=>%d\n", count++);
|
||||
}
|
||||
|
||||
printf("Exiting now\n");
|
||||
}
|
||||
Reference in New Issue
Block a user