[Lldb-commits] [lldb] r126529 - in /lldb/trunk/test/process_launch: Makefile TestProcessLaunch.py my_working_dir/ print_cwd.cpp

Johnny Chen johnny.chen at apple.com
Fri Feb 25 15:15:09 PST 2011


Author: johnny
Date: Fri Feb 25 17:15:09 2011
New Revision: 126529

URL: http://llvm.org/viewvc/llvm-project?rev=126529&view=rev
Log:
Add a test case to exercise the process launch flag of '-w <path>' which sets the
current working directory when running the inferior.  Radar filed:

    # rdar://problem/9056462
    # The process launch flag '-w' for setting the current working directory not working?

Added:
    lldb/trunk/test/process_launch/my_working_dir/
    lldb/trunk/test/process_launch/print_cwd.cpp
Modified:
    lldb/trunk/test/process_launch/Makefile
    lldb/trunk/test/process_launch/TestProcessLaunch.py

Modified: lldb/trunk/test/process_launch/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/process_launch/Makefile?rev=126529&r1=126528&r2=126529&view=diff
==============================================================================
--- lldb/trunk/test/process_launch/Makefile (original)
+++ lldb/trunk/test/process_launch/Makefile Fri Feb 25 17:15:09 2011
@@ -1,6 +1,7 @@
 LEVEL = ../make
 
 CXX_SOURCES := main.cpp
+#CXX_SOURCES := print-cwd.cpp
 
 include $(LEVEL)/Makefile.rules
 

Modified: lldb/trunk/test/process_launch/TestProcessLaunch.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/process_launch/TestProcessLaunch.py?rev=126529&r1=126528&r2=126529&view=diff
==============================================================================
--- lldb/trunk/test/process_launch/TestProcessLaunch.py (original)
+++ lldb/trunk/test/process_launch/TestProcessLaunch.py Fri Feb 25 17:15:09 2011
@@ -96,6 +96,75 @@
         if not success:
             self.fail (err_msg)
 
+    dict = {'CXX_SOURCES' : 'print_cwd.cpp'}
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_set_working_dir_with_dsym (self):
+        dict = {'CXX_SOURCES' : 'print_cwd.cpp'}
+        self.buildDsym(dictionary=dict)
+        self.setTearDownCleanup(dict)
+        self.my_working_dir_test()
+
+    def test_set_working_dir_with_dwarf (self):
+        dict = {'CXX_SOURCES' : 'print_cwd.cpp'}
+        self.buildDwarf(dictionary=dict)
+        self.setTearDownCleanup(dict)
+        self.my_working_dir_test()
+
+    # rdar://problem/9056462
+    # The process launch flag '-w' for setting the current working directory not working?
+    def my_working_dir_test (self):
+        """Test that '-w dir' sets the working dir when running the inferior."""
+        exe = os.path.join (os.getcwd(), "a.out")
+        self.runCmd("file " + exe)
+
+        mywd = 'my_working_dir'
+        out_file_name = "my_working_dir_test.out"
+
+        my_working_dir_path = os.path.join(os.getcwd(), mywd)
+        out_file_path = os.path.join(my_working_dir_path, out_file_name)
+
+        # Make sure the output files do not exist before launching the process
+        try:
+            os.remove (out_file_path)
+        except OSError:
+            pass
+
+        launch_command = "process launch -w %s -o %s" % (my_working_dir_path,
+                                                         out_file_path)
+
+        self.expect(launch_command,
+                    patterns = [ "Process .* launched: .*a.out" ])
+
+        success = True
+        err_msg = ""
+
+        # Check to see if the 'stdout' file was created
+        try:
+            out_f = open(out_file_path)
+        except IOError:
+            success = False
+            err_msg = err_msg + "ERROR: stdout file was not created.\n"
+        else:
+            # Check to see if the 'stdout' file contains the right output
+            line = out_f.readline();
+            print "line:", line
+            if not re.search(mywd, line):
+                success = False
+                err_msg = err_msg + "The current working directory was not set correctly.\n"
+                out_f.close();
+            
+        # Try to delete the 'stdout' file
+        try:
+            os.remove(out_file_path)
+            pass
+        except OSError:
+            pass
+
+        if not success:
+            self.fail(err_msg)
+
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()

Added: lldb/trunk/test/process_launch/print_cwd.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/process_launch/print_cwd.cpp?rev=126529&view=auto
==============================================================================
--- lldb/trunk/test/process_launch/print_cwd.cpp (added)
+++ lldb/trunk/test/process_launch/print_cwd.cpp Fri Feb 25 17:15:09 2011
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+  char buffer[1024];
+
+  fprintf(stdout, "stdout: %s\n", getcwd(buffer, 1024));
+  fprintf(stderr, "stderr: %s\n", getcwd(buffer, 1024));
+
+  return 0;
+}





More information about the lldb-commits mailing list