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