blob: b7d39bd59411dcaa56df177fb19f6613aa69faa9 [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 Chen138532a2010-10-08 00:47:30 +000016 system(["/bin/sh", "-c", "rm -f output.txt"])
17 system(["/bin/sh", "-c", "rm -f 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 Chena913ea42010-10-19 19:39:20 +000026 self.expect("settings show prompt", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000027 startstr = "prompt (string) = 'lldb2'")
Johnny Chen881c3712010-09-07 17:12:10 +000028
29 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000030 self.expect("settings show", SETTING_MSG("prompt"),
Johnny Chen77377772010-09-07 17:06:13 +000031 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
Johnny Chena37764b2010-09-07 17:31:05 +000039 self.runCmd("settings set term-width 70")
40
41 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000042 self.expect("settings show term-width", SETTING_MSG("term-width"),
Johnny Chena37764b2010-09-07 17:31:05 +000043 startstr = "term-width (int) = '70'")
44
45 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000046 self.expect("settings show", SETTING_MSG("term-width"),
Johnny Chen138532a2010-10-08 00:47:30 +000047 substrs = ["term-width (int) = '70'"])
Johnny Chena37764b2010-09-07 17:31:05 +000048
Johnny Chen3e9c50c2010-10-18 17:51:45 +000049 def test_set_auto_confirm(self):
50 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
51 self.buildDefault()
52
53 exe = os.path.join(os.getcwd(), "a.out")
54 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
55
Johnny Chen3e9c50c2010-10-18 17:51:45 +000056 self.runCmd("settings set auto-confirm true")
57
58 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000059 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000060 startstr = "auto-confirm (boolean) = 'true'")
61
62 # Now 'breakpoint delete' should just work fine without confirmation
63 # prompt from the command interpreter.
64 self.runCmd("breakpoint set -n main")
65 self.expect("breakpoint delete",
66 startstr = "All breakpoints removed")
67
68 # Restore the original setting of auto-confirm.
69 self.runCmd("settings set -r auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +000070 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Johnny Chen3e9c50c2010-10-18 17:51:45 +000071 startstr = "auto-confirm (boolean) = 'false'")
72
Johnny Chend5e111c2010-09-15 22:27:29 +000073 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
74 def test_with_dsym(self):
75 """Test that run-args and env-vars are passed to the launched process."""
76 self.buildDsym()
77 self.pass_run_args_and_env_vars()
78
79 def test_with_dwarf(self):
80 """Test that run-args and env-vars are passed to the launched process."""
81 self.buildDwarf()
82 self.pass_run_args_and_env_vars()
83
84 def pass_run_args_and_env_vars(self):
85 """Test that run-args and env-vars are passed to the launched process."""
86 exe = os.path.join(os.getcwd(), "a.out")
87 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
88
89 # Set the run-args and the env-vars.
Caroline Ticedaccaa92010-09-20 20:44:43 +000090 self.runCmd('settings set target.process.run-args A B C')
91 self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +000092 # And add hooks to restore the settings during tearDown().
93 self.addTearDownHook(
94 lambda: self.runCmd("settings set -r target.process.run-args"))
95 self.addTearDownHook(
96 lambda: self.runCmd("settings set -r target.process.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +000097
98 self.runCmd("run", RUN_SUCCEEDED)
99
100 # Read the output file produced by running the program.
Johnny Chen277c8f02010-10-08 22:10:42 +0000101 with open('output.txt', 'r') as f:
102 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000103
Johnny Chenbe7da212010-10-08 20:01:03 +0000104 self.expect(output, exe=False,
105 substrs = ["argv[1] matches",
106 "argv[2] matches",
107 "argv[3] matches",
108 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000109
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000110 @unittest2.expectedFailure
111 # rdar://problem/8435794
Caroline Ticedaccaa92010-09-20 20:44:43 +0000112 # settings set target.process.output-path does not seem to work
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000113 def test_set_output_path(self):
Caroline Ticedaccaa92010-09-20 20:44:43 +0000114 """Test that setting target.process.output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000115 self.buildDefault()
116
117 exe = os.path.join(os.getcwd(), "a.out")
118 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
119
120 # Set the output-path and verify it is set.
Caroline Ticedaccaa92010-09-20 20:44:43 +0000121 self.runCmd("settings set target.process.output-path 'stdout.txt'")
Johnny Chen707d8222010-10-19 23:40:13 +0000122 # And add a hook to restore original setting of target.process.output-path
123 # later on during tearDown().
124 self.addTearDownHook(
125 lambda: self.runCmd("settings set -r target.process.output-path"))
126
Caroline Ticedaccaa92010-09-20 20:44:43 +0000127 self.expect("settings show target.process.output-path",
Johnny Chen3343f042010-10-19 19:11:38 +0000128 SETTING_MSG("target.process.output-path"),
Caroline Ticedaccaa92010-09-20 20:44:43 +0000129 startstr = "target.process.output-path (string) = 'stdout.txt'")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000130
131 self.runCmd("run", RUN_SUCCEEDED)
132
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000133 # The 'stdout.txt' file should now exist.
134 self.assertTrue(os.path.isfile("stdout.txt"),
135 "'stdout.txt' exists due to target.process.output-path.")
136
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000137 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000138 with open('stdout.txt', 'r') as f:
139 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000140
Johnny Chenbe7da212010-10-08 20:01:03 +0000141 self.expect(output, exe=False,
142 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000143
Johnny Chen77377772010-09-07 17:06:13 +0000144
145if __name__ == '__main__':
146 import atexit
147 lldb.SBDebugger.Initialize()
148 atexit.register(lambda: lldb.SBDebugger.Terminate())
149 unittest2.main()