blob: b38a255bb899e21d7f3b631d7cad16039238e570 [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
61 @unittest2.expectedFailure
62 def test_set_frame_format(self):
63 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
64 self.buildDefault()
65
66 exe = os.path.join(os.getcwd(), "a.out")
67 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
68
69 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name-with-args}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
70 self.runCmd("settings set frame-format %s" % format_string)
71
72 # Immediately test the setting.
73 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
74 substrs = [format_string])
75
76 self.runCmd("breakpoint set -n main")
77 self.runCmd("run")
78 self.expect("thread backtrace",
79 substrs = ["`main", os.getcwd()])
80
Johnny Chen3e9c50c2010-10-18 17:51:45 +000081 def test_set_auto_confirm(self):
82 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
83 self.buildDefault()
84
85 exe = os.path.join(os.getcwd(), "a.out")
86 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
87
Johnny Chen3e9c50c2010-10-18 17:51:45 +000088 self.runCmd("settings set auto-confirm true")
89
90 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000091 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +000092 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +000093
94 # Now 'breakpoint delete' should just work fine without confirmation
95 # prompt from the command interpreter.
96 self.runCmd("breakpoint set -n main")
97 self.expect("breakpoint delete",
98 startstr = "All breakpoints removed")
99
100 # Restore the original setting of auto-confirm.
101 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000102 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000103 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000104
Johnny Chend5e111c2010-09-15 22:27:29 +0000105 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chena245f932010-12-14 23:43:29 +0000106 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000107 """Test that run-args and env-vars are passed to the launched process."""
108 self.buildDsym()
109 self.pass_run_args_and_env_vars()
110
Johnny Chena245f932010-12-14 23:43:29 +0000111 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000112 """Test that run-args and env-vars are passed to the launched process."""
113 self.buildDwarf()
114 self.pass_run_args_and_env_vars()
115
116 def pass_run_args_and_env_vars(self):
117 """Test that run-args and env-vars are passed to the launched process."""
118 exe = os.path.join(os.getcwd(), "a.out")
119 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
120
121 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000122 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000123 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000124 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000125 lambda: self.runCmd("settings set -r target.run-args"))
126 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000127 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000128 lambda: self.runCmd("settings set -r target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000129
130 self.runCmd("run", RUN_SUCCEEDED)
131
132 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000133 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000134 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000135
Johnny Chenbe7da212010-10-08 20:01:03 +0000136 self.expect(output, exe=False,
137 substrs = ["argv[1] matches",
138 "argv[2] matches",
139 "argv[3] matches",
140 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000141
Johnny Chen80554b82010-12-04 00:44:56 +0000142 def test_pass_host_env_vars(self):
143 """Test that the host env vars are passed to the launched process."""
144 self.buildDefault()
145
146 exe = os.path.join(os.getcwd(), "a.out")
147 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
148
149 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000150 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
151 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000152
153 # Set some host environment variables now.
154 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
155 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
156
Johnny Chena245f932010-12-14 23:43:29 +0000157 # This is the function to unset the two env variables set above.
158 def unset_env_variables():
159 os.environ.pop("MY_HOST_ENV_VAR1")
160 os.environ.pop("MY_HOST_ENV_VAR2")
161
162 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000163 self.runCmd("run", RUN_SUCCEEDED)
164
165 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000166 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000167 output = f.read()
168
169 self.expect(output, exe=False,
170 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
171 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
172
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000173 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000174 """Test that setting target.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000175 self.buildDefault()
176
177 exe = os.path.join(os.getcwd(), "a.out")
178 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
179
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000180 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000181 self.runCmd("settings set target.error-path stderr.txt")
182 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000183 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000184 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000185 lambda: self.runCmd("settings set -r target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000186 self.addTearDownHook(
Greg Clayton1d885962011-11-08 02:43:13 +0000187 lambda: self.runCmd("settings set -r target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000188
Greg Clayton1d885962011-11-08 02:43:13 +0000189 self.expect("settings show target.error-path",
190 SETTING_MSG("target.error-path"),
191 startstr = 'target.error-path (string) = "stderr.txt"')
Johnny Chen707d8222010-10-19 23:40:13 +0000192
Greg Clayton1d885962011-11-08 02:43:13 +0000193 self.expect("settings show target.output-path",
194 SETTING_MSG("target.output-path"),
195 startstr = 'target.output-path (string) = "stdout.txt"')
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000196
197 self.runCmd("run", RUN_SUCCEEDED)
198
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000199 # The 'stderr.txt' file should now exist.
200 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000201 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000202
203 # Read the output file produced by running the program.
204 with open('stderr.txt', 'r') as f:
205 output = f.read()
206
207 self.expect(output, exe=False,
208 startstr = "This message should go to standard error.")
209
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000210 # The 'stdout.txt' file should now exist.
211 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000212 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000213
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000214 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000215 with open('stdout.txt', 'r') as f:
216 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000217
Johnny Chenbe7da212010-10-08 20:01:03 +0000218 self.expect(output, exe=False,
219 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000220
Caroline Ticec9c235e2011-01-31 18:18:54 +0000221 def test_print_dictionary_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000222 self.runCmd ("settings set -r target.env-vars")
223 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
224 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000225 substrs = [ "MY_VAR=some-value" ])
Greg Clayton1d885962011-11-08 02:43:13 +0000226 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000227
228 def test_print_array_setting(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000229 self.runCmd ("settings set -r target.run-args")
230 self.runCmd ("settings set target.run-args gobbledy-gook")
231 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000232 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000233 self.runCmd ("settings set -r target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000234
235 def test_settings_with_quotes (self):
Greg Clayton1d885962011-11-08 02:43:13 +0000236 self.runCmd ("settings set -r target.run-args")
237 self.runCmd ("settings set target.run-args a b c")
238 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000239 substrs = [ '[0]: "a"',
240 '[1]: "b"',
241 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000242 self.runCmd ("settings set target.run-args 'a b c'")
243 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000244 substrs = [ '[0]: "a b c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000245 self.runCmd ("settings set -r target.run-args")
246 self.runCmd ("settings set -r target.env-vars")
247 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
248 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000249 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000250 self.runCmd ("settings set -r target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000251
Johnny Chen77377772010-09-07 17:06:13 +0000252
Caroline Ticeb904ca52011-03-10 22:29:54 +0000253 def test_all_settings_exist (self):
254 self.expect ("settings show",
255 substrs = [ "frame-format (string) = ",
256 "prompt (string) = ",
257 "script-lang (string) = ",
258 "term-width (int) = ",
259 "thread-format (string) = ",
260 "use-external-editor (boolean) = ",
261 "auto-confirm (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000262 "target.default-arch (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000263 "target.expr-prefix (string) = ",
Greg Clayton1d885962011-11-08 02:43:13 +0000264 "target.run-args (array) =",
265 "target.env-vars (dictionary) =",
266 "target.inherit-env (boolean) = ",
267 "target.input-path (string) = ",
268 "target.output-path (string) = ",
269 "target.error-path (string) = ",
270 "target.disable-aslr (boolean) = ",
271 "target.disable-stdio (boolean) = ",
Greg Clayton4c207172011-04-19 22:32:36 +0000272 "target.process.thread.step-avoid-regexp (string) =",
Caroline Ticeb904ca52011-03-10 22:29:54 +0000273 "target.process.thread.trace-thread (boolean) =" ])
274
275
Johnny Chen77377772010-09-07 17:06:13 +0000276if __name__ == '__main__':
277 import atexit
278 lldb.SBDebugger.Initialize()
279 atexit.register(lambda: lldb.SBDebugger.Terminate())
280 unittest2.main()