[llvm-branch-commits] [lldb] r270123 - Make File option flags consistent for Python API

Francis Ricci via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu May 19 13:52:14 PDT 2016


Author: fjricci
Date: Thu May 19 15:52:14 2016
New Revision: 270123

URL: http://llvm.org/viewvc/llvm-project?rev=270123&view=rev
Log:
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 at fb.com>

This is a cherry-pick of r264351

Modified:
    lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
    lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
    lldb/branches/release_38/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Modified: lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py?rev=270123&r1=270122&r2=270123&view=diff
==============================================================================
--- lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py (original)
+++ lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py Thu May 19 15:52:14 2016
@@ -25,7 +25,7 @@ class CommandScriptImmediateOutputTestCa
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
     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)"
@@ -34,4 +34,38 @@ class CommandScriptImmediateOutputTestCa
         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)
+

Modified: lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py?rev=270123&r1=270122&r2=270123&view=diff
==============================================================================
--- lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py (original)
+++ lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py Thu May 19 15:52:14 2016
@@ -6,3 +6,12 @@ def command_function(debugger, command,
         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)

Modified: lldb/branches/release_38/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=270123&r1=270122&r2=270123&view=diff
==============================================================================
--- lldb/branches/release_38/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original)
+++ lldb/branches/release_38/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Thu May 19 15:52:14 2016
@@ -1167,10 +1167,10 @@ PythonFile::GetOptionsFromMode(llvm::Str
     return llvm::StringSwitch<uint32_t>(mode.str().c_str())
     .Case("r",   File::eOpenOptionRead)
     .Case("w",   File::eOpenOptionWrite)
-    .Case("a",   File::eOpenOptionAppend|File::eOpenOptionCanCreate)
+    .Case("a",   File::eOpenOptionWrite|File::eOpenOptionAppend|File::eOpenOptionCanCreate)
     .Case("r+",  File::eOpenOptionRead|File::eOpenOptionWrite)
     .Case("w+",  File::eOpenOptionRead|File::eOpenOptionWrite|File::eOpenOptionCanCreate|File::eOpenOptionTruncate)
-    .Case("a+",  File::eOpenOptionRead|File::eOpenOptionWrite|File::eOpenOptionCanCreate)
+    .Case("a+",  File::eOpenOptionRead|File::eOpenOptionWrite|File::eOpenOptionAppend|File::eOpenOptionCanCreate)
     .Default(0);
 }
 




More information about the llvm-branch-commits mailing list