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