blob: 12bbb8db6d2aa62d31d16bf7379f4044f476876f [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 Chen138532a2010-10-08 00:47:30 +000019 system(["/bin/sh", "-c", "rm -f stdout.txt"])
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000020
Johnny Chen77377772010-09-07 17:06:13 +000021 def test_set_prompt(self):
22 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000023
Johnny Chen23cb3712010-09-27 17:36:59 +000024 # Set prompt to 'lldb2'.
Johnny Chen622220b2010-12-20 21:29:34 +000025 self.runCmd("settings set prompt lldb2")
Johnny Chen881c3712010-09-07 17:12:10 +000026
27 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000028 self.expect("settings show prompt", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000029 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000030
31 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000032 self.expect("settings show", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000033 substrs = ["prompt (string) = 'lldb2'"])
34
Johnny Chen23cb3712010-09-27 17:36:59 +000035 # Use '-r' option to reset to the original default prompt.
36 self.runCmd("settings set -r prompt")
37
Johnny Chena37764b2010-09-07 17:31:05 +000038 def test_set_term_width(self):
39 """Test that 'set term-width' actually changes the term-width."""
40
Johnny Chena37764b2010-09-07 17:31:05 +000041 self.runCmd("settings set term-width 70")
42
43 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000044 self.expect("settings show term-width", SETTING_MSG("term-width"),
Johnny Chena37764b2010-09-07 17:31:05 +000045 startstr = "term-width (int) = '70'")
46
47 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000048 self.expect("settings show", SETTING_MSG("term-width"),
Johnny Chen138532a2010-10-08 00:47:30 +000049 substrs = ["term-width (int) = '70'"])
Johnny Chena37764b2010-09-07 17:31:05 +000050
Johnny Chen3e9c50c2010-10-18 17:51:45 +000051 def test_set_auto_confirm(self):
52 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
53 self.buildDefault()
54
55 exe = os.path.join(os.getcwd(), "a.out")
56 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
57
Johnny Chen3e9c50c2010-10-18 17:51:45 +000058 self.runCmd("settings set auto-confirm true")
59
60 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000061 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000062 startstr = "auto-confirm (boolean) = 'true'")
63
64 # Now 'breakpoint delete' should just work fine without confirmation
65 # prompt from the command interpreter.
66 self.runCmd("breakpoint set -n main")
67 self.expect("breakpoint delete",
68 startstr = "All breakpoints removed")
69
70 # Restore the original setting of auto-confirm.
71 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +000072 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000073 startstr = "auto-confirm (boolean) = 'false'")
74
Johnny Chend5e111c2010-09-15 22:27:29 +000075 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chena245f932010-12-14 23:43:29 +000076 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +000077 """Test that run-args and env-vars are passed to the launched process."""
78 self.buildDsym()
79 self.pass_run_args_and_env_vars()
80
Johnny Chena245f932010-12-14 23:43:29 +000081 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +000082 """Test that run-args and env-vars are passed to the launched process."""
83 self.buildDwarf()
84 self.pass_run_args_and_env_vars()
85
86 def pass_run_args_and_env_vars(self):
87 """Test that run-args and env-vars are passed to the launched process."""
88 exe = os.path.join(os.getcwd(), "a.out")
89 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
90
91 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +000092 # And add hooks to restore the settings during tearDown().
Johnny Chenf48b6452010-12-14 23:47:55 +000093 self.runCmd('settings set target.process.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +000094 self.addTearDownHook(
95 lambda: self.runCmd("settings set -r target.process.run-args"))
Johnny Chenf48b6452010-12-14 23:47:55 +000096 self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +000097 self.addTearDownHook(
98 lambda: self.runCmd("settings set -r target.process.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +000099
100 self.runCmd("run", RUN_SUCCEEDED)
101
102 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000103 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000104 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000105
Johnny Chenbe7da212010-10-08 20:01:03 +0000106 self.expect(output, exe=False,
107 substrs = ["argv[1] matches",
108 "argv[2] matches",
109 "argv[3] matches",
110 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000111
Johnny Chen80554b82010-12-04 00:44:56 +0000112 def test_pass_host_env_vars(self):
113 """Test that the host env vars are passed to the launched process."""
114 self.buildDefault()
115
116 exe = os.path.join(os.getcwd(), "a.out")
117 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
118
119 # By default, inherit-env is 'true'.
120 self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
121 startstr = "target.process.inherit-env (boolean) = 'true'")
122
123 # Set some host environment variables now.
124 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
125 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
126
Johnny Chena245f932010-12-14 23:43:29 +0000127 # This is the function to unset the two env variables set above.
128 def unset_env_variables():
129 os.environ.pop("MY_HOST_ENV_VAR1")
130 os.environ.pop("MY_HOST_ENV_VAR2")
131
132 self.addTearDownHook(unset_env_variables)
Johnny Chen80554b82010-12-04 00:44:56 +0000133 self.runCmd("run", RUN_SUCCEEDED)
134
135 # Read the output file produced by running the program.
Johnny Chena245f932010-12-14 23:43:29 +0000136 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000137 output = f.read()
138
139 self.expect(output, exe=False,
140 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
141 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
142
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000143 @unittest2.expectedFailure
144 # rdar://problem/8435794
Caroline Ticedaccaa92010-09-20 20:44:43 +0000145 # settings set target.process.output-path does not seem to work
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000146 def test_set_output_path(self):
Caroline Ticedaccaa92010-09-20 20:44:43 +0000147 """Test that setting target.process.output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000148 self.buildDefault()
149
150 exe = os.path.join(os.getcwd(), "a.out")
151 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
152
153 # Set the output-path and verify it is set.
Caroline Ticedaccaa92010-09-20 20:44:43 +0000154 self.runCmd("settings set target.process.output-path 'stdout.txt'")
Johnny Chen707d8222010-10-19 23:40:13 +0000155 # And add a hook to restore original setting of target.process.output-path
156 # later on during tearDown().
157 self.addTearDownHook(
158 lambda: self.runCmd("settings set -r target.process.output-path"))
159
Caroline Ticedaccaa92010-09-20 20:44:43 +0000160 self.expect("settings show target.process.output-path",
Johnny Chen3343f042010-10-19 19:11:38 +0000161 SETTING_MSG("target.process.output-path"),
Caroline Ticedaccaa92010-09-20 20:44:43 +0000162 startstr = "target.process.output-path (string) = 'stdout.txt'")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000163
164 self.runCmd("run", RUN_SUCCEEDED)
165
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000166 # The 'stdout.txt' file should now exist.
167 self.assertTrue(os.path.isfile("stdout.txt"),
168 "'stdout.txt' exists due to target.process.output-path.")
169
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000170 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000171 with open('stdout.txt', 'r') as f:
172 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000173
Johnny Chenbe7da212010-10-08 20:01:03 +0000174 self.expect(output, exe=False,
175 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000176
Johnny Chen77377772010-09-07 17:06:13 +0000177
178if __name__ == '__main__':
179 import atexit
180 lldb.SBDebugger.Initialize()
181 atexit.register(lambda: lldb.SBDebugger.Terminate())
182 unittest2.main()