blob: 9cd3f48adc2b5e5693d4dab2b656ea44c09a10ba [file] [log] [blame]
Johnny Chen77377772010-09-07 17:06:13 +00001"""
2Test lldb settings command.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class SettingsCommandTestCase(TestBase):
11
12 mydir = "settings"
13
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000014 @classmethod
15 def classCleanup(cls):
16 system(["/bin/sh", "-c", "rm output.txt"])
Johnny Chen2fcc0e52010-09-16 18:26:06 +000017 #system(["/bin/sh", "-c", "rm stdout.txt"])
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000018
Johnny Chen77377772010-09-07 17:06:13 +000019 def test_set_prompt(self):
20 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000021
Johnny Chen23cb3712010-09-27 17:36:59 +000022 # Set prompt to 'lldb2'.
23 self.runCmd("settings set prompt 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000024
25 # Immediately test the setting.
Johnny Chen77377772010-09-07 17:06:13 +000026 self.expect("settings show prompt",
27 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000028
29 # The overall display should also reflect the new setting.
Johnny Chen77377772010-09-07 17:06:13 +000030 self.expect("settings show",
31 substrs = ["prompt (string) = 'lldb2'"])
32
Johnny Chen23cb3712010-09-27 17:36:59 +000033 # Use '-r' option to reset to the original default prompt.
34 self.runCmd("settings set -r prompt")
35
Johnny Chena37764b2010-09-07 17:31:05 +000036 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 Chenea772bb2010-09-07 18:55:50 +000048 startstr = "term-width (int) = '70'")
Johnny Chena37764b2010-09-07 17:31:05 +000049
Johnny Chend5e111c2010-09-15 22:27:29 +000050 @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 Ticedaccaa92010-09-20 20:44:43 +000067 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 Chend5e111c2010-09-15 22:27:29 +000069
70 self.runCmd("run", RUN_SUCCEEDED)
71
72 # Read the output file produced by running the program.
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000073 output = open('output.txt', 'r').read()
Johnny Chend5e111c2010-09-15 22:27:29 +000074
75 self.assertTrue(output.startswith("argv[1] matches") and
76 output.find("argv[2] matches") > 0 and
77 output.find("argv[3] matches") > 0 and
78 output.find("Environment variable 'MY_ENV_VAR' successfully passed.") > 0)
79
Johnny Chen2fcc0e52010-09-16 18:26:06 +000080 @unittest2.expectedFailure
81 # rdar://problem/8435794
Caroline Ticedaccaa92010-09-20 20:44:43 +000082 # settings set target.process.output-path does not seem to work
Johnny Chen2fcc0e52010-09-16 18:26:06 +000083 def test_set_output_path(self):
Caroline Ticedaccaa92010-09-20 20:44:43 +000084 """Test that setting target.process.output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +000085 self.buildDefault()
86
87 exe = os.path.join(os.getcwd(), "a.out")
88 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
89
90 # Set the output-path and verify it is set.
Caroline Ticedaccaa92010-09-20 20:44:43 +000091 self.runCmd("settings set target.process.output-path 'stdout.txt'")
92 self.expect("settings show target.process.output-path",
93 startstr = "target.process.output-path (string) = 'stdout.txt'")
Johnny Chen2fcc0e52010-09-16 18:26:06 +000094
95 self.runCmd("run", RUN_SUCCEEDED)
96
97 # Read the output file produced by running the program.
98 output = open('stdout.txt', 'r').read()
99
100 self.assertTrue(
101 output.startswith("This message should go to standard out."))
102
Johnny Chen77377772010-09-07 17:06:13 +0000103
104if __name__ == '__main__':
105 import atexit
106 lldb.SBDebugger.Initialize()
107 atexit.register(lambda: lldb.SBDebugger.Terminate())
108 unittest2.main()