Beispiel #1
0
    def test_run_args_and_env_vars(self):
        """Test that run-args and env-vars are passed to the launched process."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Set the run-args and the env-vars.
        # And add hooks to restore the settings during tearDown().
        self.runCmd('settings set target.run-args A B C')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.run-args"))
        self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.env-vars"))

        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output2.txt")

        self.expect(
            output,
            exe=False,
            substrs=[
                "argv[1] matches",
                "argv[2] matches",
                "argv[3] matches",
                "Environment variable 'MY_ENV_VAR' successfully passed."])
Beispiel #2
0
    def test_pass_host_env_vars(self):
        """Test that the host env vars are passed to the launched process."""
        self.build()

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # By default, inherit-env is 'true'.
        self.expect(
            'settings show target.inherit-env',
            "Default inherit-env is 'true'",
            startstr="target.inherit-env (boolean) = true")

        # Set some host environment variables now.
        os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
        os.environ["MY_HOST_ENV_VAR2"] = "VAR2"

        # This is the function to unset the two env variables set above.
        def unset_env_variables():
            os.environ.pop("MY_HOST_ENV_VAR1")
            os.environ.pop("MY_HOST_ENV_VAR2")

        self.addTearDownHook(unset_env_variables)
        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output1.txt")

        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."])
Beispiel #3
0
    def test_run_args_and_env_vars(self):
        """Test that run-args and env-vars are passed to the launched process."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Set the run-args and the env-vars.
        # And add hooks to restore the settings during tearDown().
        self.runCmd('settings set target.run-args A B C')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.run-args"))
        self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.env-vars"))

        self.runCmd(
            "process launch --working-dir '{0}'".format(
                self.get_process_working_directory()), RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output2.txt")

        self.expect(
            output,
            exe=False,
            substrs=[
                "argv[1] matches", "argv[2] matches", "argv[3] matches",
                "Environment variable 'MY_ENV_VAR' successfully passed."
            ])
Beispiel #4
0
    def test_pass_host_env_vars(self):
        """Test that the host env vars are passed to the launched process."""
        self.build()

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # By default, inherit-env is 'true'.
        self.expect(
            'settings show target.inherit-env',
            "Default inherit-env is 'true'",
            startstr="target.inherit-env (boolean) = true")

        # Set some host environment variables now.
        os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
        os.environ["MY_HOST_ENV_VAR2"] = "VAR2"

        # This is the function to unset the two env variables set above.
        def unset_env_variables():
            os.environ.pop("MY_HOST_ENV_VAR1")
            os.environ.pop("MY_HOST_ENV_VAR2")

        self.addTearDownHook(unset_env_variables)
        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output1.txt")

        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."])
Beispiel #5
0
    def test_set_error_output_path(self):
        """Test that setting target.error/output-path for the launched process works."""
        self.build()

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Set the error-path and output-path and verify both are set.
        self.runCmd("settings set target.error-path '{0}'".format(
            lldbutil.append_to_process_working_directory(self, "stderr.txt")))
        self.runCmd("settings set target.output-path '{0}".format(
            lldbutil.append_to_process_working_directory(self, "stdout.txt")))
        # And add hooks to restore the original settings during tearDown().
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.output-path"))
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.error-path"))

        self.expect("settings show target.error-path",
                    SETTING_MSG("target.error-path"),
                    substrs=['target.error-path (file)', 'stderr.txt"'])

        self.expect("settings show target.output-path",
                    SETTING_MSG("target.output-path"),
                    substrs=['target.output-path (file)', 'stdout.txt"'])

        self.runCmd(
            "process launch --working-dir '{0}'".format(
                self.get_process_working_directory()), RUN_SUCCEEDED)

        output = lldbutil.read_file_from_process_wd(self, "stderr.txt")
        message = "This message should go to standard error."
        if lldbplatformutil.hasChattyStderr(self):
            self.expect(output, exe=False, substrs=[message])
        else:
            self.expect(output, exe=False, startstr=message)

        output = lldbutil.read_file_from_process_wd(self, "stdout.txt")
        self.expect(output,
                    exe=False,
                    startstr="This message should go to standard out.")
Beispiel #6
0
    def test_set_error_output_path(self):
        """Test that setting target.error/output-path for the launched process works."""
        self.build()

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Set the error-path and output-path and verify both are set.
        self.runCmd("settings set target.error-path '{0}'".format(
            lldbutil.append_to_process_working_directory(self, "stderr.txt")))
        self.runCmd("settings set target.output-path '{0}".format(
            lldbutil.append_to_process_working_directory(self, "stdout.txt")))
        # And add hooks to restore the original settings during tearDown().
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.output-path"))
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.error-path"))

        self.expect("settings show target.error-path",
                    SETTING_MSG("target.error-path"),
                    substrs=['target.error-path (file)', 'stderr.txt"'])

        self.expect("settings show target.output-path",
                    SETTING_MSG("target.output-path"),
                    substrs=['target.output-path (file)', 'stdout.txt"'])

        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        output = lldbutil.read_file_from_process_wd(self, "stderr.txt")
        message = "This message should go to standard error."
        if lldbplatformutil.hasChattyStderr(self):
            self.expect(output, exe=False, substrs=[message])
        else:
            self.expect(output, exe=False, startstr=message)

        output = lldbutil.read_file_from_process_wd(self, "stdout.txt")
        self.expect(output, exe=False,
                    startstr="This message should go to standard out.")
Beispiel #7
0
    def test_pass_host_env_vars(self):
        """Test that the host env vars are passed to the launched process."""
        self.build()

        # Set some host environment variables now.
        os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
        os.environ["MY_HOST_ENV_VAR2"] = "VAR2"

        # This is the function to unset the two env variables set above.
        def unset_env_variables():
            os.environ.pop("MY_HOST_ENV_VAR1")
            os.environ.pop("MY_HOST_ENV_VAR2")
        self.addTearDownHook(unset_env_variables)

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # By default, inherit-env is 'true'.
        self.expect(
            'settings show target.inherit-env',
            "Default inherit-env is 'true'",
            startstr="target.inherit-env (boolean) = true")

        self.expect(
            'target show-launch-environment',
            'Host environment is passed correctly',
            substrs=['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2'])
        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output1.txt")

        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."])

        # Now test that we can prevent the inferior from inheriting the
        # environment.
        self.runCmd('settings set target.inherit-env false')

        self.expect(
            'target show-launch-environment',
            'target.inherit-env affects `target show-launch-environment`',
            matching=False,
            substrs = ['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2'])

        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output1.txt")

        self.expect(
            output,
            exe=False,
            matching=False,
            substrs=[
                "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
                "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])

        # Now test that we can unset variables from the inherited environment.
        self.runCmd('settings set target.inherit-env true')
        self.runCmd('settings set target.unset-env-vars MY_HOST_ENV_VAR1')
        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output1.txt")

        self.expect(
            'target show-launch-environment',
            'MY_HOST_ENV_VAR1 is unset, it shouldn\'t be in `target show-launch-environment`',
            matching=False,
            substrs = ['MY_HOST_ENV_VAR1=VAR1'])
        self.expect(
            'target show-launch-environment',
            'MY_HOST_ENV_VAR2 shouldn be in `target show-launch-environment`',
            substrs = ['MY_HOST_ENV_VAR2=VAR2'])

        self.expect(
            output,
            exe=False,
            matching=False,
            substrs=[
                "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed."])
        self.expect(
            output,
            exe=False,
            substrs=[
                "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
Beispiel #8
0
    def do_test_run_args_and_env_vars(self, use_launchsimple):
        """Test that run-args and env-vars are passed to the launched process."""
        self.build()

        # Set the run-args and the env-vars.
        # And add hooks to restore the settings during tearDown().
        self.runCmd('settings set target.run-args A B C')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.run-args"))
        self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
        self.addTearDownHook(
            lambda: self.runCmd("settings clear target.env-vars"))

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        target = self.dbg.GetTargetAtIndex(0)
        launch_info = target.GetLaunchInfo()
        found_env_var = False
        for i in range(0, launch_info.GetNumEnvironmentEntries()):
            if launch_info.GetEnvironmentEntryAtIndex(i) == "MY_ENV_VAR=YES":
                found_env_var = True
                break
        self.assertTrue(found_env_var,
                        "MY_ENV_VAR was not set in LunchInfo object")

        self.assertEqual(launch_info.GetNumArguments(), 3)
        self.assertEqual(launch_info.GetArgumentAtIndex(0), "A")
        self.assertEqual(launch_info.GetArgumentAtIndex(1), "B")
        self.assertEqual(launch_info.GetArgumentAtIndex(2), "C")
        
        self.expect(
            'target show-launch-environment',
            substrs=["MY_ENV_VAR=YES"])

        wd = self.get_process_working_directory()
        if use_launchsimple:
            process = target.LaunchSimple(None, None, wd)
            self.assertTrue(process)
        else:
            self.runCmd("process launch --working-dir '{0}'".format(wd),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output2.txt")

        self.expect(
            output,
            exe=False,
            substrs=[
                "argv[1] matches",
                "argv[2] matches",
                "argv[3] matches",
                "Environment variable 'MY_ENV_VAR' successfully passed."])

        # Check that env-vars overrides unset-env-vars.
        self.runCmd('settings set target.unset-env-vars MY_ENV_VAR')

        self.expect(
            'target show-launch-environment',
            'env-vars overrides unset-env-vars',
            substrs=["MY_ENV_VAR=YES"])

        wd = self.get_process_working_directory()
        if use_launchsimple:
            process = target.LaunchSimple(None, None, wd)
            self.assertTrue(process)
        else:
            self.runCmd("process launch --working-dir '{0}'".format(wd),
                RUN_SUCCEEDED)

        # Read the output file produced by running the program.
        output = lldbutil.read_file_from_process_wd(self, "output2.txt")

        self.expect(
            output,
            exe=False,
            substrs=[
                "Environment variable 'MY_ENV_VAR' successfully passed."])