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.""" |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 17 | system(["/bin/sh", "-c", "rm -f output1.txt"]) |
| 18 | system(["/bin/sh", "-c", "rm -f output2.txt"]) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 19 | system(["/bin/sh", "-c", "rm -f stderr.txt"]) |
Johnny Chen | 138532a | 2010-10-08 00:47:30 +0000 | [diff] [blame] | 20 | system(["/bin/sh", "-c", "rm -f 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'", |
| 26 | substrs = ["target.process.env-vars", |
| 27 | "environment variables", |
| 28 | "executable's environment"]) |
| 29 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 30 | def test_set_prompt(self): |
| 31 | """Test that 'set prompt' actually changes the prompt.""" |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 32 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 33 | # Set prompt to 'lldb2'. |
Johnny Chen | 622220b | 2010-12-20 21:29:34 +0000 | [diff] [blame] | 34 | self.runCmd("settings set prompt lldb2") |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 35 | |
| 36 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 37 | self.expect("settings show prompt", SETTING_MSG("prompt"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 38 | startstr = 'prompt (string) = "lldb2"') |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 39 | |
| 40 | # The overall display should also reflect the new setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 41 | self.expect("settings show", SETTING_MSG("prompt"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 42 | substrs = ['prompt (string) = "lldb2"']) |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 43 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 44 | # Use '-r' option to reset to the original default prompt. |
| 45 | self.runCmd("settings set -r prompt") |
| 46 | |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 47 | def test_set_term_width(self): |
| 48 | """Test that 'set term-width' actually changes the term-width.""" |
| 49 | |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 50 | self.runCmd("settings set term-width 70") |
| 51 | |
| 52 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 53 | self.expect("settings show term-width", SETTING_MSG("term-width"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 54 | startstr = "term-width (int) = 70") |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 55 | |
| 56 | # The overall display should also reflect the new setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 57 | self.expect("settings show", SETTING_MSG("term-width"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 58 | substrs = ["term-width (int) = 70"]) |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 59 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 60 | def test_set_auto_confirm(self): |
| 61 | """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" |
| 62 | self.buildDefault() |
| 63 | |
| 64 | exe = os.path.join(os.getcwd(), "a.out") |
| 65 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 66 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 67 | self.runCmd("settings set auto-confirm true") |
| 68 | |
| 69 | # Immediately test the setting. |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 70 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 71 | startstr = "auto-confirm (boolean) = true") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 72 | |
| 73 | # Now 'breakpoint delete' should just work fine without confirmation |
| 74 | # prompt from the command interpreter. |
| 75 | self.runCmd("breakpoint set -n main") |
| 76 | self.expect("breakpoint delete", |
| 77 | startstr = "All breakpoints removed") |
| 78 | |
| 79 | # Restore the original setting of auto-confirm. |
| 80 | self.runCmd("settings set -r auto-confirm") |
Johnny Chen | a913ea4 | 2010-10-19 19:39:20 +0000 | [diff] [blame] | 81 | self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 82 | startstr = "auto-confirm (boolean) = false") |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 83 | |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 84 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 85 | def test_run_args_and_env_vars_with_dsym(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 86 | """Test that run-args and env-vars are passed to the launched process.""" |
| 87 | self.buildDsym() |
| 88 | self.pass_run_args_and_env_vars() |
| 89 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 90 | def test_run_args_and_env_vars_with_dwarf(self): |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 91 | """Test that run-args and env-vars are passed to the launched process.""" |
| 92 | self.buildDwarf() |
| 93 | self.pass_run_args_and_env_vars() |
| 94 | |
| 95 | def pass_run_args_and_env_vars(self): |
| 96 | """Test that run-args and env-vars are passed to the launched process.""" |
| 97 | exe = os.path.join(os.getcwd(), "a.out") |
| 98 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 99 | |
| 100 | # Set the run-args and the env-vars. |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 101 | # And add hooks to restore the settings during tearDown(). |
Johnny Chen | f48b645 | 2010-12-14 23:47:55 +0000 | [diff] [blame] | 102 | self.runCmd('settings set target.process.run-args A B C') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 103 | self.addTearDownHook( |
| 104 | lambda: self.runCmd("settings set -r target.process.run-args")) |
Johnny Chen | f48b645 | 2010-12-14 23:47:55 +0000 | [diff] [blame] | 105 | self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 106 | self.addTearDownHook( |
| 107 | lambda: self.runCmd("settings set -r target.process.env-vars")) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 108 | |
| 109 | self.runCmd("run", RUN_SUCCEEDED) |
| 110 | |
| 111 | # Read the output file produced by running the program. |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 112 | with open('output2.txt', 'r') as f: |
Johnny Chen | 277c8f0 | 2010-10-08 22:10:42 +0000 | [diff] [blame] | 113 | output = f.read() |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 114 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 115 | self.expect(output, exe=False, |
| 116 | substrs = ["argv[1] matches", |
| 117 | "argv[2] matches", |
| 118 | "argv[3] matches", |
| 119 | "Environment variable 'MY_ENV_VAR' successfully passed."]) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 120 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 121 | def test_pass_host_env_vars(self): |
| 122 | """Test that the host env vars are passed to the launched process.""" |
| 123 | self.buildDefault() |
| 124 | |
| 125 | exe = os.path.join(os.getcwd(), "a.out") |
| 126 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 127 | |
| 128 | # By default, inherit-env is 'true'. |
| 129 | self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 130 | startstr = "target.process.inherit-env (boolean) = true") |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 131 | |
| 132 | # Set some host environment variables now. |
| 133 | os.environ["MY_HOST_ENV_VAR1"] = "VAR1" |
| 134 | os.environ["MY_HOST_ENV_VAR2"] = "VAR2" |
| 135 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 136 | # This is the function to unset the two env variables set above. |
| 137 | def unset_env_variables(): |
| 138 | os.environ.pop("MY_HOST_ENV_VAR1") |
| 139 | os.environ.pop("MY_HOST_ENV_VAR2") |
| 140 | |
| 141 | self.addTearDownHook(unset_env_variables) |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 142 | self.runCmd("run", RUN_SUCCEEDED) |
| 143 | |
| 144 | # Read the output file produced by running the program. |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame] | 145 | with open('output1.txt', 'r') as f: |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 146 | output = f.read() |
| 147 | |
| 148 | self.expect(output, exe=False, |
| 149 | substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", |
| 150 | "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) |
| 151 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 152 | def test_set_error_output_path(self): |
| 153 | """Test that setting target.process.error/output-path for the launched process works.""" |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 154 | self.buildDefault() |
| 155 | |
| 156 | exe = os.path.join(os.getcwd(), "a.out") |
| 157 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 158 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 159 | # Set the error-path and output-path and verify both are set. |
| 160 | self.runCmd("settings set target.process.error-path stderr.txt") |
| 161 | self.runCmd("settings set target.process.output-path stdout.txt") |
| 162 | # And add hooks to restore the original settings during tearDown(). |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 163 | self.addTearDownHook( |
| 164 | lambda: self.runCmd("settings set -r target.process.output-path")) |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 165 | self.addTearDownHook( |
| 166 | lambda: self.runCmd("settings set -r target.process.error-path")) |
| 167 | |
| 168 | self.expect("settings show target.process.error-path", |
| 169 | SETTING_MSG("target.process.error-path"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 170 | startstr = 'target.process.error-path (string) = "stderr.txt"') |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 171 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 172 | self.expect("settings show target.process.output-path", |
Johnny Chen | 3343f04 | 2010-10-19 19:11:38 +0000 | [diff] [blame] | 173 | SETTING_MSG("target.process.output-path"), |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 174 | startstr = 'target.process.output-path (string) = "stdout.txt"') |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 175 | |
| 176 | self.runCmd("run", RUN_SUCCEEDED) |
| 177 | |
Johnny Chen | 93b0c8b | 2011-01-25 17:39:43 +0000 | [diff] [blame] | 178 | # The 'stderr.txt' file should now exist. |
| 179 | self.assertTrue(os.path.isfile("stderr.txt"), |
| 180 | "'stderr.txt' exists due to target.process.error-path.") |
| 181 | |
| 182 | # Read the output file produced by running the program. |
| 183 | with open('stderr.txt', 'r') as f: |
| 184 | output = f.read() |
| 185 | |
| 186 | self.expect(output, exe=False, |
| 187 | startstr = "This message should go to standard error.") |
| 188 | |
Johnny Chen | 3e9c50c | 2010-10-18 17:51:45 +0000 | [diff] [blame] | 189 | # The 'stdout.txt' file should now exist. |
| 190 | self.assertTrue(os.path.isfile("stdout.txt"), |
| 191 | "'stdout.txt' exists due to target.process.output-path.") |
| 192 | |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 193 | # Read the output file produced by running the program. |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 194 | with open('stdout.txt', 'r') as f: |
| 195 | output = f.read() |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 196 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame] | 197 | self.expect(output, exe=False, |
| 198 | startstr = "This message should go to standard out.") |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 199 | |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 200 | def test_print_dictionary_setting(self): |
| 201 | self.runCmd ("settings set -r target.process.env-vars") |
| 202 | self.runCmd ("settings set target.process.env-vars [\"MY_VAR\"]=some-value") |
| 203 | self.expect ("settings show target.process.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 204 | substrs = [ "MY_VAR=some-value" ]) |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 205 | self.runCmd ("settings set -r target.process.env-vars") |
| 206 | |
| 207 | def test_print_array_setting(self): |
| 208 | self.runCmd ("settings set -r target.process.run-args") |
| 209 | self.runCmd ("settings set target.process.run-args gobbledy-gook") |
| 210 | self.expect ("settings show target.process.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 211 | substrs = [ '[0]: "gobbledy-gook"' ]) |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 212 | self.runCmd ("settings set -r target.process.run-args") |
| 213 | |
| 214 | def test_settings_with_quotes (self): |
| 215 | self.runCmd ("settings set -r target.process.run-args") |
| 216 | self.runCmd ("settings set target.process.run-args a b c") |
| 217 | self.expect ("settings show target.process.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 218 | substrs = [ '[0]: "a"', |
| 219 | '[1]: "b"', |
| 220 | '[2]: "c"' ]) |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 221 | self.runCmd ("settings set target.process.run-args 'a b c'") |
| 222 | self.expect ("settings show target.process.run-args", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 223 | substrs = [ '[0]: "a b c"' ]) |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 224 | self.runCmd ("settings set -r target.process.run-args") |
| 225 | self.runCmd ("settings set -r target.process.env-vars") |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 226 | self.runCmd ('settings set target.process.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 227 | self.expect ("settings show target.process.env-vars", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 228 | substrs = [ 'MY_FILE=this is a file name with spaces.txt' ]) |
Caroline Tice | c9c235e | 2011-01-31 18:18:54 +0000 | [diff] [blame] | 229 | self.runCmd ("settings set -r target.process.env-vars") |
| 230 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 231 | |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 232 | def test_all_settings_exist (self): |
| 233 | self.expect ("settings show", |
| 234 | substrs = [ "frame-format (string) = ", |
| 235 | "prompt (string) = ", |
| 236 | "script-lang (string) = ", |
| 237 | "term-width (int) = ", |
| 238 | "thread-format (string) = ", |
| 239 | "use-external-editor (boolean) = ", |
| 240 | "auto-confirm (boolean) = ", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 241 | "target.default-arch (string) =", |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 242 | "target.expr-prefix (string) = ", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 243 | "target.process.run-args (array) =", |
| 244 | "target.process.env-vars (dictionary) =", |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 245 | "target.process.inherit-env (boolean) = ", |
| 246 | "target.process.input-path (string) = ", |
| 247 | "target.process.output-path (string) = ", |
| 248 | "target.process.error-path (string) = ", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 249 | "target.process.plugin (enum) =", |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 250 | "target.process.disable-aslr (boolean) = ", |
| 251 | "target.process.disable-stdio (boolean) = ", |
Greg Clayton | 4c20717 | 2011-04-19 22:32:36 +0000 | [diff] [blame^] | 252 | "target.process.thread.step-avoid-regexp (string) =", |
Caroline Tice | b904ca5 | 2011-03-10 22:29:54 +0000 | [diff] [blame] | 253 | "target.process.thread.trace-thread (boolean) =" ]) |
| 254 | |
| 255 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 256 | if __name__ == '__main__': |
| 257 | import atexit |
| 258 | lldb.SBDebugger.Initialize() |
| 259 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 260 | unittest2.main() |