summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/python_api/file_handle
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-10-15 16:46:27 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-10-15 16:46:27 +0000
commitd9b553ec9961e95740535d3aeff62817f867767f (patch)
treea20193fd70d7956369ddf7c7b75407b7273c597f /lldb/packages/Python/lldbsuite/test/python_api/file_handle
parent1184c27fa586f8fe713921150146d433aae969ff (diff)
downloadbcm5719-llvm-d9b553ec9961e95740535d3aeff62817f867767f.tar.gz
bcm5719-llvm-d9b553ec9961e95740535d3aeff62817f867767f.zip
SBFile::GetFile: convert SBFile back into python native files.
Summary: This makes SBFile::GetFile public and adds a SWIG typemap to convert the result back into a python native file. If the underlying File itself came from a python file, it is returned identically. Otherwise a new python file object is created using the file descriptor. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68737 llvm-svn: 374911
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/python_api/file_handle')
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
index 577c6b3e88f..1bd002e6bb7 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
@@ -772,7 +772,21 @@ class FileHandleTestCase(lldbtest.TestBase):
@add_test_categories(['pyapi'])
- @expectedFailureAll() # FIXME implement SBFile::GetFile
+ def test_stdout_file(self):
+ with open(self.out_filename, 'w') as f:
+ status = self.debugger.SetOutputFile(f)
+ self.assertTrue(status.Success())
+ self.handleCmd(r"script sys.stdout.write('foobar\n')")
+ with open(self.out_filename, 'r') as f:
+ # In python2 sys.stdout.write() returns None, which
+ # the REPL will ignore, but in python3 it will
+ # return the number of bytes written, which the REPL
+ # will print out.
+ lines = [x for x in f.read().strip().split() if x != "7"]
+ self.assertEqual(lines, ["foobar"])
+
+
+ @add_test_categories(['pyapi'])
@skipIf(py_version=['<', (3,)])
def test_identity(self):
@@ -826,3 +840,22 @@ class FileHandleTestCase(lldbtest.TestBase):
with open(self.out_filename, 'r') as f:
self.assertEqual("foobar", f.read().strip())
+
+
+ @add_test_categories(['pyapi'])
+ def test_back_and_forth(self):
+ with open(self.out_filename, 'w') as f:
+ # at each step here we're borrowing the file, so we have to keep
+ # them all alive until the end.
+ sbf = lldb.SBFile.Create(f, borrow=True)
+ def i(sbf):
+ for i in range(10):
+ f = sbf.GetFile()
+ yield f
+ sbf = lldb.SBFile.Create(f, borrow=True)
+ yield sbf
+ sbf.Write(str(i).encode('ascii') + b"\n")
+ files = list(i(sbf))
+ with open(self.out_filename, 'r') as f:
+ self.assertEqual(list(range(10)), list(map(int, f.read().strip().split())))
+
OpenPOWER on IntegriCloud