Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb settings command. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class SettingsCommandTestCase(TestBase): |
| 11 | |
| 12 | mydir = "settings" |
| 13 | |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 14 | @classmethod |
| 15 | def classCleanup(cls): |
Johnny Chen | a91b947 | 2010-10-22 21:06:04 +0000 | [diff] [blame] | 16 | """Cleanup the test byproducts.""" |
Filipe Cabecinhas | 0eec15a | 2012-06-20 10:13:40 +0000 | [diff] [blame] | 17 | cls.RemoveTempFile("output1.txt") |
| 18 | cls.RemoveTempFile("output2.txt") |
| 19 | cls.RemoveTempFile("stderr.txt") |
| 20 | cls.RemoveTempFile("stdout.txt") |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 21 | |
Johnny Chen | 7fa6c95 | 2011-02-04 00:50:49 +0000 | [diff] [blame] | 22 | 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 Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 26 | substrs = ["target.env-vars", |
Johnny Chen | 7fa6c95 | 2011-02-04 00:50:49 +0000 | [diff] [blame] | 27 | "environment variables", |
| 28 | "executable's environment"]) |
| 29 | |
Johnny Chen | 8cc80b2 | 2012-01-23 19:49:28 +0000 | [diff] [blame] | 30 | def test_append_target_env_vars(self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 31 | """Test that 'append target.run-args' works.""" |
Johnny Chen | 8cc80b2 | 2012-01-23 19:49:28 +0000 | [diff] [blame] | 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( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 36 | lambda: self.runCmd("settings clear target.env-vars")) |
Johnny Chen | 8cc80b2 | 2012-01-23 19:49:28 +0000 | [diff] [blame] | 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( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 48 | lambda: self.runCmd("settings clear target.run-args")) |
Johnny Chen | 8cc80b2 | 2012-01-23 19:49:28 +0000 | [diff] [blame] | 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', |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 56 | substrs = ['target.run-args', |
Johnny Chen | 8cc80b2 | 2012-01-23 19:49:28 +0000 | [diff] [blame] | 57 | '[0]: "__a__"', |
| 58 | '[1]: "a"', |
| 59 | '[2]: "__A__"', |
| 60 | '[3]: "b"', |
| 61 | '[4]: "c"']) |
| 62 | |
Johnny Chen | 5928f64 | 2012-01-21 01:45:18 +0000 | [diff] [blame] | 63 | 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( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 69 | lambda: self.runCmd("settings clear target.run-args")) |
Johnny Chen | 5928f64 | 2012-01-21 01:45:18 +0000 | [diff] [blame] | 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', |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 75 | substrs = ['target.run-args (arguments) =', |
Johnny Chen | 5928f64 | 2012-01-21 01:45:18 +0000 | [diff] [blame] | 76 | '[0]: "A"', |
| 77 | '[1]: "b"', |
| 78 | '[2]: "c"']) |
| 79 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 80 | def test_set_prompt(self): |
| 81 | """Test that 'set prompt' actually changes the prompt.""" |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 82 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 83 | # Set prompt to 'lldb2'. |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 84 | self.runCmd("settings set prompt 'lldb2 '") |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 85 | |
| 86 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 87 | self.expect("settings show prompt", SETTING_MSG("prompt"), |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 88 | startstr = 'prompt (string) = "lldb2 "') |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 89 | |
| 90 | # The overall display should also reflect the new setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 91 | self.expect("settings show", SETTING_MSG("prompt"), |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 92 | substrs = ['prompt (string) = "lldb2 "']) |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 93 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 94 | # Use '-r' option to reset to the original default prompt. |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 95 | self.runCmd("settings clear prompt") |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 96 | |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 97 | def test_set_term_width(self): |
| 98 | """Test that 'set term-width' actually changes the term-width.""" |
| 99 | |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 100 | self.runCmd("settings set term-width 70") |
| 101 | |
| 102 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 103 | self.expect("settings show term-width", SETTING_MSG("term-width"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 104 | startstr = "term-width (int) = 70") |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 105 | |
| 106 | # The overall display should also reflect the new setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 107 | self.expect("settings show", SETTING_MSG("term-width"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 108 | substrs = ["term-width (int) = 70"]) |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 109 | |
Johnny Chen | 41b780d | 2012-01-18 19:07:08 +0000 | [diff] [blame] | 110 | #rdar://problem/10712130 |
Johnny Chen | 41b780d | 2012-01-18 19:07:08 +0000 | [diff] [blame] | 111 | 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 | |
Filipe Cabecinhas | 5158f3d | 2012-05-18 21:35:43 +0000 | [diff] [blame] | 118 | def cleanup(): |
| 119 | format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}{`${function.name}${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}\n" |
| 120 | self.runCmd("settings set frame-format %s" % format_string, check=False) |
Filipe Cabecinhas | 5158f3d | 2012-05-18 21:35:43 +0000 | [diff] [blame] | 121 | |
| 122 | # Execute the cleanup function during test case tear down. |
| 123 | self.addTearDownHook(cleanup) |
| 124 | |
Johnny Chen | 41b780d | 2012-01-18 19:07:08 +0000 | [diff] [blame] | 125 | format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name-with-args}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n" |
| 126 | self.runCmd("settings set frame-format %s" % format_string) |
| 127 | |
| 128 | # Immediately test the setting. |
| 129 | self.expect("settings show frame-format", SETTING_MSG("frame-format"), |
| 130 | substrs = [format_string]) |
| 131 | |
| 132 | self.runCmd("breakpoint set -n main") |
| 133 | self.runCmd("run") |
| 134 | self.expect("thread backtrace", |
| 135 | substrs = ["`main", os.getcwd()]) |
| 136 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 137 | def test_set_auto_confirm(self): |
| 138 | """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" |
| 139 | self.buildDefault() |
| 140 | |
| 141 | exe = os.path.join(os.getcwd(), "a.out") |
| 142 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 143 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 144 | self.runCmd("settings set auto-confirm true") |
| 145 | |
| 146 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 147 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 148 | startstr = "auto-confirm (boolean) = true") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 149 | |
| 150 | # Now 'breakpoint delete' should just work fine without confirmation |
| 151 | # prompt from the command interpreter. |
| 152 | self.runCmd("breakpoint set -n main") |
| 153 | self.expect("breakpoint delete", |
| 154 | startstr = "All breakpoints removed") |
| 155 | |
| 156 | # Restore the original setting of auto-confirm. |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 157 | self.runCmd("settings clear auto-confirm") |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 158 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 159 | startstr = "auto-confirm (boolean) = false") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 160 | |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 161 | @unittest2.skipUnless(os.uname()[4] in ['i386', 'x86_64'], "requires x86 or x86_64") |
| 162 | def test_disassembler_settings(self): |
| 163 | """Test that user options for the disassembler take effect.""" |
| 164 | self.buildDefault() |
| 165 | |
| 166 | exe = os.path.join(os.getcwd(), "a.out") |
| 167 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 168 | |
| 169 | # AT&T syntax |
| 170 | self.runCmd("settings set target.x86-disassembly-flavor att") |
| 171 | self.runCmd("settings set target.use-hex-immediates false") |
| 172 | self.expect("disassemble -n numberfn", |
| 173 | substrs = ["$90"]) |
| 174 | self.runCmd("settings set target.use-hex-immediates true") |
| 175 | self.runCmd("settings set target.hex-immediate-style c") |
| 176 | self.expect("disassemble -n numberfn", |
| 177 | substrs = ["$0x5a"]) |
| 178 | self.runCmd("settings set target.hex-immediate-style asm") |
| 179 | self.expect("disassemble -n numberfn", |
| 180 | substrs = ["$5ah"]) |
| 181 | |
| 182 | # Intel syntax |
| 183 | self.runCmd("settings set target.x86-disassembly-flavor intel") |
| 184 | self.runCmd("settings set target.use-hex-immediates false") |
| 185 | self.expect("disassemble -n numberfn", |
| 186 | substrs = ["90"]) |
| 187 | self.runCmd("settings set target.use-hex-immediates true") |
| 188 | self.runCmd("settings set target.hex-immediate-style c") |
| 189 | self.expect("disassemble -n numberfn", |
| 190 | substrs = ["0x5a"]) |
| 191 | self.runCmd("settings set target.hex-immediate-style asm") |
| 192 | self.expect("disassemble -n numberfn", |
| 193 | substrs = ["5ah"]) |
| 194 | |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 195 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 196 | @dsym_test |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 197 | def test_run_args_and_env_vars_with_dsym(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 198 | """Test that run-args and env-vars are passed to the launched process.""" |
| 199 | self.buildDsym() |
| 200 | self.pass_run_args_and_env_vars() |
| 201 | |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 202 | @dwarf_test |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 203 | def test_run_args_and_env_vars_with_dwarf(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 204 | """Test that run-args and env-vars are passed to the launched process.""" |
| 205 | self.buildDwarf() |
| 206 | self.pass_run_args_and_env_vars() |
| 207 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 208 | @not_remote_testsuite_ready |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 209 | def pass_run_args_and_env_vars(self): |
| 210 | """Test that run-args and env-vars are passed to the launched process.""" |
| 211 | exe = os.path.join(os.getcwd(), "a.out") |
| 212 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 213 | |
| 214 | # Set the run-args and the env-vars. |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 215 | # And add hooks to restore the settings during tearDown(). |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 216 | self.runCmd('settings set target.run-args A B C') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 217 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 218 | lambda: self.runCmd("settings clear target.run-args")) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 219 | self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 220 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 221 | lambda: self.runCmd("settings clear target.env-vars")) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 222 | |
| 223 | self.runCmd("run", RUN_SUCCEEDED) |
| 224 | |
| 225 | # Read the output file produced by running the program. |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 226 | with open('output2.txt', 'r') as f: |
Johnny Chen | 277c8f0 | 2010-10-08 22:10:42 +0000 | [diff] [blame] | 227 | output = f.read() |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 228 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 229 | self.expect(output, exe=False, |
| 230 | substrs = ["argv[1] matches", |
| 231 | "argv[2] matches", |
| 232 | "argv[3] matches", |
| 233 | "Environment variable 'MY_ENV_VAR' successfully passed."]) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 234 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 235 | @not_remote_testsuite_ready |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 236 | def test_pass_host_env_vars(self): |
| 237 | """Test that the host env vars are passed to the launched process.""" |
| 238 | self.buildDefault() |
| 239 | |
| 240 | exe = os.path.join(os.getcwd(), "a.out") |
| 241 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 242 | |
| 243 | # By default, inherit-env is 'true'. |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 244 | self.expect('settings show target.inherit-env', "Default inherit-env is 'true'", |
| 245 | startstr = "target.inherit-env (boolean) = true") |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 246 | |
| 247 | # Set some host environment variables now. |
| 248 | os.environ["MY_HOST_ENV_VAR1"] = "VAR1" |
| 249 | os.environ["MY_HOST_ENV_VAR2"] = "VAR2" |
| 250 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 251 | # This is the function to unset the two env variables set above. |
| 252 | def unset_env_variables(): |
| 253 | os.environ.pop("MY_HOST_ENV_VAR1") |
| 254 | os.environ.pop("MY_HOST_ENV_VAR2") |
| 255 | |
| 256 | self.addTearDownHook(unset_env_variables) |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 257 | self.runCmd("run", RUN_SUCCEEDED) |
| 258 | |
| 259 | # Read the output file produced by running the program. |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 260 | with open('output1.txt', 'r') as f: |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 261 | output = f.read() |
| 262 | |
| 263 | self.expect(output, exe=False, |
| 264 | substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", |
| 265 | "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) |
| 266 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 267 | @not_remote_testsuite_ready |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 268 | def test_set_error_output_path(self): |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 269 | """Test that setting target.error/output-path for the launched process works.""" |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 270 | self.buildDefault() |
| 271 | |
| 272 | exe = os.path.join(os.getcwd(), "a.out") |
| 273 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 274 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 275 | # Set the error-path and output-path and verify both are set. |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 276 | self.runCmd("settings set target.error-path stderr.txt") |
| 277 | self.runCmd("settings set target.output-path stdout.txt") |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 278 | # And add hooks to restore the original settings during tearDown(). |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 279 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 280 | lambda: self.runCmd("settings clear target.output-path")) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 281 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 282 | lambda: self.runCmd("settings clear target.error-path")) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 283 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 284 | self.expect("settings show target.error-path", |
| 285 | SETTING_MSG("target.error-path"), |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 286 | startstr = 'target.error-path (file) = "stderr.txt"') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 287 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 288 | self.expect("settings show target.output-path", |
| 289 | SETTING_MSG("target.output-path"), |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 290 | startstr = 'target.output-path (file) = "stdout.txt"') |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 291 | |
| 292 | self.runCmd("run", RUN_SUCCEEDED) |
| 293 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 294 | # The 'stderr.txt' file should now exist. |
| 295 | self.assertTrue(os.path.isfile("stderr.txt"), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 296 | "'stderr.txt' exists due to target.error-path.") |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 297 | |
| 298 | # Read the output file produced by running the program. |
| 299 | with open('stderr.txt', 'r') as f: |
| 300 | output = f.read() |
| 301 | |
| 302 | self.expect(output, exe=False, |
| 303 | startstr = "This message should go to standard error.") |
| 304 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 305 | # The 'stdout.txt' file should now exist. |
| 306 | self.assertTrue(os.path.isfile("stdout.txt"), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 307 | "'stdout.txt' exists due to target.output-path.") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 308 | |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 309 | # Read the output file produced by running the program. |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 310 | with open('stdout.txt', 'r') as f: |
| 311 | output = f.read() |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 312 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 313 | self.expect(output, exe=False, |
| 314 | startstr = "This message should go to standard out.") |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 315 | |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 316 | def test_print_dictionary_setting(self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 317 | self.runCmd ("settings clear target.env-vars") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 318 | self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value") |
| 319 | self.expect ("settings show target.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 320 | substrs = [ "MY_VAR=some-value" ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 321 | self.runCmd ("settings clear target.env-vars") |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 322 | |
| 323 | def test_print_array_setting(self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 324 | self.runCmd ("settings clear target.run-args") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 325 | self.runCmd ("settings set target.run-args gobbledy-gook") |
| 326 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 327 | substrs = [ '[0]: "gobbledy-gook"' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 328 | self.runCmd ("settings clear target.run-args") |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 329 | |
| 330 | def test_settings_with_quotes (self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 331 | self.runCmd ("settings clear target.run-args") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 332 | self.runCmd ("settings set target.run-args a b c") |
| 333 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 334 | substrs = [ '[0]: "a"', |
| 335 | '[1]: "b"', |
| 336 | '[2]: "c"' ]) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 337 | self.runCmd ("settings set target.run-args 'a b c'") |
| 338 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 339 | substrs = [ '[0]: "a b c"' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 340 | self.runCmd ("settings clear target.run-args") |
| 341 | self.runCmd ("settings clear target.env-vars") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 342 | self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') |
| 343 | self.expect ("settings show target.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 344 | substrs = [ 'MY_FILE=this is a file name with spaces.txt' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 345 | self.runCmd ("settings clear target.env-vars") |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 346 | |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 347 | def test_settings_with_trailing_whitespace (self): |
| 348 | |
| 349 | # boolean |
| 350 | self.runCmd ("settings set target.skip-prologue true") # Set to known value |
| 351 | self.runCmd ("settings set target.skip-prologue false ") # Set to new value with trailing whitespace |
| 352 | # Make sure the setting was correctly set to "false" |
| 353 | self.expect ("settings show target.skip-prologue", SETTING_MSG("target.skip-prologue"), |
| 354 | startstr = "target.skip-prologue (boolean) = false") |
| 355 | self.runCmd("settings clear target.skip-prologue", check=False) |
| 356 | # integer |
| 357 | self.runCmd ("settings set term-width 70") # Set to known value |
| 358 | self.runCmd ("settings set term-width 60 \t") # Set to new value with trailing whitespaces |
| 359 | self.expect ("settings show term-width", SETTING_MSG("term-width"), |
| 360 | startstr = "term-width (int) = 60") |
| 361 | self.runCmd("settings clear term-width", check=False) |
| 362 | # string |
| 363 | self.runCmd ("settings set target.arg0 abc") # Set to known value |
| 364 | self.runCmd ("settings set target.arg0 cde\t ") # Set to new value with trailing whitespaces |
| 365 | self.expect ("settings show target.arg0", SETTING_MSG("target.arg0"), |
| 366 | startstr = 'target.arg0 (string) = "cde"') |
| 367 | self.runCmd("settings clear target.arg0", check=False) |
| 368 | # file |
| 369 | self.runCmd ("settings set target.output-path /bin/ls") # Set to known value |
| 370 | self.runCmd ("settings set target.output-path /bin/cat ") # Set to new value with trailing whitespaces |
| 371 | self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"), |
Daniel Malea | 7dadf49 | 2013-07-30 21:34:44 +0000 | [diff] [blame] | 372 | startstr = 'target.output-path (file) = ', substrs=['/bin/cat"']) |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 373 | self.runCmd("settings clear target.output-path", check=False) |
| 374 | # enum |
| 375 | self.runCmd ("settings set stop-disassembly-display never") # Set to known value |
| 376 | self.runCmd ("settings set stop-disassembly-display always ") # Set to new value with trailing whitespaces |
| 377 | self.expect ("settings show stop-disassembly-display", SETTING_MSG("stop-disassembly-display"), |
| 378 | startstr = 'stop-disassembly-display (enum) = always') |
| 379 | self.runCmd("settings clear stop-disassembly-display", check=False) |
| 380 | # arguments |
| 381 | self.runCmd ("settings set target.run-args 1 2 3") # Set to known value |
| 382 | self.runCmd ("settings set target.run-args 3 4 5 ") # Set to new value with trailing whitespaces |
| 383 | self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"), |
| 384 | substrs = [ 'target.run-args (arguments) =', |
| 385 | '[0]: "3"', |
| 386 | '[1]: "4"', |
| 387 | '[2]: "5"' ]) |
| 388 | self.runCmd("settings clear target.run-args", check=False) |
| 389 | # dictionaries |
| 390 | self.runCmd ("settings clear target.env-vars") # Set to known value |
| 391 | self.runCmd ("settings set target.env-vars A=B C=D\t ") # Set to new value with trailing whitespaces |
| 392 | self.expect ("settings show target.env-vars", SETTING_MSG("target.env-vars"), |
| 393 | substrs = [ 'target.env-vars (dictionary of strings) =', |
| 394 | 'A=B', |
| 395 | 'C=D']) |
| 396 | self.runCmd("settings clear target.env-vars", check=False) |
| 397 | |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 398 | def test_all_settings_exist (self): |
| 399 | self.expect ("settings show", |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 400 | substrs = [ "auto-confirm", |
| 401 | "frame-format", |
| 402 | "notify-void", |
| 403 | "prompt", |
| 404 | "script-lang", |
| 405 | "stop-disassembly-count", |
| 406 | "stop-disassembly-display", |
| 407 | "stop-line-count-after", |
| 408 | "stop-line-count-before", |
| 409 | "term-width", |
| 410 | "thread-format", |
| 411 | "use-external-editor", |
| 412 | "target.default-arch", |
| 413 | "target.expr-prefix", |
| 414 | "target.prefer-dynamic-value", |
| 415 | "target.enable-synthetic-value", |
| 416 | "target.skip-prologue", |
| 417 | "target.source-map", |
| 418 | "target.exec-search-paths", |
| 419 | "target.max-children-count", |
| 420 | "target.max-string-summary-length", |
| 421 | "target.breakpoints-use-platform-avoid-list", |
| 422 | "target.run-args", |
| 423 | "target.env-vars", |
| 424 | "target.inherit-env", |
| 425 | "target.input-path", |
| 426 | "target.output-path", |
| 427 | "target.error-path", |
| 428 | "target.disable-aslr", |
| 429 | "target.disable-stdio", |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 430 | "target.x86-disassembly-flavor", |
| 431 | "target.use-hex-immediates", |
| 432 | "target.hex-immediate-style", |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 433 | "target.process.disable-memory-cache", |
| 434 | "target.process.extra-startup-command", |
| 435 | "target.process.thread.step-avoid-regexp", |
| 436 | "target.process.thread.trace-thread"]) |
| 437 | |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 438 | |
| 439 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 440 | if __name__ == '__main__': |
| 441 | import atexit |
| 442 | lldb.SBDebugger.Initialize() |
| 443 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 444 | unittest2.main() |