blob: e0653c442bda3a9ab0daf003ff65f16426192a1e [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):
Johnny Chena91b9472010-10-22 21:06:04 +000016 """Cleanup the test byproducts."""
Johnny Chen138532a2010-10-08 00:47:30 +000017 system(["/bin/sh", "-c", "rm -f output.txt"])
18 system(["/bin/sh", "-c", "rm -f stdout.txt"])
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000019
Johnny Chen77377772010-09-07 17:06:13 +000020 def test_set_prompt(self):
21 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000022
Johnny Chen23cb3712010-09-27 17:36:59 +000023 # Set prompt to 'lldb2'.
24 self.runCmd("settings set prompt 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000025
26 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000027 self.expect("settings show prompt", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000028 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000029
30 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000031 self.expect("settings show", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000032 substrs = ["prompt (string) = 'lldb2'"])
33
Johnny Chen23cb3712010-09-27 17:36:59 +000034 # Use '-r' option to reset to the original default prompt.
35 self.runCmd("settings set -r prompt")
36
Johnny Chena37764b2010-09-07 17:31:05 +000037 def test_set_term_width(self):
38 """Test that 'set term-width' actually changes the term-width."""
39
Johnny Chena37764b2010-09-07 17:31:05 +000040 self.runCmd("settings set term-width 70")
41
42 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000043 self.expect("settings show term-width", SETTING_MSG("term-width"),
Johnny Chena37764b2010-09-07 17:31:05 +000044 startstr = "term-width (int) = '70'")
45
46 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000047 self.expect("settings show", SETTING_MSG("term-width"),
Johnny Chen138532a2010-10-08 00:47:30 +000048 substrs = ["term-width (int) = '70'"])
Johnny Chena37764b2010-09-07 17:31:05 +000049
Johnny Chen3e9c50c2010-10-18 17:51:45 +000050 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 Chen3e9c50c2010-10-18 17:51:45 +000057 self.runCmd("settings set auto-confirm true")
58
59 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000060 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000061 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 Chena913ea42010-10-19 19:39:20 +000071 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000072 startstr = "auto-confirm (boolean) = 'false'")
73
Johnny Chend5e111c2010-09-15 22:27:29 +000074 @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 Ticedaccaa92010-09-20 20:44:43 +000091 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 Chen707d8222010-10-19 23:40:13 +000093 # 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 Chend5e111c2010-09-15 22:27:29 +000098
99 self.runCmd("run", RUN_SUCCEEDED)
100
101 # Read the output file produced by running the program.
Johnny Chen277c8f02010-10-08 22:10:42 +0000102 with open('output.txt', 'r') as f:
103 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000104
Johnny Chenbe7da212010-10-08 20:01:03 +0000105 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 Chend5e111c2010-09-15 22:27:29 +0000110
Johnny Chen80554b82010-12-04 00:44:56 +0000111 def test_pass_host_env_vars(self):
112 """Test that the host env vars are passed to the launched process."""
113 self.buildDefault()
114
115 exe = os.path.join(os.getcwd(), "a.out")
116 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
117
118 # By default, inherit-env is 'true'.
119 self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
120 startstr = "target.process.inherit-env (boolean) = 'true'")
121
122 # Set some host environment variables now.
123 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
124 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
125
126 self.runCmd("run", RUN_SUCCEEDED)
127
128 # Read the output file produced by running the program.
129 with open('output.txt', 'r') as f:
130 output = f.read()
131
132 self.expect(output, exe=False,
133 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
134 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
135
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000136 @unittest2.expectedFailure
137 # rdar://problem/8435794
Caroline Ticedaccaa92010-09-20 20:44:43 +0000138 # settings set target.process.output-path does not seem to work
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000139 def test_set_output_path(self):
Caroline Ticedaccaa92010-09-20 20:44:43 +0000140 """Test that setting target.process.output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000141 self.buildDefault()
142
143 exe = os.path.join(os.getcwd(), "a.out")
144 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
145
146 # Set the output-path and verify it is set.
Caroline Ticedaccaa92010-09-20 20:44:43 +0000147 self.runCmd("settings set target.process.output-path 'stdout.txt'")
Johnny Chen707d8222010-10-19 23:40:13 +0000148 # And add a hook to restore original setting of target.process.output-path
149 # later on during tearDown().
150 self.addTearDownHook(
151 lambda: self.runCmd("settings set -r target.process.output-path"))
152
Caroline Ticedaccaa92010-09-20 20:44:43 +0000153 self.expect("settings show target.process.output-path",
Johnny Chen3343f042010-10-19 19:11:38 +0000154 SETTING_MSG("target.process.output-path"),
Caroline Ticedaccaa92010-09-20 20:44:43 +0000155 startstr = "target.process.output-path (string) = 'stdout.txt'")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000156
157 self.runCmd("run", RUN_SUCCEEDED)
158
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000159 # The 'stdout.txt' file should now exist.
160 self.assertTrue(os.path.isfile("stdout.txt"),
161 "'stdout.txt' exists due to target.process.output-path.")
162
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000163 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000164 with open('stdout.txt', 'r') as f:
165 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000166
Johnny Chenbe7da212010-10-08 20:01:03 +0000167 self.expect(output, exe=False,
168 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000169
Johnny Chen77377772010-09-07 17:06:13 +0000170
171if __name__ == '__main__':
172 import atexit
173 lldb.SBDebugger.Initialize()
174 atexit.register(lambda: lldb.SBDebugger.Terminate())
175 unittest2.main()