[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / process / launch / TestProcessLaunch.py
blob45f9f494ab8f5cdc4875b35ce0dd235160a9c973
1 """
2 Test lldb process launch flags.
3 """
5 import os
7 import lldb
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
16 def setUp(self):
17 # Call super's setUp().
18 TestBase.setUp(self)
19 self.runCmd("settings set auto-confirm true")
21 def tearDown(self):
22 self.runCmd("settings clear auto-confirm")
23 TestBase.tearDown(self)
25 @skipIfRemote
26 def test_io(self):
27 """Test that process launch I/O redirection flags work properly."""
28 self.build()
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
37 try:
38 os.remove(out_file)
39 except OSError:
40 pass
42 try:
43 os.remove(err_file)
44 except OSError:
45 pass
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:
52 self.runCmd(
53 'platform put-file "{local}" "{remote}"'.format(
54 local=in_file, remote=in_file
58 self.expect(launch_command, patterns=["Process .* launched: .*a.out"])
60 success = True
61 err_msg = ""
63 out = lldbutil.read_file_on_target(self, out_file)
64 if out != "This should go to stdout.\n":
65 success = False
66 err_msg = (
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":
72 success = False
73 err_msg = (
74 err_msg + " ERROR: stderr file does not contain correct output.\n"
77 if not success:
78 self.fail(err_msg)
80 # rdar://problem/9056462
81 # The process launch flag '-w' for setting the current working directory
82 # not working?
83 @skipIfRemote
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" % (
105 invalid_dir_path,
106 out_file_path,
107 err_file_path,
110 self.expect(
111 launch_command,
112 error=True,
113 patterns=["error:.* No such file or directory: %s" % invalid_dir_path],
116 @skipIfRemote
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
135 try:
136 os.remove(out_file_path)
137 os.remove(err_file_path)
138 except OSError:
139 pass
141 launch_command = "process launch -w %s -o %s -e %s" % (
142 my_working_dir_path,
143 out_file_path,
144 err_file_path,
147 self.expect(launch_command, patterns=["Process .* launched: .*a.out"])
149 success = True
150 err_msg = ""
152 # Check to see if the 'stdout' file was created
153 try:
154 out_f = open(out_file_path)
155 except IOError:
156 success = False
157 err_msg = err_msg + "ERROR: stdout file was not created.\n"
158 else:
159 # Check to see if the 'stdout' file contains the right output
160 line = out_f.readline()
161 if self.TraceOn():
162 print("line:", line)
163 if not re.search(mywd, line):
164 success = False
165 err_msg = (
166 err_msg + "The current working directory was not set correctly.\n"
168 out_f.close()
170 # Try to delete the 'stdout' and 'stderr' files
171 try:
172 os.remove(out_file_path)
173 os.remove(err_file_path)
174 except OSError:
175 pass
177 if not success:
178 self.fail(err_msg)
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)
207 process.Continue()
208 self.assertState(process.GetState(), lldb.eStateExited, PROCESS_EXITED)