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 | 138532a | 2010-10-08 00:47:30 +0000 | [diff] [blame] | 16 | system(["/bin/sh", "-c", "rm -f output.txt"]) |
| 17 | system(["/bin/sh", "-c", "rm -f stdout.txt"]) |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 18 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 19 | def test_set_prompt(self): |
| 20 | """Test that 'set prompt' actually changes the prompt.""" |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 21 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 22 | # Set prompt to 'lldb2'. |
| 23 | self.runCmd("settings set prompt 'lldb2'") |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 24 | |
| 25 | # Immediately test the setting. |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 26 | self.expect("settings show prompt", |
| 27 | startstr = "prompt (string) = 'lldb2'") |
Johnny Chen | 881c371 | 2010-09-07 17:12:10 +0000 | [diff] [blame] | 28 | |
| 29 | # The overall display should also reflect the new setting. |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 30 | self.expect("settings show", |
| 31 | substrs = ["prompt (string) = 'lldb2'"]) |
| 32 | |
Johnny Chen | 23cb371 | 2010-09-27 17:36:59 +0000 | [diff] [blame] | 33 | # Use '-r' option to reset to the original default prompt. |
| 34 | self.runCmd("settings set -r prompt") |
| 35 | |
Johnny Chen | a37764b | 2010-09-07 17:31:05 +0000 | [diff] [blame] | 36 | def test_set_term_width(self): |
| 37 | """Test that 'set term-width' actually changes the term-width.""" |
| 38 | |
| 39 | # No '-o' option is needed for static setting. |
| 40 | self.runCmd("settings set term-width 70") |
| 41 | |
| 42 | # Immediately test the setting. |
| 43 | self.expect("settings show term-width", |
| 44 | startstr = "term-width (int) = '70'") |
| 45 | |
| 46 | # The overall display should also reflect the new setting. |
| 47 | self.expect("settings show", |
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 | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 50 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 51 | def test_with_dsym(self): |
| 52 | """Test that run-args and env-vars are passed to the launched process.""" |
| 53 | self.buildDsym() |
| 54 | self.pass_run_args_and_env_vars() |
| 55 | |
| 56 | def test_with_dwarf(self): |
| 57 | """Test that run-args and env-vars are passed to the launched process.""" |
| 58 | self.buildDwarf() |
| 59 | self.pass_run_args_and_env_vars() |
| 60 | |
| 61 | def pass_run_args_and_env_vars(self): |
| 62 | """Test that run-args and env-vars are passed to the launched process.""" |
| 63 | exe = os.path.join(os.getcwd(), "a.out") |
| 64 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 65 | |
| 66 | # Set the run-args and the env-vars. |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 67 | self.runCmd('settings set target.process.run-args A B C') |
| 68 | self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES') |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 69 | |
| 70 | self.runCmd("run", RUN_SUCCEEDED) |
| 71 | |
| 72 | # Read the output file produced by running the program. |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 73 | output = open('output.txt', 'r').read() |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 74 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame^] | 75 | self.expect(output, exe=False, |
| 76 | substrs = ["argv[1] matches", |
| 77 | "argv[2] matches", |
| 78 | "argv[3] matches", |
| 79 | "Environment variable 'MY_ENV_VAR' successfully passed."]) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 80 | |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 81 | @unittest2.expectedFailure |
| 82 | # rdar://problem/8435794 |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 83 | # settings set target.process.output-path does not seem to work |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 84 | def test_set_output_path(self): |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 85 | """Test that setting target.process.output-path for the launched process works.""" |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 86 | self.buildDefault() |
| 87 | |
| 88 | exe = os.path.join(os.getcwd(), "a.out") |
| 89 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 90 | |
| 91 | # Set the output-path and verify it is set. |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 92 | self.runCmd("settings set target.process.output-path 'stdout.txt'") |
| 93 | self.expect("settings show target.process.output-path", |
| 94 | startstr = "target.process.output-path (string) = 'stdout.txt'") |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 95 | |
| 96 | self.runCmd("run", RUN_SUCCEEDED) |
| 97 | |
| 98 | # Read the output file produced by running the program. |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame^] | 99 | with open('stdout.txt', 'r') as f: |
| 100 | output = f.read() |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 101 | |
Johnny Chen | be7da21 | 2010-10-08 20:01:03 +0000 | [diff] [blame^] | 102 | self.expect(output, exe=False, |
| 103 | startstr = "This message should go to standard out.") |
Johnny Chen | 2fcc0e5 | 2010-09-16 18:26:06 +0000 | [diff] [blame] | 104 | |
Johnny Chen | 7737777 | 2010-09-07 17:06:13 +0000 | [diff] [blame] | 105 | |
| 106 | if __name__ == '__main__': |
| 107 | import atexit |
| 108 | lldb.SBDebugger.Initialize() |
| 109 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 110 | unittest2.main() |