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