diff options
author | Stephane Sezer <sas@cd80.net> | 2016-03-24 22:22:20 +0000 |
---|---|---|
committer | Stephane Sezer <sas@cd80.net> | 2016-03-24 22:22:20 +0000 |
commit | c5273d929f54f9499d1cdea6e3112d6cdf9b18b1 (patch) | |
tree | 6849e01f27567456bd12f823ea377d5daa5be13b /lldb/packages/Python/lldbsuite | |
parent | ce7c6cfe0e817251548a8c335ccb99bf5c0b12b4 (diff) | |
download | bcm5719-llvm-c5273d929f54f9499d1cdea6e3112d6cdf9b18b1.tar.gz bcm5719-llvm-c5273d929f54f9499d1cdea6e3112d6cdf9b18b1.zip |
Make File option flags consistent for Python API
Summary:
Fixes SBCommandReturnObject::SetImmediateOutputFile() and
SBCommandReturnObject::SetImmediateOutputFile() for files opened
with "a" or "a+" by resolving inconsistencies between File and
our Python parsing of file objects.
Reviewers: granata.enrico, Eugene.Zelenko, jingham, clayborg
Subscribers: lldb-commits, sas
Differential Revision: http://reviews.llvm.org/D18228
Change by Francis Ricci <fjricci@fb.com>
llvm-svn: 264351
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
2 files changed, 44 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py index 4716d65368f..570745edf6f 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py @@ -26,7 +26,7 @@ class CommandScriptImmediateOutputTestCase (PExpectTest): @expectedFailureAll(oslist=["freebsd","linux"], bugnumber="llvm.org/pr26139") def test_command_script_immediate_output (self): """Test that LLDB correctly allows scripted commands to set an immediate output file.""" - self.launch(timeout=5) + self.launch(timeout=60) script = os.path.join(os.getcwd(), 'custom_command.py') prompt = "(lldb)" @@ -35,4 +35,38 @@ class CommandScriptImmediateOutputTestCase (PExpectTest): self.sendline('command script add -f custom_command.command_function mycommand', patterns=[prompt]) self.sendline('mycommand', patterns='this is a test string, just a test string') self.sendline('command script delete mycommand', patterns=[prompt]) + + test_files = {os.path.join(os.getcwd(), 'read.txt') :'r', + os.path.join(os.getcwd(), 'write.txt') :'w', + os.path.join(os.getcwd(), 'append.txt') :'a', + os.path.join(os.getcwd(), 'write_plus.txt') :'w+', + os.path.join(os.getcwd(), 'read_plus.txt') :'r+', + os.path.join(os.getcwd(), 'append_plus.txt') :'a+'} + + starter_string = 'Starter Garbage\n' + write_string = 'writing to file with mode: ' + + for path, mode in test_files.iteritems(): + with open(path, 'w+') as init: + init.write(starter_string) + + self.sendline('command script add -f custom_command.write_file mywrite', patterns=[prompt]) + for path, mode in test_files.iteritems(): + command = 'mywrite ' + path + ' ' + mode + + self.sendline(command, patterns=[prompt]) + + self.sendline('command script delete mywrite', patterns=[prompt]) + self.quit(gracefully=False) + + for path, mode in test_files.iteritems(): + with open(path, 'r') as result: + if mode in ['r', 'a', 'a+']: + self.assertEquals(result.readline(), starter_string) + if mode in ['w', 'w+', 'r+', 'a', 'a+']: + self.assertEquals(result.readline(), write_string + mode + '\n') + + self.assertTrue(os.path.isfile(path)) + os.remove(path) + diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py index a9749196ca7..03d688ad967 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py @@ -6,3 +6,12 @@ def command_function(debugger, command, exe_ctx, result, internal_dict): result.SetImmediateOutputFile(sys.__stdout__) print('this is a test string, just a test string', file=result) +def write_file(debugger, command, exe_ctx, result, internal_dict): + args = command.split(' ') + path = args[0] + mode = args[1] + + with open(path, mode) as f: + result.SetImmediateOutputFile(f) + if not mode in ['r']: + print('writing to file with mode: ' + mode, file=result) |