|
8 | 8 | from lldbsuite.test.decorators import * |
9 | 9 | from lldbsuite.test.lldbtest import * |
10 | 10 | from lldbsuite.test import lldbutil |
| 11 | +from pathlib import Path |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class ProcessLaunchTestCase(TestBase): |
@@ -206,3 +207,60 @@ def test_environment_with_special_char(self): |
206 | 207 | self.assertEqual(value, evil_var) |
207 | 208 | process.Continue() |
208 | 209 | self.assertState(process.GetState(), lldb.eStateExited, PROCESS_EXITED) |
| 210 | + |
| 211 | + @skipIfRemote |
| 212 | + def test_target_launch_working_dir_prop(self): |
| 213 | + """Test that the setting `target.launch-working-dir` is correctly used when launching a process.""" |
| 214 | + d = {"CXX_SOURCES": "print_cwd.cpp"} |
| 215 | + self.build(dictionary=d) |
| 216 | + self.setTearDownCleanup(d) |
| 217 | + exe = self.getBuildArtifact("a.out") |
| 218 | + self.runCmd("file " + exe) |
| 219 | + |
| 220 | + mywd = "my_working_dir" |
| 221 | + out_file_name = "my_working_dir_test.out" |
| 222 | + |
| 223 | + my_working_dir_path = self.getBuildArtifact(mywd) |
| 224 | + lldbutil.mkdir_p(my_working_dir_path) |
| 225 | + out_file_path = os.path.join(my_working_dir_path, out_file_name) |
| 226 | + another_working_dir_path = Path( |
| 227 | + os.path.join(my_working_dir_path, "..") |
| 228 | + ).resolve() |
| 229 | + |
| 230 | + # If -w is not passed to process launch, then the setting will be used. |
| 231 | + self.runCmd( |
| 232 | + f"settings set target.launch-working-dir {another_working_dir_path}" |
| 233 | + ) |
| 234 | + launch_command = f"process launch -o {out_file_path}" |
| 235 | + |
| 236 | + self.expect( |
| 237 | + launch_command, |
| 238 | + patterns=["Process .* launched: .*a.out"], |
| 239 | + ) |
| 240 | + |
| 241 | + out = lldbutil.read_file_on_target(self, out_file_path) |
| 242 | + |
| 243 | + self.assertIn(f"stdout: {another_working_dir_path}", out) |
| 244 | + |
| 245 | + # If -w is passed to process launch, that value will be used instead of the setting. |
| 246 | + launch_command = f"process launch -w {my_working_dir_path} -o {out_file_path}" |
| 247 | + |
| 248 | + self.expect( |
| 249 | + launch_command, |
| 250 | + patterns=["Process .* launched: .*a.out"], |
| 251 | + ) |
| 252 | + |
| 253 | + out = lldbutil.read_file_on_target(self, out_file_path) |
| 254 | + self.assertIn(f"stdout: {my_working_dir_path}", out) |
| 255 | + |
| 256 | + # If set to empty, then LLDB's cwd will be used to launch the process. |
| 257 | + self.runCmd(f"settings set target.launch-working-dir ''") |
| 258 | + launch_command = f"process launch -o {out_file_path}" |
| 259 | + |
| 260 | + self.expect( |
| 261 | + launch_command, |
| 262 | + patterns=["Process .* launched: .*a.out"], |
| 263 | + ) |
| 264 | + |
| 265 | + out = lldbutil.read_file_on_target(self, out_file_path) |
| 266 | + self.assertNotIn(f"stdout: {another_working_dir_path}", out) |
0 commit comments