Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb settings command. |
| 3 | """ |
| 4 | |
Richard Mitton | 5c98c9a | 2013-10-03 01:50:35 +0000 | [diff] [blame] | 5 | import os, time, re |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class SettingsCommandTestCase(TestBase): |
| 11 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 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(): |
Ashok Thirumurthi | bb82b84 | 2013-09-25 15:30:14 +0000 | [diff] [blame] | 119 | self.runCmd("settings set frame-format %s" % self.format_string, check=False) |
Filipe Cabecinhas | 5158f3d | 2012-05-18 21:35:43 +0000 | [diff] [blame] | 120 | |
| 121 | # Execute the cleanup function during test case tear down. |
| 122 | self.addTearDownHook(cleanup) |
| 123 | |
Ashok Thirumurthi | bb82b84 | 2013-09-25 15:30:14 +0000 | [diff] [blame] | 124 | self.runCmd("settings show frame-format") |
Richard Mitton | 5c98c9a | 2013-10-03 01:50:35 +0000 | [diff] [blame] | 125 | m = re.match( |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 126 | '^frame-format \(format-string\) = "(.*)\"$', |
Richard Mitton | 5c98c9a | 2013-10-03 01:50:35 +0000 | [diff] [blame] | 127 | self.res.GetOutput()) |
| 128 | self.assertTrue(m, "Bad settings string") |
| 129 | self.format_string = m.group(1) |
Ashok Thirumurthi | bb82b84 | 2013-09-25 15:30:14 +0000 | [diff] [blame] | 130 | |
| 131 | # Change the default format to print function.name rather than function.name-with-args |
| 132 | format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n" |
Johnny Chen | 41b780d | 2012-01-18 19:07:08 +0000 | [diff] [blame] | 133 | self.runCmd("settings set frame-format %s" % format_string) |
| 134 | |
| 135 | # Immediately test the setting. |
| 136 | self.expect("settings show frame-format", SETTING_MSG("frame-format"), |
| 137 | substrs = [format_string]) |
| 138 | |
| 139 | self.runCmd("breakpoint set -n main") |
| 140 | self.runCmd("run") |
| 141 | self.expect("thread backtrace", |
| 142 | substrs = ["`main", os.getcwd()]) |
| 143 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 144 | def test_set_auto_confirm(self): |
| 145 | """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" |
| 146 | self.buildDefault() |
| 147 | |
| 148 | exe = os.path.join(os.getcwd(), "a.out") |
| 149 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 150 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 151 | self.runCmd("settings set auto-confirm true") |
| 152 | |
| 153 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 154 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 155 | startstr = "auto-confirm (boolean) = true") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 156 | |
| 157 | # Now 'breakpoint delete' should just work fine without confirmation |
| 158 | # prompt from the command interpreter. |
| 159 | self.runCmd("breakpoint set -n main") |
| 160 | self.expect("breakpoint delete", |
| 161 | startstr = "All breakpoints removed") |
| 162 | |
| 163 | # Restore the original setting of auto-confirm. |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 164 | self.runCmd("settings clear auto-confirm") |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 165 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 166 | startstr = "auto-confirm (boolean) = false") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 167 | |
Tamas Berghammer | 3215d04 | 2015-04-17 09:37:06 +0000 | [diff] [blame] | 168 | @expectedFailureArch("arm") |
| 169 | @expectedFailureArch("aarch64") |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 170 | def test_disassembler_settings(self): |
| 171 | """Test that user options for the disassembler take effect.""" |
| 172 | self.buildDefault() |
| 173 | |
| 174 | exe = os.path.join(os.getcwd(), "a.out") |
| 175 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 176 | |
| 177 | # AT&T syntax |
| 178 | self.runCmd("settings set target.x86-disassembly-flavor att") |
| 179 | self.runCmd("settings set target.use-hex-immediates false") |
| 180 | self.expect("disassemble -n numberfn", |
| 181 | substrs = ["$90"]) |
| 182 | self.runCmd("settings set target.use-hex-immediates true") |
| 183 | self.runCmd("settings set target.hex-immediate-style c") |
| 184 | self.expect("disassemble -n numberfn", |
| 185 | substrs = ["$0x5a"]) |
| 186 | self.runCmd("settings set target.hex-immediate-style asm") |
| 187 | self.expect("disassemble -n numberfn", |
| 188 | substrs = ["$5ah"]) |
| 189 | |
| 190 | # Intel syntax |
| 191 | self.runCmd("settings set target.x86-disassembly-flavor intel") |
| 192 | self.runCmd("settings set target.use-hex-immediates false") |
| 193 | self.expect("disassemble -n numberfn", |
| 194 | substrs = ["90"]) |
| 195 | self.runCmd("settings set target.use-hex-immediates true") |
| 196 | self.runCmd("settings set target.hex-immediate-style c") |
| 197 | self.expect("disassemble -n numberfn", |
| 198 | substrs = ["0x5a"]) |
| 199 | self.runCmd("settings set target.hex-immediate-style asm") |
| 200 | self.expect("disassemble -n numberfn", |
| 201 | substrs = ["5ah"]) |
| 202 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 203 | @skipUnlessDarwin |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 204 | @dsym_test |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 205 | def test_run_args_and_env_vars_with_dsym(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 206 | """Test that run-args and env-vars are passed to the launched process.""" |
| 207 | self.buildDsym() |
| 208 | self.pass_run_args_and_env_vars() |
| 209 | |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 210 | @dwarf_test |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 211 | def test_run_args_and_env_vars_with_dwarf(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 212 | """Test that run-args and env-vars are passed to the launched process.""" |
| 213 | self.buildDwarf() |
| 214 | self.pass_run_args_and_env_vars() |
| 215 | |
| 216 | def pass_run_args_and_env_vars(self): |
| 217 | """Test that run-args and env-vars are passed to the launched process.""" |
| 218 | exe = os.path.join(os.getcwd(), "a.out") |
| 219 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 220 | |
| 221 | # Set the run-args and the env-vars. |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 222 | # And add hooks to restore the settings during tearDown(). |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 223 | self.runCmd('settings set target.run-args A B C') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 224 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 225 | lambda: self.runCmd("settings clear target.run-args")) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 226 | self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 227 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 228 | lambda: self.runCmd("settings clear target.env-vars")) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 229 | |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 230 | self.runCmd("run", RUN_FAILED) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 231 | |
| 232 | # Read the output file produced by running the program. |
Vince Harron | ed7cbb2 | 2015-02-18 23:14:49 +0000 | [diff] [blame] | 233 | if lldb.remote_platform: |
| 234 | self.runCmd('platform get-file "output2.txt" "output2.txt"') |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 235 | with open('output2.txt', 'r') as f: |
Johnny Chen | 277c8f0 | 2010-10-08 22:10:42 +0000 | [diff] [blame] | 236 | output = f.read() |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 237 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 238 | self.expect(output, exe=False, |
| 239 | substrs = ["argv[1] matches", |
| 240 | "argv[2] matches", |
| 241 | "argv[3] matches", |
| 242 | "Environment variable 'MY_ENV_VAR' successfully passed."]) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 243 | |
Vince Harron | ed7cbb2 | 2015-02-18 23:14:49 +0000 | [diff] [blame] | 244 | @skipIfRemote # it doesn't make sense to send host env to remote target |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 245 | def test_pass_host_env_vars(self): |
| 246 | """Test that the host env vars are passed to the launched process.""" |
| 247 | self.buildDefault() |
| 248 | |
| 249 | exe = os.path.join(os.getcwd(), "a.out") |
| 250 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 251 | |
| 252 | # By default, inherit-env is 'true'. |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 253 | self.expect('settings show target.inherit-env', "Default inherit-env is 'true'", |
| 254 | startstr = "target.inherit-env (boolean) = true") |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 255 | |
| 256 | # Set some host environment variables now. |
| 257 | os.environ["MY_HOST_ENV_VAR1"] = "VAR1" |
| 258 | os.environ["MY_HOST_ENV_VAR2"] = "VAR2" |
| 259 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 260 | # This is the function to unset the two env variables set above. |
| 261 | def unset_env_variables(): |
| 262 | os.environ.pop("MY_HOST_ENV_VAR1") |
| 263 | os.environ.pop("MY_HOST_ENV_VAR2") |
| 264 | |
| 265 | self.addTearDownHook(unset_env_variables) |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 266 | self.runCmd("run", RUN_FAILED) |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 267 | |
| 268 | # Read the output file produced by running the program. |
Vince Harron | ed7cbb2 | 2015-02-18 23:14:49 +0000 | [diff] [blame] | 269 | if lldb.remote_platform: |
| 270 | self.runCmd('platform get-file "output1.txt" "output1.txt"') |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 271 | with open('output1.txt', 'r') as f: |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 272 | output = f.read() |
| 273 | |
| 274 | self.expect(output, exe=False, |
| 275 | substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", |
| 276 | "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) |
| 277 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 278 | def test_set_error_output_path(self): |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 279 | """Test that setting target.error/output-path for the launched process works.""" |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 280 | self.buildDefault() |
| 281 | |
| 282 | exe = os.path.join(os.getcwd(), "a.out") |
| 283 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 284 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 285 | # Set the error-path and output-path and verify both are set. |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 286 | self.runCmd("settings set target.error-path stderr.txt") |
| 287 | self.runCmd("settings set target.output-path stdout.txt") |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 288 | # And add hooks to restore the original settings during tearDown(). |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 289 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 290 | lambda: self.runCmd("settings clear target.output-path")) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 291 | self.addTearDownHook( |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 292 | lambda: self.runCmd("settings clear target.error-path")) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 293 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 294 | self.expect("settings show target.error-path", |
| 295 | SETTING_MSG("target.error-path"), |
Vince Harron | 1f4706c | 2015-02-18 23:12:26 +0000 | [diff] [blame] | 296 | substrs = ['target.error-path (file) = "stderr.txt"']) |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 297 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 298 | self.expect("settings show target.output-path", |
| 299 | SETTING_MSG("target.output-path"), |
Vince Harron | 1f4706c | 2015-02-18 23:12:26 +0000 | [diff] [blame] | 300 | substrs = ['target.output-path (file) = "stdout.txt"']) |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 301 | |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 302 | self.runCmd("run", RUN_FAILED) |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 303 | |
Vince Harron | 1f4706c | 2015-02-18 23:12:26 +0000 | [diff] [blame] | 304 | if lldb.remote_platform: |
| 305 | self.runCmd('platform get-file "stderr.txt" "stderr.txt"') |
| 306 | self.runCmd('platform get-file "stdout.txt" "stdout.txt"') |
| 307 | |
| 308 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 309 | # The 'stderr.txt' file should now exist. |
| 310 | self.assertTrue(os.path.isfile("stderr.txt"), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 311 | "'stderr.txt' exists due to target.error-path.") |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 312 | |
| 313 | # Read the output file produced by running the program. |
| 314 | with open('stderr.txt', 'r') as f: |
| 315 | output = f.read() |
| 316 | |
| 317 | self.expect(output, exe=False, |
| 318 | startstr = "This message should go to standard error.") |
| 319 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 320 | # The 'stdout.txt' file should now exist. |
| 321 | self.assertTrue(os.path.isfile("stdout.txt"), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 322 | "'stdout.txt' exists due to target.output-path.") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 323 | |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 324 | # Read the output file produced by running the program. |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 325 | with open('stdout.txt', 'r') as f: |
| 326 | output = f.read() |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 327 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 328 | self.expect(output, exe=False, |
| 329 | startstr = "This message should go to standard out.") |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 330 | |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 331 | def test_print_dictionary_setting(self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 332 | self.runCmd ("settings clear target.env-vars") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 333 | self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value") |
| 334 | self.expect ("settings show target.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 335 | substrs = [ "MY_VAR=some-value" ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 336 | self.runCmd ("settings clear target.env-vars") |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 337 | |
| 338 | def test_print_array_setting(self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 339 | self.runCmd ("settings clear target.run-args") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 340 | self.runCmd ("settings set target.run-args gobbledy-gook") |
| 341 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 342 | substrs = [ '[0]: "gobbledy-gook"' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 343 | self.runCmd ("settings clear target.run-args") |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 344 | |
| 345 | def test_settings_with_quotes (self): |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 346 | self.runCmd ("settings clear target.run-args") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 347 | self.runCmd ("settings set target.run-args a b c") |
| 348 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 349 | substrs = [ '[0]: "a"', |
| 350 | '[1]: "b"', |
| 351 | '[2]: "c"' ]) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 352 | self.runCmd ("settings set target.run-args 'a b c'") |
| 353 | self.expect ("settings show target.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 354 | substrs = [ '[0]: "a b c"' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 355 | self.runCmd ("settings clear target.run-args") |
| 356 | self.runCmd ("settings clear target.env-vars") |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 357 | self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') |
| 358 | self.expect ("settings show target.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 359 | substrs = [ 'MY_FILE=this is a file name with spaces.txt' ]) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 360 | self.runCmd ("settings clear target.env-vars") |
Greg Clayton | b2e0c11 | 2015-06-03 02:02:48 +0000 | [diff] [blame^] | 361 | # Test and make sure that setting "format-string" settings obeys quotes if they are provided |
| 362 | self.runCmd ("settings set thread-format 'abc def' ") |
| 363 | self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"') |
| 364 | self.runCmd ('settings set thread-format "abc def" ') |
| 365 | self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"') |
| 366 | # Make sure when no quotes are provided that we maintain any trailing spaces |
| 367 | self.runCmd ('settings set thread-format abc def ') |
| 368 | self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def "') |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 369 | |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 370 | def test_settings_with_trailing_whitespace (self): |
| 371 | |
| 372 | # boolean |
| 373 | self.runCmd ("settings set target.skip-prologue true") # Set to known value |
| 374 | self.runCmd ("settings set target.skip-prologue false ") # Set to new value with trailing whitespace |
| 375 | # Make sure the setting was correctly set to "false" |
| 376 | self.expect ("settings show target.skip-prologue", SETTING_MSG("target.skip-prologue"), |
| 377 | startstr = "target.skip-prologue (boolean) = false") |
| 378 | self.runCmd("settings clear target.skip-prologue", check=False) |
| 379 | # integer |
| 380 | self.runCmd ("settings set term-width 70") # Set to known value |
| 381 | self.runCmd ("settings set term-width 60 \t") # Set to new value with trailing whitespaces |
| 382 | self.expect ("settings show term-width", SETTING_MSG("term-width"), |
| 383 | startstr = "term-width (int) = 60") |
| 384 | self.runCmd("settings clear term-width", check=False) |
| 385 | # string |
| 386 | self.runCmd ("settings set target.arg0 abc") # Set to known value |
| 387 | self.runCmd ("settings set target.arg0 cde\t ") # Set to new value with trailing whitespaces |
| 388 | self.expect ("settings show target.arg0", SETTING_MSG("target.arg0"), |
| 389 | startstr = 'target.arg0 (string) = "cde"') |
| 390 | self.runCmd("settings clear target.arg0", check=False) |
| 391 | # file |
Zachary Turner | 83887fb | 2015-01-21 00:40:27 +0000 | [diff] [blame] | 392 | path1 = os.path.join(os.getcwd(), "path1.txt") |
| 393 | path2 = os.path.join(os.getcwd(), "path2.txt") |
| 394 | self.runCmd ("settings set target.output-path %s" % path1) # Set to known value |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 395 | self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"), |
Zachary Turner | 83887fb | 2015-01-21 00:40:27 +0000 | [diff] [blame] | 396 | startstr = 'target.output-path (file) = ', substrs=[path1]) |
| 397 | self.runCmd ("settings set target.output-path %s " % path2) # Set to new value with trailing whitespaces |
| 398 | self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"), |
| 399 | startstr = 'target.output-path (file) = ', substrs=[path2]) |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 400 | self.runCmd("settings clear target.output-path", check=False) |
| 401 | # enum |
| 402 | self.runCmd ("settings set stop-disassembly-display never") # Set to known value |
| 403 | self.runCmd ("settings set stop-disassembly-display always ") # Set to new value with trailing whitespaces |
| 404 | self.expect ("settings show stop-disassembly-display", SETTING_MSG("stop-disassembly-display"), |
| 405 | startstr = 'stop-disassembly-display (enum) = always') |
| 406 | self.runCmd("settings clear stop-disassembly-display", check=False) |
| 407 | # arguments |
| 408 | self.runCmd ("settings set target.run-args 1 2 3") # Set to known value |
| 409 | self.runCmd ("settings set target.run-args 3 4 5 ") # Set to new value with trailing whitespaces |
| 410 | self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"), |
| 411 | substrs = [ 'target.run-args (arguments) =', |
| 412 | '[0]: "3"', |
| 413 | '[1]: "4"', |
| 414 | '[2]: "5"' ]) |
Pavel Labath | df50f94 | 2015-02-16 13:13:39 +0000 | [diff] [blame] | 415 | self.runCmd ("settings set target.run-args 1 2 3") # Set to known value |
| 416 | self.runCmd ("settings set target.run-args 3 \ \ ") # Set to new value with trailing whitespaces |
| 417 | self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"), |
| 418 | substrs = [ 'target.run-args (arguments) =', |
| 419 | '[0]: "3"', |
| 420 | '[1]: " "', |
| 421 | '[2]: " "' ]) |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 422 | self.runCmd("settings clear target.run-args", check=False) |
| 423 | # dictionaries |
| 424 | self.runCmd ("settings clear target.env-vars") # Set to known value |
| 425 | self.runCmd ("settings set target.env-vars A=B C=D\t ") # Set to new value with trailing whitespaces |
| 426 | self.expect ("settings show target.env-vars", SETTING_MSG("target.env-vars"), |
| 427 | substrs = [ 'target.env-vars (dictionary of strings) =', |
| 428 | 'A=B', |
| 429 | 'C=D']) |
| 430 | self.runCmd("settings clear target.env-vars", check=False) |
Pavel Labath | df50f94 | 2015-02-16 13:13:39 +0000 | [diff] [blame] | 431 | # regex |
| 432 | self.runCmd ("settings clear target.process.thread.step-avoid-regexp") # Set to known value |
| 433 | self.runCmd ("settings set target.process.thread.step-avoid-regexp foo\\ ") # Set to new value with trailing whitespaces |
| 434 | self.expect ("settings show target.process.thread.step-avoid-regexp", |
| 435 | SETTING_MSG("target.process.thread.step-avoid-regexp"), |
| 436 | substrs = [ 'target.process.thread.step-avoid-regexp (regex) = foo\\ ']) |
| 437 | self.runCmd("settings clear target.process.thread.step-avoid-regexp", check=False) |
| 438 | # format-string |
| 439 | self.runCmd ("settings clear disassembly-format") # Set to known value |
| 440 | self.runCmd ("settings set disassembly-format foo ") # Set to new value with trailing whitespaces |
| 441 | self.expect ("settings show disassembly-format", |
| 442 | SETTING_MSG("disassembly-format"), |
| 443 | substrs = [ 'disassembly-format (format-string) = "foo "']) |
| 444 | self.runCmd("settings clear disassembly-format", check=False) |
Greg Clayton | 0010840 | 2013-03-06 21:17:06 +0000 | [diff] [blame] | 445 | |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 446 | def test_all_settings_exist (self): |
| 447 | self.expect ("settings show", |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 448 | substrs = [ "auto-confirm", |
| 449 | "frame-format", |
| 450 | "notify-void", |
| 451 | "prompt", |
| 452 | "script-lang", |
| 453 | "stop-disassembly-count", |
| 454 | "stop-disassembly-display", |
| 455 | "stop-line-count-after", |
| 456 | "stop-line-count-before", |
| 457 | "term-width", |
| 458 | "thread-format", |
| 459 | "use-external-editor", |
| 460 | "target.default-arch", |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 461 | "target.move-to-nearest-code", |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 462 | "target.expr-prefix", |
| 463 | "target.prefer-dynamic-value", |
| 464 | "target.enable-synthetic-value", |
| 465 | "target.skip-prologue", |
| 466 | "target.source-map", |
| 467 | "target.exec-search-paths", |
| 468 | "target.max-children-count", |
| 469 | "target.max-string-summary-length", |
| 470 | "target.breakpoints-use-platform-avoid-list", |
| 471 | "target.run-args", |
| 472 | "target.env-vars", |
| 473 | "target.inherit-env", |
| 474 | "target.input-path", |
| 475 | "target.output-path", |
| 476 | "target.error-path", |
| 477 | "target.disable-aslr", |
| 478 | "target.disable-stdio", |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 479 | "target.x86-disassembly-flavor", |
| 480 | "target.use-hex-immediates", |
| 481 | "target.hex-immediate-style", |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 482 | "target.process.disable-memory-cache", |
| 483 | "target.process.extra-startup-command", |
| 484 | "target.process.thread.step-avoid-regexp", |
| 485 | "target.process.thread.trace-thread"]) |
| 486 | |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 487 | |
| 488 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 489 | if __name__ == '__main__': |
| 490 | import atexit |
| 491 | lldb.SBDebugger.Initialize() |
| 492 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 493 | unittest2.main() |