[Lldb-commits] [lldb] r114031 - in /lldb/trunk/test/settings: Makefile TestSettings.py main.cpp

Johnny Chen johnny.chen at apple.com
Wed Sep 15 15:27:30 PDT 2010


Author: johnny
Date: Wed Sep 15 17:27:29 2010
New Revision: 114031

URL: http://llvm.org/viewvc/llvm-project?rev=114031&view=rev
Log:
Added two test cases to TestSettings.py which exercise the lldb's:

(lldb) settings set process.run-args A B C
(lldb) settings set process.env-vars ["MY_ENV_VAR"]=YES

commands.  The main.cpp checks whether A, B, C is passed to main and whether
the $MY_ENV_VAR env variable is defined and outputs the findings to a file.

Added:
    lldb/trunk/test/settings/Makefile
    lldb/trunk/test/settings/main.cpp
Modified:
    lldb/trunk/test/settings/TestSettings.py

Added: lldb/trunk/test/settings/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/Makefile?rev=114031&view=auto
==============================================================================
--- lldb/trunk/test/settings/Makefile (added)
+++ lldb/trunk/test/settings/Makefile Wed Sep 15 17:27:29 2010
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=114031&r1=114030&r2=114031&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Wed Sep 15 17:27:29 2010
@@ -39,6 +39,36 @@
         self.expect("settings show",
             startstr = "term-width (int) = '70'")
 
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym(self):
+        """Test that run-args and env-vars are passed to the launched process."""
+        self.buildDsym()
+        self.pass_run_args_and_env_vars()
+
+    def test_with_dwarf(self):
+        """Test that run-args and env-vars are passed to the launched process."""
+        self.buildDwarf()
+        self.pass_run_args_and_env_vars()
+
+    def pass_run_args_and_env_vars(self):
+        """Test that run-args and env-vars are passed to the launched process."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Set the run-args and the env-vars.
+        self.runCmd('settings set process.run-args A B C')
+        self.runCmd('settings set process.env-vars ["MY_ENV_VAR"]=YES')
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # Read the output file produced by running the program.
+        output = open('/tmp/output.txt', 'r').read()
+
+        self.assertTrue(output.startswith("argv[1] matches") and
+                        output.find("argv[2] matches") > 0 and
+                        output.find("argv[3] matches") > 0 and
+                        output.find("Environment variable 'MY_ENV_VAR' successfully passed.") > 0)
+
 
 if __name__ == '__main__':
     import atexit

Added: lldb/trunk/test/settings/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/main.cpp?rev=114031&view=auto
==============================================================================
--- lldb/trunk/test/settings/main.cpp (added)
+++ lldb/trunk/test/settings/main.cpp Wed Sep 15 17:27:29 2010
@@ -0,0 +1,44 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstdlib>
+#include <string>
+#include <fstream>
+
+int
+main(int argc, char const *argv[])
+{
+    char const *cptr = NULL;
+    // The program writes its output to the "output.txt" file.
+    std::ofstream outfile("output.txt");
+
+    for (unsigned i = 0, e = sizeof(argv); i < e; ++i) {
+        if ((cptr = argv[i]) == NULL)
+            break;
+
+        std::string str(cptr);
+        if (i == 1 && "A" == str)
+            outfile << "argv[1] matches\n";
+
+        if (i == 2 && "B" == str)
+            outfile << "argv[2] matches\n";
+
+        if (i == 3 && "C" == str)
+            outfile << "argv[3] matches\n";
+    }
+
+    if (::getenv("MY_ENV_VAR")) {
+        std::string MY_ENV_VAR(getenv("MY_ENV_VAR"));
+        if ("YES" == MY_ENV_VAR) {
+            outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n";
+        }
+    }
+
+    return 0;
+}





More information about the lldb-commits mailing list