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

Johnny Chen johnny.chen at apple.com
Fri Dec 3 16:44:56 PST 2010


Author: johnny
Date: Fri Dec  3 18:44:56 2010
New Revision: 120871

URL: http://llvm.org/viewvc/llvm-project?rev=120871&view=rev
Log:
Add a test method test_pass_host_env_vars to 'class SettingsCommandTestCase(TestBase)'
which tests the recently added lldb feature of automatically passing the host environment
variables to the launched process.

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

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=120871&r1=120870&r2=120871&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Fri Dec  3 18:44:56 2010
@@ -108,6 +108,31 @@
                        "argv[3] matches",
                        "Environment variable 'MY_ENV_VAR' successfully passed."])
 
+    def test_pass_host_env_vars(self):
+        """Test that the host env vars are passed to the launched process."""
+        self.buildDefault()
+
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # By default, inherit-env is 'true'.
+        self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
+            startstr = "target.process.inherit-env (boolean) = 'true'")
+
+        # Set some host environment variables now.
+        os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
+        os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # Read the output file produced by running the program.
+        with open('output.txt', 'r') as f:
+            output = f.read()
+
+        self.expect(output, exe=False,
+            substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
+                       "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
+
     @unittest2.expectedFailure
     # rdar://problem/8435794
     # settings set target.process.output-path does not seem to work

Modified: lldb/trunk/test/settings/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/main.cpp?rev=120871&r1=120870&r2=120871&view=diff
==============================================================================
--- lldb/trunk/test/settings/main.cpp (original)
+++ lldb/trunk/test/settings/main.cpp Fri Dec  3 18:44:56 2010
@@ -30,6 +30,7 @@
             outfile << "argv[3] matches\n";
     }
 
+    // For passing environment vars from the debugger to the launched process.
     if (::getenv("MY_ENV_VAR")) {
         std::string MY_ENV_VAR(getenv("MY_ENV_VAR"));
         if ("YES" == MY_ENV_VAR) {
@@ -37,6 +38,22 @@
         }
     }
 
+
+    // For passing host environment vars to the launched process.
+    if (::getenv("MY_HOST_ENV_VAR1")) {
+        std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1"));
+        if ("VAR1" == MY_HOST_ENV_VAR1) {
+            outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n";
+        }
+    }
+
+    if (::getenv("MY_HOST_ENV_VAR2")) {
+        std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2"));
+        if ("VAR2" == MY_HOST_ENV_VAR2) {
+            outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n";
+        }
+    }
+
     std::cout << "This message should go to standard out.\n";
 
     return 0;





More information about the lldb-commits mailing list