blob: 696cc943511b0ecc71bb4c5c1a6c38eb806238d3 [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 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 Chen41b780d2012-01-18 19:07:08 +000060 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +000061 def test_set_frame_format(self):
62 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
63 self.buildDefault()
64
65 exe = os.path.join(os.getcwd(), "a.out")
66 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
67
68 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name-with-args}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
69 self.runCmd("settings set frame-format %s" % format_string)
70
71 # Immediately test the setting.
72 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
73 substrs = [format_string])
74
75 self.runCmd("breakpoint set -n main")
76 self.runCmd("run")
77 self.expect("thread backtrace",
78 substrs = ["`main", os.getcwd()])
79
Johnny Chen3e9c50c2010-10-18 17:51:45 +000080 def test_set_auto_confirm(self):
81 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
82 self.buildDefault()
83
84 exe = os.path.join(os.getcwd(), "a.out")
85 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
86
Johnny Chen3e9c50c2010-10-18 17:51:45 +000087 self.runCmd("settings set auto-confirm true")
88
89 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000090 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +000091 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +000092
93 # Now 'breakpoint delete' should just work fine without confirmation
94 # prompt from the command interpreter.
95 self.runCmd("breakpoint set -n main")
96 self.expect("breakpoint delete",
97 startstr = "All breakpoints removed")
98
99 # Restore the original setting of auto-confirm.
100 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000101 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000102 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000103
Johnny Chend5e111c2010-09-15 22:27:29 +0000104 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chena245f932010-12-14 23:43:29 +0000105 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000106 """Test that run-args and env-vars are passed to the launched process."""
107 self.buildDsym()
108 self.pass_run_args_and_env_vars()
109
Johnny Chena245f932010-12-14 23:43:29 +0000110 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000111 """Test that run-args and env-vars are passed to the launched process."""
112 self.buildDwarf()
113 self.pass_run_args_and_env_vars()
114
115 def pass_run_args_and_env_vars(self):
116 """Test that run-args and env-vars are passed to the launched process."""
117 exe = os.path.join(os.getcwd(), "a.out")
118 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
119
120 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000121 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000122 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000123 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000124 lambda: self.runCmd("settings set -r target.run-args"))
125 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000126 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000127 lambda: self.runCmd("settings set -r target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000128
129 self.runCmd("run", RUN_SUCCEEDED)
130
131 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000132 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000133 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000134
Johnny Chenbe7da212010-10-08 20:01:03 +0000135 self.expect(output, exe=False,
136 substrs = ["argv[1] matches",
137 "argv[2] matches",
138 "argv[3] matches",
139 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000140
Johnny Chen80554b82010-12-04 00:44:56 +0000141 def test_pass_host_env_vars(self):
142 """Test that the host env vars are passed to the launched process."""
143 self.buildDefault()
144
145 exe = os.path.join(os.getcwd(), "a.out")
146 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
147
148 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000149 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
150 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000151
152 # Set some host environment variables now.
153 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
154 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
155
Johnny Chena245f932010-12-14 23:43:29 +0000156 # This is the function to unset the two env variables set above.
157 def unset_env_variables():
158 os.environ.pop("MY_HOST_ENV_VAR1")
159 os.environ.pop("MY_HOST_ENV_VAR2")
160
161 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000162 self.runCmd("run", RUN_SUCCEEDED)
163
164 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000165 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000166 output = f.read()
167
168 self.expect(output, exe=False,
169 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
170 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
171
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000172 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000173 """Test that setting target.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000174 self.buildDefault()
175
176 exe = os.path.join(os.getcwd(), "a.out")
177 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
178
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000179 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000180 self.runCmd("settings set target.error-path stderr.txt")
181 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000182 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000183 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000184 lambda: self.runCmd("settings set -r target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000185 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000186 lambda: self.runCmd("settings set -r target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000187
Greg Clayton1d885962011-11-08 02:43:13 +0000188 self.expect("settings show target.error-path",
189 SETTING_MSG("target.error-path"),
190 startstr = 'target.error-path (string) = "stderr.txt"')
Johnny Chen707d8222010-10-19 23:40:13 +0000191
Greg Clayton1d885962011-11-08 02:43:13 +0000192 self.expect("settings show target.output-path",
193 SETTING_MSG("target.output-path"),
194 startstr = 'target.output-path (string) = "stdout.txt"')
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000195
196 self.runCmd("run", RUN_SUCCEEDED)
197
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000198 # The 'stderr.txt' file should now exist.
199 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000200 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000201
202 # Read the output file produced by running the program.
203 with open('stderr.txt', 'r') as f:
204 output = f.read()
205
206 self.expect(output, exe=False,
207 startstr = "This message should go to standard error.")
208
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000209 # The 'stdout.txt' file should now exist.
210 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000211 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000212
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000213 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000214 with open('stdout.txt', 'r') as f:
215 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000216
Johnny Chenbe7da212010-10-08 20:01:03 +0000217 self.expect(output, exe=False,
218 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000219
Caroline Ticec9c235e2011-01-31 18:18:54 +0000220 def test_print_dictionary_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000221 self.runCmd ("settings set -r target.env-vars")
222 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
223 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000224 substrs = [ "MY_VAR=some-value" ])
Greg Clayton1d885962011-11-08 02:43:13 +0000225 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000226
227 def test_print_array_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000228 self.runCmd ("settings set -r target.run-args")
229 self.runCmd ("settings set target.run-args gobbledy-gook")
230 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000231 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000232 self.runCmd ("settings set -r target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000233
234 def test_settings_with_quotes (self):
Greg Clayton1d885962011-11-08 02:43:13 +0000235 self.runCmd ("settings set -r target.run-args")
236 self.runCmd ("settings set target.run-args a b c")
237 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000238 substrs = [ '[0]: "a"',
239 '[1]: "b"',
240 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000241 self.runCmd ("settings set target.run-args 'a b c'")
242 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000243 substrs = [ '[0]: "a b c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000244 self.runCmd ("settings set -r target.run-args")
245 self.runCmd ("settings set -r target.env-vars")
246 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
247 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000248 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000249 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000250
Johnny Chen77377772010-09-07 17:06:13 +0000251
Caroline Ticeb904ca52011-03-10 22:29:54 +0000252 def test_all_settings_exist (self):
253 self.expect ("settings show",
254 substrs = [ "frame-format (string) = ",
255 "prompt (string) = ",
256 "script-lang (string) = ",
257 "term-width (int) = ",
258 "thread-format (string) = ",
259 "use-external-editor (boolean) = ",
260 "auto-confirm (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000261 "target.default-arch (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000262 "target.expr-prefix (string) = ",
Greg Clayton1d885962011-11-08 02:43:13 +0000263 "target.run-args (array) =",
264 "target.env-vars (dictionary) =",
265 "target.inherit-env (boolean) = ",
266 "target.input-path (string) = ",
267 "target.output-path (string) = ",
268 "target.error-path (string) = ",
269 "target.disable-aslr (boolean) = ",
270 "target.disable-stdio (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000271 "target.process.thread.step-avoid-regexp (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000272 "target.process.thread.trace-thread (boolean) =" ])
273
274
Johnny Chen77377772010-09-07 17:06:13 +0000275if __name__ == '__main__':
276 import atexit
277 lldb.SBDebugger.Initialize()
278 atexit.register(lambda: lldb.SBDebugger.Terminate())
279 unittest2.main()