2010-09-08 01:06:13 +08:00
|
|
|
"""
|
|
|
|
Test lldb settings command.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, time
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
|
|
|
|
class SettingsCommandTestCase(TestBase):
|
|
|
|
|
|
|
|
mydir = "settings"
|
|
|
|
|
2010-09-16 09:53:04 +08:00
|
|
|
@classmethod
|
|
|
|
def classCleanup(cls):
|
2010-10-23 05:06:04 +08:00
|
|
|
"""Cleanup the test byproducts."""
|
2010-12-15 07:43:29 +08:00
|
|
|
system(["/bin/sh", "-c", "rm -f output1.txt"])
|
|
|
|
system(["/bin/sh", "-c", "rm -f output2.txt"])
|
2011-01-26 01:39:43 +08:00
|
|
|
system(["/bin/sh", "-c", "rm -f stderr.txt"])
|
2010-10-08 08:47:30 +08:00
|
|
|
system(["/bin/sh", "-c", "rm -f stdout.txt"])
|
2010-09-16 09:53:04 +08:00
|
|
|
|
2011-02-04 08:50:49 +08:00
|
|
|
def test_apropos_should_also_search_settings_description(self):
|
|
|
|
"""Test that 'apropos' command should also search descriptions for the settings variables."""
|
|
|
|
|
|
|
|
self.expect("apropos 'environment variable'",
|
2011-11-08 10:43:13 +08:00
|
|
|
substrs = ["target.env-vars",
|
2011-02-04 08:50:49 +08:00
|
|
|
"environment variables",
|
|
|
|
"executable's environment"])
|
|
|
|
|
2010-09-08 01:06:13 +08:00
|
|
|
def test_set_prompt(self):
|
|
|
|
"""Test that 'set prompt' actually changes the prompt."""
|
2010-09-08 01:12:10 +08:00
|
|
|
|
2010-09-28 01:36:59 +08:00
|
|
|
# Set prompt to 'lldb2'.
|
2010-12-21 05:29:34 +08:00
|
|
|
self.runCmd("settings set prompt lldb2")
|
2010-09-08 01:12:10 +08:00
|
|
|
|
|
|
|
# Immediately test the setting.
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show prompt", SETTING_MSG("prompt"),
|
2011-04-20 06:32:36 +08:00
|
|
|
startstr = 'prompt (string) = "lldb2"')
|
2010-09-08 01:12:10 +08:00
|
|
|
|
|
|
|
# The overall display should also reflect the new setting.
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show", SETTING_MSG("prompt"),
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = ['prompt (string) = "lldb2"'])
|
2010-09-08 01:06:13 +08:00
|
|
|
|
2010-09-28 01:36:59 +08:00
|
|
|
# Use '-r' option to reset to the original default prompt.
|
|
|
|
self.runCmd("settings set -r prompt")
|
|
|
|
|
2010-09-08 01:31:05 +08:00
|
|
|
def test_set_term_width(self):
|
|
|
|
"""Test that 'set term-width' actually changes the term-width."""
|
|
|
|
|
|
|
|
self.runCmd("settings set term-width 70")
|
|
|
|
|
|
|
|
# Immediately test the setting.
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show term-width", SETTING_MSG("term-width"),
|
2011-04-20 06:32:36 +08:00
|
|
|
startstr = "term-width (int) = 70")
|
2010-09-08 01:31:05 +08:00
|
|
|
|
|
|
|
# The overall display should also reflect the new setting.
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show", SETTING_MSG("term-width"),
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = ["term-width (int) = 70"])
|
2010-09-08 01:31:05 +08:00
|
|
|
|
2010-10-19 01:51:45 +08:00
|
|
|
def test_set_auto_confirm(self):
|
|
|
|
"""Test that after 'set auto-confirm true', manual confirmation should not kick in."""
|
|
|
|
self.buildDefault()
|
|
|
|
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
self.runCmd("settings set auto-confirm true")
|
|
|
|
|
|
|
|
# Immediately test the setting.
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
|
2011-04-20 06:32:36 +08:00
|
|
|
startstr = "auto-confirm (boolean) = true")
|
2010-10-19 01:51:45 +08:00
|
|
|
|
|
|
|
# Now 'breakpoint delete' should just work fine without confirmation
|
|
|
|
# prompt from the command interpreter.
|
|
|
|
self.runCmd("breakpoint set -n main")
|
|
|
|
self.expect("breakpoint delete",
|
|
|
|
startstr = "All breakpoints removed")
|
|
|
|
|
|
|
|
# Restore the original setting of auto-confirm.
|
|
|
|
self.runCmd("settings set -r auto-confirm")
|
2010-10-20 03:39:20 +08:00
|
|
|
self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
|
2011-04-20 06:32:36 +08:00
|
|
|
startstr = "auto-confirm (boolean) = false")
|
2010-10-19 01:51:45 +08:00
|
|
|
|
2010-09-16 06:27:29 +08:00
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
2010-12-15 07:43:29 +08:00
|
|
|
def test_run_args_and_env_vars_with_dsym(self):
|
2010-09-16 06:27:29 +08:00
|
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.pass_run_args_and_env_vars()
|
|
|
|
|
2010-12-15 07:43:29 +08:00
|
|
|
def test_run_args_and_env_vars_with_dwarf(self):
|
2010-09-16 06:27:29 +08:00
|
|
|
"""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.
|
2010-10-20 07:40:13 +08:00
|
|
|
# And add hooks to restore the settings during tearDown().
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd('settings set target.run-args A B C')
|
2010-10-20 07:40:13 +08:00
|
|
|
self.addTearDownHook(
|
2011-11-08 10:43:13 +08:00
|
|
|
lambda: self.runCmd("settings set -r target.run-args"))
|
|
|
|
self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
|
2010-10-20 07:40:13 +08:00
|
|
|
self.addTearDownHook(
|
2011-11-08 10:43:13 +08:00
|
|
|
lambda: self.runCmd("settings set -r target.env-vars"))
|
2010-09-16 06:27:29 +08:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# Read the output file produced by running the program.
|
2010-12-15 07:43:29 +08:00
|
|
|
with open('output2.txt', 'r') as f:
|
2010-10-09 06:10:42 +08:00
|
|
|
output = f.read()
|
2010-09-16 06:27:29 +08:00
|
|
|
|
2010-10-09 04:01:03 +08:00
|
|
|
self.expect(output, exe=False,
|
|
|
|
substrs = ["argv[1] matches",
|
|
|
|
"argv[2] matches",
|
|
|
|
"argv[3] matches",
|
|
|
|
"Environment variable 'MY_ENV_VAR' successfully passed."])
|
2010-09-16 06:27:29 +08:00
|
|
|
|
2010-12-04 08:44:56 +08:00
|
|
|
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'.
|
2011-11-08 10:43:13 +08:00
|
|
|
self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
|
|
|
|
startstr = "target.inherit-env (boolean) = true")
|
2010-12-04 08:44:56 +08:00
|
|
|
|
|
|
|
# Set some host environment variables now.
|
|
|
|
os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
|
|
|
|
os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
|
|
|
|
|
2010-12-15 07:43:29 +08:00
|
|
|
# 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)
|
2010-12-04 08:44:56 +08:00
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# Read the output file produced by running the program.
|
2010-12-15 07:43:29 +08:00
|
|
|
with open('output1.txt', 'r') as f:
|
2010-12-04 08:44:56 +08:00
|
|
|
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."])
|
|
|
|
|
2011-01-26 01:39:43 +08:00
|
|
|
def test_set_error_output_path(self):
|
2011-11-08 10:43:13 +08:00
|
|
|
"""Test that setting target.error/output-path for the launched process works."""
|
2010-09-17 02:26:06 +08:00
|
|
|
self.buildDefault()
|
|
|
|
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
2011-01-26 01:39:43 +08:00
|
|
|
# Set the error-path and output-path and verify both are set.
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd("settings set target.error-path stderr.txt")
|
|
|
|
self.runCmd("settings set target.output-path stdout.txt")
|
2011-01-26 01:39:43 +08:00
|
|
|
# And add hooks to restore the original settings during tearDown().
|
2010-10-20 07:40:13 +08:00
|
|
|
self.addTearDownHook(
|
2011-11-08 10:43:13 +08:00
|
|
|
lambda: self.runCmd("settings set -r target.output-path"))
|
2011-01-26 01:39:43 +08:00
|
|
|
self.addTearDownHook(
|
2011-11-08 10:43:13 +08:00
|
|
|
lambda: self.runCmd("settings set -r target.error-path"))
|
2011-01-26 01:39:43 +08:00
|
|
|
|
2011-11-08 10:43:13 +08:00
|
|
|
self.expect("settings show target.error-path",
|
|
|
|
SETTING_MSG("target.error-path"),
|
|
|
|
startstr = 'target.error-path (string) = "stderr.txt"')
|
2010-10-20 07:40:13 +08:00
|
|
|
|
2011-11-08 10:43:13 +08:00
|
|
|
self.expect("settings show target.output-path",
|
|
|
|
SETTING_MSG("target.output-path"),
|
|
|
|
startstr = 'target.output-path (string) = "stdout.txt"')
|
2010-09-17 02:26:06 +08:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
2011-01-26 01:39:43 +08:00
|
|
|
# The 'stderr.txt' file should now exist.
|
|
|
|
self.assertTrue(os.path.isfile("stderr.txt"),
|
2011-11-08 10:43:13 +08:00
|
|
|
"'stderr.txt' exists due to target.error-path.")
|
2011-01-26 01:39:43 +08:00
|
|
|
|
|
|
|
# Read the output file produced by running the program.
|
|
|
|
with open('stderr.txt', 'r') as f:
|
|
|
|
output = f.read()
|
|
|
|
|
|
|
|
self.expect(output, exe=False,
|
|
|
|
startstr = "This message should go to standard error.")
|
|
|
|
|
2010-10-19 01:51:45 +08:00
|
|
|
# The 'stdout.txt' file should now exist.
|
|
|
|
self.assertTrue(os.path.isfile("stdout.txt"),
|
2011-11-08 10:43:13 +08:00
|
|
|
"'stdout.txt' exists due to target.output-path.")
|
2010-10-19 01:51:45 +08:00
|
|
|
|
2010-09-17 02:26:06 +08:00
|
|
|
# Read the output file produced by running the program.
|
2010-10-09 04:01:03 +08:00
|
|
|
with open('stdout.txt', 'r') as f:
|
|
|
|
output = f.read()
|
2010-09-17 02:26:06 +08:00
|
|
|
|
2010-10-09 04:01:03 +08:00
|
|
|
self.expect(output, exe=False,
|
|
|
|
startstr = "This message should go to standard out.")
|
2010-09-17 02:26:06 +08:00
|
|
|
|
2011-02-01 02:18:54 +08:00
|
|
|
def test_print_dictionary_setting(self):
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.env-vars")
|
|
|
|
self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
|
|
|
|
self.expect ("settings show target.env-vars",
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = [ "MY_VAR=some-value" ])
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.env-vars")
|
2011-02-01 02:18:54 +08:00
|
|
|
|
|
|
|
def test_print_array_setting(self):
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.run-args")
|
|
|
|
self.runCmd ("settings set target.run-args gobbledy-gook")
|
|
|
|
self.expect ("settings show target.run-args",
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = [ '[0]: "gobbledy-gook"' ])
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.run-args")
|
2011-02-01 02:18:54 +08:00
|
|
|
|
|
|
|
def test_settings_with_quotes (self):
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.run-args")
|
|
|
|
self.runCmd ("settings set target.run-args a b c")
|
|
|
|
self.expect ("settings show target.run-args",
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = [ '[0]: "a"',
|
|
|
|
'[1]: "b"',
|
|
|
|
'[2]: "c"' ])
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set target.run-args 'a b c'")
|
|
|
|
self.expect ("settings show target.run-args",
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = [ '[0]: "a b c"' ])
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.run-args")
|
|
|
|
self.runCmd ("settings set -r target.env-vars")
|
|
|
|
self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
|
|
|
|
self.expect ("settings show target.env-vars",
|
2011-04-20 06:32:36 +08:00
|
|
|
substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
|
2011-11-08 10:43:13 +08:00
|
|
|
self.runCmd ("settings set -r target.env-vars")
|
2011-02-01 02:18:54 +08:00
|
|
|
|
2010-09-08 01:06:13 +08:00
|
|
|
|
2011-03-11 06:29:54 +08:00
|
|
|
def test_all_settings_exist (self):
|
|
|
|
self.expect ("settings show",
|
|
|
|
substrs = [ "frame-format (string) = ",
|
|
|
|
"prompt (string) = ",
|
|
|
|
"script-lang (string) = ",
|
|
|
|
"term-width (int) = ",
|
|
|
|
"thread-format (string) = ",
|
|
|
|
"use-external-editor (boolean) = ",
|
|
|
|
"auto-confirm (boolean) = ",
|
2011-04-20 06:32:36 +08:00
|
|
|
"target.default-arch (string) =",
|
2011-03-11 06:29:54 +08:00
|
|
|
"target.expr-prefix (string) = ",
|
2011-11-08 10:43:13 +08:00
|
|
|
"target.run-args (array) =",
|
|
|
|
"target.env-vars (dictionary) =",
|
|
|
|
"target.inherit-env (boolean) = ",
|
|
|
|
"target.input-path (string) = ",
|
|
|
|
"target.output-path (string) = ",
|
|
|
|
"target.error-path (string) = ",
|
|
|
|
"target.disable-aslr (boolean) = ",
|
|
|
|
"target.disable-stdio (boolean) = ",
|
2011-04-20 06:32:36 +08:00
|
|
|
"target.process.thread.step-avoid-regexp (string) =",
|
2011-03-11 06:29:54 +08:00
|
|
|
"target.process.thread.trace-thread (boolean) =" ])
|
|
|
|
|
|
|
|
|
2010-09-08 01:06:13 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|