2 Test lldb process launch flags.
8 from lldbsuite
.test
.decorators
import *
9 from lldbsuite
.test
.lldbtest
import *
10 from lldbsuite
.test
import lldbutil
13 class ProcessLaunchTestCase(TestBase
):
14 NO_DEBUG_INFO_TESTCASE
= True
17 # Call super's setUp().
19 self
.runCmd("settings set auto-confirm true")
22 self
.runCmd("settings clear auto-confirm")
23 TestBase
.tearDown(self
)
27 """Test that process launch I/O redirection flags work properly."""
29 exe
= self
.getBuildArtifact("a.out")
30 self
.expect("file " + exe
, patterns
=["Current executable set to .*a.out"])
32 in_file
= os
.path
.join(self
.getSourceDir(), "input-file.txt")
33 out_file
= lldbutil
.append_to_process_working_directory(self
, "output-test.out")
34 err_file
= lldbutil
.append_to_process_working_directory(self
, "output-test.err")
36 # Make sure the output files do not exist before launching the process
47 launch_command
= "process launch -i '{0}' -o '{1}' -e '{2}' -w '{3}'".format(
48 in_file
, out_file
, err_file
, self
.get_process_working_directory()
51 if lldb
.remote_platform
:
53 'platform put-file "{local}" "{remote}"'.format(
54 local
=in_file
, remote
=in_file
58 self
.expect(launch_command
, patterns
=["Process .* launched: .*a.out"])
63 out
= lldbutil
.read_file_on_target(self
, out_file
)
64 if out
!= "This should go to stdout.\n":
67 err_msg
+ " ERROR: stdout file does not contain correct output.\n"
70 err
= lldbutil
.read_file_on_target(self
, err_file
)
71 if err
!= "This should go to stderr.\n":
74 err_msg
+ " ERROR: stderr file does not contain correct output.\n"
80 # rdar://problem/9056462
81 # The process launch flag '-w' for setting the current working directory
84 @expectedFailureAll(oslist
=["freebsd", "linux"], bugnumber
="llvm.org/pr20265")
85 @expectedFailureNetBSD
86 def test_set_working_dir_nonexisting(self
):
87 """Test that '-w dir' fails to set the working dir when running the inferior with a dir which doesn't exist."""
88 d
= {"CXX_SOURCES": "print_cwd.cpp"}
89 self
.build(dictionary
=d
)
90 self
.setTearDownCleanup(d
)
91 exe
= self
.getBuildArtifact("a.out")
92 self
.runCmd("file " + exe
)
94 mywd
= "my_working_dir"
95 out_file_name
= "my_working_dir_test.out"
96 err_file_name
= "my_working_dir_test.err"
98 my_working_dir_path
= self
.getBuildArtifact(mywd
)
99 out_file_path
= os
.path
.join(my_working_dir_path
, out_file_name
)
100 err_file_path
= os
.path
.join(my_working_dir_path
, err_file_name
)
102 # Check that we get an error when we have a nonexisting path
103 invalid_dir_path
= mywd
+ "z"
104 launch_command
= "process launch -w %s -o %s -e %s" % (
113 patterns
=["error:.* No such file or directory: %s" % invalid_dir_path
],
117 def test_set_working_dir_existing(self
):
118 """Test that '-w dir' sets the working dir when running the inferior."""
119 d
= {"CXX_SOURCES": "print_cwd.cpp"}
120 self
.build(dictionary
=d
)
121 self
.setTearDownCleanup(d
)
122 exe
= self
.getBuildArtifact("a.out")
123 self
.runCmd("file " + exe
)
125 mywd
= "my_working_dir"
126 out_file_name
= "my_working_dir_test.out"
127 err_file_name
= "my_working_dir_test.err"
129 my_working_dir_path
= self
.getBuildArtifact(mywd
)
130 lldbutil
.mkdir_p(my_working_dir_path
)
131 out_file_path
= os
.path
.join(my_working_dir_path
, out_file_name
)
132 err_file_path
= os
.path
.join(my_working_dir_path
, err_file_name
)
134 # Make sure the output files do not exist before launching the process
136 os
.remove(out_file_path
)
137 os
.remove(err_file_path
)
141 launch_command
= "process launch -w %s -o %s -e %s" % (
147 self
.expect(launch_command
, patterns
=["Process .* launched: .*a.out"])
152 # Check to see if the 'stdout' file was created
154 out_f
= open(out_file_path
)
157 err_msg
= err_msg
+ "ERROR: stdout file was not created.\n"
159 # Check to see if the 'stdout' file contains the right output
160 line
= out_f
.readline()
163 if not re
.search(mywd
, line
):
166 err_msg
+ "The current working directory was not set correctly.\n"
170 # Try to delete the 'stdout' and 'stderr' files
172 os
.remove(out_file_path
)
173 os
.remove(err_file_path
)
180 def test_environment_with_special_char(self
):
181 """Test that environment variables containing '*' and '}' are handled correctly by the inferior."""
182 source
= "print_env.cpp"
183 d
= {"CXX_SOURCES": source
}
184 self
.build(dictionary
=d
)
185 self
.setTearDownCleanup(d
)
187 evil_var
= "INIT*MIDDLE}TAIL"
189 target
= self
.createTestTarget()
190 main_source_spec
= lldb
.SBFileSpec(source
)
191 breakpoint
= target
.BreakpointCreateBySourceRegex(
192 "// Set breakpoint here.", main_source_spec
195 process
= target
.LaunchSimple(
196 None, ["EVIL=" + evil_var
], self
.get_process_working_directory()
198 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
200 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, breakpoint
)
201 self
.assertEqual(len(threads
), 1)
202 frame
= threads
[0].GetFrameAtIndex(0)
203 sbvalue
= frame
.EvaluateExpression("evil")
204 value
= sbvalue
.GetSummary().strip('"')
206 self
.assertEqual(value
, evil_var
)
208 self
.assertState(process
.GetState(), lldb
.eStateExited
, PROCESS_EXITED
)