blob: e49531367c468a49fa1b5596e42c2b75bc0ae2fe [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'",
Greg Clayton1d885962011-11-08 02:43:13 +000026 substrs = ["target.env-vars",
Johnny Chen7fa6c952011-02-04 00:50:49 +000027 "environment variables",
28 "executable's environment"])
29
Johnny Chen8cc80b22012-01-23 19:49:28 +000030 def test_append_target_env_vars(self):
31 """Test that 'replace target.run-args' works."""
32 # Append the env-vars.
33 self.runCmd('settings append target.env-vars MY_ENV_VAR=YES')
34 # And add hooks to restore the settings during tearDown().
35 self.addTearDownHook(
36 lambda: self.runCmd("settings set -r target.env-vars"))
37
38 # Check it immediately!
39 self.expect('settings show target.env-vars',
40 substrs = ['MY_ENV_VAR=YES'])
41
42 def test_insert_before_and_after_target_run_args(self):
43 """Test that 'insert-before/after target.run-args' works."""
44 # Set the run-args first.
45 self.runCmd('settings set target.run-args a b c')
46 # And add hooks to restore the settings during tearDown().
47 self.addTearDownHook(
48 lambda: self.runCmd("settings set -r target.run-args"))
49
50 # Now insert-before the index-0 element with '__a__'.
51 self.runCmd('settings insert-before target.run-args 0 __a__')
52 # And insert-after the index-1 element with '__A__'.
53 self.runCmd('settings insert-after target.run-args 1 __A__')
54 # Check it immediately!
55 self.expect('settings show target.run-args',
56 substrs = ['target.run-args (array) = ',
57 '[0]: "__a__"',
58 '[1]: "a"',
59 '[2]: "__A__"',
60 '[3]: "b"',
61 '[4]: "c"'])
62
Johnny Chen5928f642012-01-21 01:45:18 +000063 def test_replace_target_run_args(self):
64 """Test that 'replace target.run-args' works."""
65 # Set the run-args and then replace the index-0 element.
66 self.runCmd('settings set target.run-args a b c')
67 # And add hooks to restore the settings during tearDown().
68 self.addTearDownHook(
69 lambda: self.runCmd("settings set -r target.run-args"))
70
71 # Now replace the index-0 element with 'A', instead.
72 self.runCmd('settings replace target.run-args 0 A')
73 # Check it immediately!
74 self.expect('settings show target.run-args',
75 substrs = ['target.run-args (array) = ',
76 '[0]: "A"',
77 '[1]: "b"',
78 '[2]: "c"'])
79
Johnny Chen77377772010-09-07 17:06:13 +000080 def test_set_prompt(self):
81 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000082
Johnny Chen23cb3712010-09-27 17:36:59 +000083 # Set prompt to 'lldb2'.
Johnny Chen622220b2010-12-20 21:29:34 +000084 self.runCmd("settings set prompt lldb2")
Johnny Chen881c3712010-09-07 17:12:10 +000085
86 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000087 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000088 startstr = 'prompt (string) = "lldb2"')
Johnny Chen881c3712010-09-07 17:12:10 +000089
90 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000091 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000092 substrs = ['prompt (string) = "lldb2"'])
Johnny Chen77377772010-09-07 17:06:13 +000093
Johnny Chen23cb3712010-09-27 17:36:59 +000094 # Use '-r' option to reset to the original default prompt.
95 self.runCmd("settings set -r prompt")
96
Johnny Chena37764b2010-09-07 17:31:05 +000097 def test_set_term_width(self):
98 """Test that 'set term-width' actually changes the term-width."""
99
Johnny Chena37764b2010-09-07 17:31:05 +0000100 self.runCmd("settings set term-width 70")
101
102 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000103 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000104 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +0000105
106 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000107 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000108 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +0000109
Johnny Chen41b780d2012-01-18 19:07:08 +0000110 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +0000111 def test_set_frame_format(self):
112 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
113 self.buildDefault()
114
115 exe = os.path.join(os.getcwd(), "a.out")
116 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
117
118 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name-with-args}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
119 self.runCmd("settings set frame-format %s" % format_string)
120
121 # Immediately test the setting.
122 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
123 substrs = [format_string])
124
125 self.runCmd("breakpoint set -n main")
126 self.runCmd("run")
127 self.expect("thread backtrace",
128 substrs = ["`main", os.getcwd()])
129
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000130 def test_set_auto_confirm(self):
131 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
132 self.buildDefault()
133
134 exe = os.path.join(os.getcwd(), "a.out")
135 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
136
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000137 self.runCmd("settings set auto-confirm true")
138
139 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000140 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000141 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000142
143 # Now 'breakpoint delete' should just work fine without confirmation
144 # prompt from the command interpreter.
145 self.runCmd("breakpoint set -n main")
146 self.expect("breakpoint delete",
147 startstr = "All breakpoints removed")
148
149 # Restore the original setting of auto-confirm.
150 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000151 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000152 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000153
Johnny Chend5e111c2010-09-15 22:27:29 +0000154 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen24086bc2012-04-06 19:54:10 +0000155 @dsym_test
Johnny Chena245f932010-12-14 23:43:29 +0000156 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000157 """Test that run-args and env-vars are passed to the launched process."""
158 self.buildDsym()
159 self.pass_run_args_and_env_vars()
160
Johnny Chen24086bc2012-04-06 19:54:10 +0000161 @dwarf_test
Johnny Chena245f932010-12-14 23:43:29 +0000162 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000163 """Test that run-args and env-vars are passed to the launched process."""
164 self.buildDwarf()
165 self.pass_run_args_and_env_vars()
166
167 def pass_run_args_and_env_vars(self):
168 """Test that run-args and env-vars are passed to the launched process."""
169 exe = os.path.join(os.getcwd(), "a.out")
170 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
171
172 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000173 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000174 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000175 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000176 lambda: self.runCmd("settings set -r target.run-args"))
177 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000178 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000179 lambda: self.runCmd("settings set -r target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000180
181 self.runCmd("run", RUN_SUCCEEDED)
182
183 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000184 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000185 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000186
Johnny Chenbe7da212010-10-08 20:01:03 +0000187 self.expect(output, exe=False,
188 substrs = ["argv[1] matches",
189 "argv[2] matches",
190 "argv[3] matches",
191 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000192
Johnny Chen80554b82010-12-04 00:44:56 +0000193 def test_pass_host_env_vars(self):
194 """Test that the host env vars are passed to the launched process."""
195 self.buildDefault()
196
197 exe = os.path.join(os.getcwd(), "a.out")
198 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
199
200 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000201 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
202 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000203
204 # Set some host environment variables now.
205 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
206 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
207
Johnny Chena245f932010-12-14 23:43:29 +0000208 # This is the function to unset the two env variables set above.
209 def unset_env_variables():
210 os.environ.pop("MY_HOST_ENV_VAR1")
211 os.environ.pop("MY_HOST_ENV_VAR2")
212
213 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000214 self.runCmd("run", RUN_SUCCEEDED)
215
216 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000217 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000218 output = f.read()
219
220 self.expect(output, exe=False,
221 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
222 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
223
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000224 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000225 """Test that setting target.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000226 self.buildDefault()
227
228 exe = os.path.join(os.getcwd(), "a.out")
229 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
230
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000231 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000232 self.runCmd("settings set target.error-path stderr.txt")
233 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000234 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000235 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000236 lambda: self.runCmd("settings set -r target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000237 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000238 lambda: self.runCmd("settings set -r target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000239
Greg Clayton1d885962011-11-08 02:43:13 +0000240 self.expect("settings show target.error-path",
241 SETTING_MSG("target.error-path"),
242 startstr = 'target.error-path (string) = "stderr.txt"')
Johnny Chen707d8222010-10-19 23:40:13 +0000243
Greg Clayton1d885962011-11-08 02:43:13 +0000244 self.expect("settings show target.output-path",
245 SETTING_MSG("target.output-path"),
246 startstr = 'target.output-path (string) = "stdout.txt"')
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000247
248 self.runCmd("run", RUN_SUCCEEDED)
249
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000250 # The 'stderr.txt' file should now exist.
251 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000252 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000253
254 # Read the output file produced by running the program.
255 with open('stderr.txt', 'r') as f:
256 output = f.read()
257
258 self.expect(output, exe=False,
259 startstr = "This message should go to standard error.")
260
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000261 # The 'stdout.txt' file should now exist.
262 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000263 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000264
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000265 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000266 with open('stdout.txt', 'r') as f:
267 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000268
Johnny Chenbe7da212010-10-08 20:01:03 +0000269 self.expect(output, exe=False,
270 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000271
Caroline Ticec9c235e2011-01-31 18:18:54 +0000272 def test_print_dictionary_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000273 self.runCmd ("settings set -r target.env-vars")
274 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
275 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000276 substrs = [ "MY_VAR=some-value" ])
Greg Clayton1d885962011-11-08 02:43:13 +0000277 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000278
279 def test_print_array_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000280 self.runCmd ("settings set -r target.run-args")
281 self.runCmd ("settings set target.run-args gobbledy-gook")
282 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000283 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000284 self.runCmd ("settings set -r target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000285
286 def test_settings_with_quotes (self):
Greg Clayton1d885962011-11-08 02:43:13 +0000287 self.runCmd ("settings set -r target.run-args")
288 self.runCmd ("settings set target.run-args a b c")
289 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000290 substrs = [ '[0]: "a"',
291 '[1]: "b"',
292 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000293 self.runCmd ("settings set target.run-args 'a b c'")
294 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000295 substrs = [ '[0]: "a b c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000296 self.runCmd ("settings set -r target.run-args")
297 self.runCmd ("settings set -r target.env-vars")
298 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
299 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000300 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000301 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000302
Johnny Chen77377772010-09-07 17:06:13 +0000303
Caroline Ticeb904ca52011-03-10 22:29:54 +0000304 def test_all_settings_exist (self):
305 self.expect ("settings show",
306 substrs = [ "frame-format (string) = ",
307 "prompt (string) = ",
308 "script-lang (string) = ",
309 "term-width (int) = ",
310 "thread-format (string) = ",
311 "use-external-editor (boolean) = ",
312 "auto-confirm (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000313 "target.default-arch (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000314 "target.expr-prefix (string) = ",
Greg Clayton1d885962011-11-08 02:43:13 +0000315 "target.run-args (array) =",
316 "target.env-vars (dictionary) =",
317 "target.inherit-env (boolean) = ",
318 "target.input-path (string) = ",
319 "target.output-path (string) = ",
320 "target.error-path (string) = ",
321 "target.disable-aslr (boolean) = ",
322 "target.disable-stdio (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000323 "target.process.thread.step-avoid-regexp (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000324 "target.process.thread.trace-thread (boolean) =" ])
325
326
Johnny Chen77377772010-09-07 17:06:13 +0000327if __name__ == '__main__':
328 import atexit
329 lldb.SBDebugger.Initialize()
330 atexit.register(lambda: lldb.SBDebugger.Terminate())
331 unittest2.main()