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