blob: 01af654a1116b06ba23bc95445745ec558254f20 [file] [log] [blame]
Johnny Chen77377772010-09-07 17:06:13 +00001"""
2Test lldb settings command.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class SettingsCommandTestCase(TestBase):
11
12 mydir = "settings"
13
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000014 @classmethod
15 def classCleanup(cls):
Johnny Chena91b9472010-10-22 21:06:04 +000016 """Cleanup the test byproducts."""
Johnny Chena245f932010-12-14 23:43:29 +000017 system(["/bin/sh", "-c", "rm -f output1.txt"])
18 system(["/bin/sh", "-c", "rm -f output2.txt"])
Johnny Chen93b0c8b2011-01-25 17:39:43 +000019 system(["/bin/sh", "-c", "rm -f stderr.txt"])
Johnny Chen138532a2010-10-08 00:47:30 +000020 system(["/bin/sh", "-c", "rm -f stdout.txt"])
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000021
Johnny Chen7fa6c952011-02-04 00:50:49 +000022 def test_apropos_should_also_search_settings_description(self):
23 """Test that 'apropos' command should also search descriptions for the settings variables."""
24
25 self.expect("apropos 'environment variable'",
26 substrs = ["target.process.env-vars",
27 "environment variables",
28 "executable's environment"])
29
Johnny Chen77377772010-09-07 17:06:13 +000030 def test_set_prompt(self):
31 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000032
Johnny Chen23cb3712010-09-27 17:36:59 +000033 # Set prompt to 'lldb2'.
Johnny Chen622220b2010-12-20 21:29:34 +000034 self.runCmd("settings set prompt lldb2")
Johnny Chen881c3712010-09-07 17:12:10 +000035
36 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000037 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000038 startstr = 'prompt (string) = "lldb2"')
Johnny Chen881c3712010-09-07 17:12:10 +000039
40 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000041 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000042 substrs = ['prompt (string) = "lldb2"'])
Johnny Chen77377772010-09-07 17:06:13 +000043
Johnny Chen23cb3712010-09-27 17:36:59 +000044 # Use '-r' option to reset to the original default prompt.
45 self.runCmd("settings set -r prompt")
46
Johnny Chena37764b2010-09-07 17:31:05 +000047 def test_set_term_width(self):
48 """Test that 'set term-width' actually changes the term-width."""
49
Johnny Chena37764b2010-09-07 17:31:05 +000050 self.runCmd("settings set term-width 70")
51
52 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000053 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +000054 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +000055
56 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000057 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +000058 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +000059
Johnny Chen3e9c50c2010-10-18 17:51:45 +000060 def test_set_auto_confirm(self):
61 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
62 self.buildDefault()
63
64 exe = os.path.join(os.getcwd(), "a.out")
65 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
66
Johnny Chen3e9c50c2010-10-18 17:51:45 +000067 self.runCmd("settings set auto-confirm true")
68
69 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000070 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +000071 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +000072
73 # Now 'breakpoint delete' should just work fine without confirmation
74 # prompt from the command interpreter.
75 self.runCmd("breakpoint set -n main")
76 self.expect("breakpoint delete",
77 startstr = "All breakpoints removed")
78
79 # Restore the original setting of auto-confirm.
80 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +000081 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +000082 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +000083
Johnny Chend5e111c2010-09-15 22:27:29 +000084 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chena245f932010-12-14 23:43:29 +000085 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +000086 """Test that run-args and env-vars are passed to the launched process."""
87 self.buildDsym()
88 self.pass_run_args_and_env_vars()
89
Johnny Chena245f932010-12-14 23:43:29 +000090 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +000091 """Test that run-args and env-vars are passed to the launched process."""
92 self.buildDwarf()
93 self.pass_run_args_and_env_vars()
94
95 def pass_run_args_and_env_vars(self):
96 """Test that run-args and env-vars are passed to the launched process."""
97 exe = os.path.join(os.getcwd(), "a.out")
98 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
99
100 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000101 # And add hooks to restore the settings during tearDown().
Johnny Chenf48b6452010-12-14 23:47:55 +0000102 self.runCmd('settings set target.process.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000103 self.addTearDownHook(
104 lambda: self.runCmd("settings set -r target.process.run-args"))
Johnny Chenf48b6452010-12-14 23:47:55 +0000105 self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000106 self.addTearDownHook(
107 lambda: self.runCmd("settings set -r target.process.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000108
109 self.runCmd("run", RUN_SUCCEEDED)
110
111 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000112 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000113 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000114
Johnny Chenbe7da212010-10-08 20:01:03 +0000115 self.expect(output, exe=False,
116 substrs = ["argv[1] matches",
117 "argv[2] matches",
118 "argv[3] matches",
119 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000120
Johnny Chen80554b82010-12-04 00:44:56 +0000121 def test_pass_host_env_vars(self):
122 """Test that the host env vars are passed to the launched process."""
123 self.buildDefault()
124
125 exe = os.path.join(os.getcwd(), "a.out")
126 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
127
128 # By default, inherit-env is 'true'.
129 self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
Greg Clayton4c207172011-04-19 22:32:36 +0000130 startstr = "target.process.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000131
132 # Set some host environment variables now.
133 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
134 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
135
Johnny Chena245f932010-12-14 23:43:29 +0000136 # This is the function to unset the two env variables set above.
137 def unset_env_variables():
138 os.environ.pop("MY_HOST_ENV_VAR1")
139 os.environ.pop("MY_HOST_ENV_VAR2")
140
141 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000142 self.runCmd("run", RUN_SUCCEEDED)
143
144 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000145 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000146 output = f.read()
147
148 self.expect(output, exe=False,
149 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
150 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
151
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000152 def test_set_error_output_path(self):
153 """Test that setting target.process.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000154 self.buildDefault()
155
156 exe = os.path.join(os.getcwd(), "a.out")
157 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
158
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000159 # Set the error-path and output-path and verify both are set.
160 self.runCmd("settings set target.process.error-path stderr.txt")
161 self.runCmd("settings set target.process.output-path stdout.txt")
162 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000163 self.addTearDownHook(
164 lambda: self.runCmd("settings set -r target.process.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000165 self.addTearDownHook(
166 lambda: self.runCmd("settings set -r target.process.error-path"))
167
168 self.expect("settings show target.process.error-path",
169 SETTING_MSG("target.process.error-path"),
Greg Clayton4c207172011-04-19 22:32:36 +0000170 startstr = 'target.process.error-path (string) = "stderr.txt"')
Johnny Chen707d8222010-10-19 23:40:13 +0000171
Caroline Ticedaccaa92010-09-20 20:44:43 +0000172 self.expect("settings show target.process.output-path",
Johnny Chen3343f042010-10-19 19:11:38 +0000173 SETTING_MSG("target.process.output-path"),
Greg Clayton4c207172011-04-19 22:32:36 +0000174 startstr = 'target.process.output-path (string) = "stdout.txt"')
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000175
176 self.runCmd("run", RUN_SUCCEEDED)
177
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000178 # The 'stderr.txt' file should now exist.
179 self.assertTrue(os.path.isfile("stderr.txt"),
180 "'stderr.txt' exists due to target.process.error-path.")
181
182 # Read the output file produced by running the program.
183 with open('stderr.txt', 'r') as f:
184 output = f.read()
185
186 self.expect(output, exe=False,
187 startstr = "This message should go to standard error.")
188
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000189 # The 'stdout.txt' file should now exist.
190 self.assertTrue(os.path.isfile("stdout.txt"),
191 "'stdout.txt' exists due to target.process.output-path.")
192
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000193 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000194 with open('stdout.txt', 'r') as f:
195 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000196
Johnny Chenbe7da212010-10-08 20:01:03 +0000197 self.expect(output, exe=False,
198 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000199
Caroline Ticec9c235e2011-01-31 18:18:54 +0000200 def test_print_dictionary_setting(self):
201 self.runCmd ("settings set -r target.process.env-vars")
202 self.runCmd ("settings set target.process.env-vars [\"MY_VAR\"]=some-value")
203 self.expect ("settings show target.process.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000204 substrs = [ "MY_VAR=some-value" ])
Caroline Ticec9c235e2011-01-31 18:18:54 +0000205 self.runCmd ("settings set -r target.process.env-vars")
206
207 def test_print_array_setting(self):
208 self.runCmd ("settings set -r target.process.run-args")
209 self.runCmd ("settings set target.process.run-args gobbledy-gook")
210 self.expect ("settings show target.process.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000211 substrs = [ '[0]: "gobbledy-gook"' ])
Caroline Ticec9c235e2011-01-31 18:18:54 +0000212 self.runCmd ("settings set -r target.process.run-args")
213
214 def test_settings_with_quotes (self):
215 self.runCmd ("settings set -r target.process.run-args")
216 self.runCmd ("settings set target.process.run-args a b c")
217 self.expect ("settings show target.process.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000218 substrs = [ '[0]: "a"',
219 '[1]: "b"',
220 '[2]: "c"' ])
Caroline Ticec9c235e2011-01-31 18:18:54 +0000221 self.runCmd ("settings set target.process.run-args 'a b c'")
222 self.expect ("settings show target.process.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000223 substrs = [ '[0]: "a b c"' ])
Caroline Ticec9c235e2011-01-31 18:18:54 +0000224 self.runCmd ("settings set -r target.process.run-args")
225 self.runCmd ("settings set -r target.process.env-vars")
Greg Clayton4c207172011-04-19 22:32:36 +0000226 self.runCmd ('settings set target.process.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
Caroline Ticec9c235e2011-01-31 18:18:54 +0000227 self.expect ("settings show target.process.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000228 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Caroline Ticec9c235e2011-01-31 18:18:54 +0000229 self.runCmd ("settings set -r target.process.env-vars")
230
Johnny Chen77377772010-09-07 17:06:13 +0000231
Caroline Ticeb904ca52011-03-10 22:29:54 +0000232 def test_all_settings_exist (self):
233 self.expect ("settings show",
234 substrs = [ "frame-format (string) = ",
235 "prompt (string) = ",
236 "script-lang (string) = ",
237 "term-width (int) = ",
238 "thread-format (string) = ",
239 "use-external-editor (boolean) = ",
240 "auto-confirm (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000241 "target.default-arch (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000242 "target.expr-prefix (string) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000243 "target.process.run-args (array) =",
244 "target.process.env-vars (dictionary) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000245 "target.process.inherit-env (boolean) = ",
246 "target.process.input-path (string) = ",
247 "target.process.output-path (string) = ",
248 "target.process.error-path (string) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000249 "target.process.plugin (enum) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000250 "target.process.disable-aslr (boolean) = ",
251 "target.process.disable-stdio (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000252 "target.process.thread.step-avoid-regexp (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000253 "target.process.thread.trace-thread (boolean) =" ])
254
255
Johnny Chen77377772010-09-07 17:06:13 +0000256if __name__ == '__main__':
257 import atexit
258 lldb.SBDebugger.Initialize()
259 atexit.register(lambda: lldb.SBDebugger.Terminate())
260 unittest2.main()