blob: aad7db85df652b7116c755a6e2541d6e5d4460ee [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 Chen5928f642012-01-21 01:45:18 +000030 def test_replace_target_run_args(self):
31 """Test that 'replace target.run-args' works."""
32 # Set the run-args and then replace the index-0 element.
33 self.runCmd('settings set target.run-args a b c')
34 # And add hooks to restore the settings during tearDown().
35 self.addTearDownHook(
36 lambda: self.runCmd("settings set -r target.run-args"))
37
38 # Now replace the index-0 element with 'A', instead.
39 self.runCmd('settings replace target.run-args 0 A')
40 # Check it immediately!
41 self.expect('settings show target.run-args',
42 substrs = ['target.run-args (array) = ',
43 '[0]: "A"',
44 '[1]: "b"',
45 '[2]: "c"'])
46
Johnny Chen77377772010-09-07 17:06:13 +000047 def test_set_prompt(self):
48 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000049
Johnny Chen23cb3712010-09-27 17:36:59 +000050 # Set prompt to 'lldb2'.
Johnny Chen622220b2010-12-20 21:29:34 +000051 self.runCmd("settings set prompt lldb2")
Johnny Chen881c3712010-09-07 17:12:10 +000052
53 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000054 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000055 startstr = 'prompt (string) = "lldb2"')
Johnny Chen881c3712010-09-07 17:12:10 +000056
57 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000058 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton4c207172011-04-19 22:32:36 +000059 substrs = ['prompt (string) = "lldb2"'])
Johnny Chen77377772010-09-07 17:06:13 +000060
Johnny Chen23cb3712010-09-27 17:36:59 +000061 # Use '-r' option to reset to the original default prompt.
62 self.runCmd("settings set -r prompt")
63
Johnny Chena37764b2010-09-07 17:31:05 +000064 def test_set_term_width(self):
65 """Test that 'set term-width' actually changes the term-width."""
66
Johnny Chena37764b2010-09-07 17:31:05 +000067 self.runCmd("settings set term-width 70")
68
69 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000070 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +000071 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +000072
73 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000074 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +000075 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +000076
Johnny Chen41b780d2012-01-18 19:07:08 +000077 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +000078 def test_set_frame_format(self):
79 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
80 self.buildDefault()
81
82 exe = os.path.join(os.getcwd(), "a.out")
83 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
84
85 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name-with-args}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
86 self.runCmd("settings set frame-format %s" % format_string)
87
88 # Immediately test the setting.
89 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
90 substrs = [format_string])
91
92 self.runCmd("breakpoint set -n main")
93 self.runCmd("run")
94 self.expect("thread backtrace",
95 substrs = ["`main", os.getcwd()])
96
Johnny Chen3e9c50c2010-10-18 17:51:45 +000097 def test_set_auto_confirm(self):
98 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
99 self.buildDefault()
100
101 exe = os.path.join(os.getcwd(), "a.out")
102 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
103
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000104 self.runCmd("settings set auto-confirm true")
105
106 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000107 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000108 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000109
110 # Now 'breakpoint delete' should just work fine without confirmation
111 # prompt from the command interpreter.
112 self.runCmd("breakpoint set -n main")
113 self.expect("breakpoint delete",
114 startstr = "All breakpoints removed")
115
116 # Restore the original setting of auto-confirm.
117 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000118 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000119 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000120
Johnny Chend5e111c2010-09-15 22:27:29 +0000121 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chena245f932010-12-14 23:43:29 +0000122 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000123 """Test that run-args and env-vars are passed to the launched process."""
124 self.buildDsym()
125 self.pass_run_args_and_env_vars()
126
Johnny Chena245f932010-12-14 23:43:29 +0000127 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000128 """Test that run-args and env-vars are passed to the launched process."""
129 self.buildDwarf()
130 self.pass_run_args_and_env_vars()
131
132 def pass_run_args_and_env_vars(self):
133 """Test that run-args and env-vars are passed to the launched process."""
134 exe = os.path.join(os.getcwd(), "a.out")
135 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
136
137 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000138 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000139 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000140 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000141 lambda: self.runCmd("settings set -r target.run-args"))
142 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000143 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000144 lambda: self.runCmd("settings set -r target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000145
146 self.runCmd("run", RUN_SUCCEEDED)
147
148 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000149 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000150 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000151
Johnny Chenbe7da212010-10-08 20:01:03 +0000152 self.expect(output, exe=False,
153 substrs = ["argv[1] matches",
154 "argv[2] matches",
155 "argv[3] matches",
156 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000157
Johnny Chen80554b82010-12-04 00:44:56 +0000158 def test_pass_host_env_vars(self):
159 """Test that the host env vars are passed to the launched process."""
160 self.buildDefault()
161
162 exe = os.path.join(os.getcwd(), "a.out")
163 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
164
165 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000166 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
167 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000168
169 # Set some host environment variables now.
170 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
171 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
172
Johnny Chena245f932010-12-14 23:43:29 +0000173 # This is the function to unset the two env variables set above.
174 def unset_env_variables():
175 os.environ.pop("MY_HOST_ENV_VAR1")
176 os.environ.pop("MY_HOST_ENV_VAR2")
177
178 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000179 self.runCmd("run", RUN_SUCCEEDED)
180
181 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000182 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000183 output = f.read()
184
185 self.expect(output, exe=False,
186 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
187 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
188
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000189 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000190 """Test that setting target.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000191 self.buildDefault()
192
193 exe = os.path.join(os.getcwd(), "a.out")
194 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
195
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000196 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000197 self.runCmd("settings set target.error-path stderr.txt")
198 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000199 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000200 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000201 lambda: self.runCmd("settings set -r target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000202 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000203 lambda: self.runCmd("settings set -r target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000204
Greg Clayton1d885962011-11-08 02:43:13 +0000205 self.expect("settings show target.error-path",
206 SETTING_MSG("target.error-path"),
207 startstr = 'target.error-path (string) = "stderr.txt"')
Johnny Chen707d8222010-10-19 23:40:13 +0000208
Greg Clayton1d885962011-11-08 02:43:13 +0000209 self.expect("settings show target.output-path",
210 SETTING_MSG("target.output-path"),
211 startstr = 'target.output-path (string) = "stdout.txt"')
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000212
213 self.runCmd("run", RUN_SUCCEEDED)
214
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000215 # The 'stderr.txt' file should now exist.
216 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000217 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000218
219 # Read the output file produced by running the program.
220 with open('stderr.txt', 'r') as f:
221 output = f.read()
222
223 self.expect(output, exe=False,
224 startstr = "This message should go to standard error.")
225
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000226 # The 'stdout.txt' file should now exist.
227 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000228 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000229
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000230 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000231 with open('stdout.txt', 'r') as f:
232 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000233
Johnny Chenbe7da212010-10-08 20:01:03 +0000234 self.expect(output, exe=False,
235 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000236
Caroline Ticec9c235e2011-01-31 18:18:54 +0000237 def test_print_dictionary_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000238 self.runCmd ("settings set -r target.env-vars")
239 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
240 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000241 substrs = [ "MY_VAR=some-value" ])
Greg Clayton1d885962011-11-08 02:43:13 +0000242 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000243
244 def test_print_array_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000245 self.runCmd ("settings set -r target.run-args")
246 self.runCmd ("settings set target.run-args gobbledy-gook")
247 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000248 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000249 self.runCmd ("settings set -r target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000250
251 def test_settings_with_quotes (self):
Greg Clayton1d885962011-11-08 02:43:13 +0000252 self.runCmd ("settings set -r target.run-args")
253 self.runCmd ("settings set target.run-args a b c")
254 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000255 substrs = [ '[0]: "a"',
256 '[1]: "b"',
257 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000258 self.runCmd ("settings set target.run-args 'a b c'")
259 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000260 substrs = [ '[0]: "a b c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000261 self.runCmd ("settings set -r target.run-args")
262 self.runCmd ("settings set -r target.env-vars")
263 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
264 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000265 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000266 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000267
Johnny Chen77377772010-09-07 17:06:13 +0000268
Caroline Ticeb904ca52011-03-10 22:29:54 +0000269 def test_all_settings_exist (self):
270 self.expect ("settings show",
271 substrs = [ "frame-format (string) = ",
272 "prompt (string) = ",
273 "script-lang (string) = ",
274 "term-width (int) = ",
275 "thread-format (string) = ",
276 "use-external-editor (boolean) = ",
277 "auto-confirm (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000278 "target.default-arch (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000279 "target.expr-prefix (string) = ",
Greg Clayton1d885962011-11-08 02:43:13 +0000280 "target.run-args (array) =",
281 "target.env-vars (dictionary) =",
282 "target.inherit-env (boolean) = ",
283 "target.input-path (string) = ",
284 "target.output-path (string) = ",
285 "target.error-path (string) = ",
286 "target.disable-aslr (boolean) = ",
287 "target.disable-stdio (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000288 "target.process.thread.step-avoid-regexp (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000289 "target.process.thread.trace-thread (boolean) =" ])
290
291
Johnny Chen77377772010-09-07 17:06:13 +0000292if __name__ == '__main__':
293 import atexit
294 lldb.SBDebugger.Initialize()
295 atexit.register(lambda: lldb.SBDebugger.Terminate())
296 unittest2.main()