1""" 2Test platform process launch. 3""" 4 5from textwrap import dedent 6from lldbsuite.test import lldbutil 7from lldbsuite.test.lldbtest import TestBase 8 9 10class ProcessLaunchTestCase(TestBase): 11 NO_DEBUG_INFO_TESTCASE = True 12 13 def setup(self): 14 self.build() 15 self.runCmd("file " + self.getBuildArtifact("a.out")) 16 exe = lldbutil.append_to_process_working_directory(self, "a.out") 17 outfile = lldbutil.append_to_process_working_directory(self, "stdio.log") 18 return (exe, outfile) 19 20 def test_process_launch_no_args(self): 21 # When there are no extra arguments we just have 0, the program name. 22 exe, outfile = self.setup() 23 self.runCmd("platform process launch --stdout {} -s".format(outfile)) 24 self.runCmd("continue") 25 26 stdio_log = lldbutil.read_file_on_target(self, outfile) 27 self.assertEqual( 28 dedent( 29 """\ 30 Got 1 argument(s). 31 [0]: {} 32 """.format( 33 exe 34 ) 35 ), 36 stdio_log, 37 ) 38 39 def test_process_launch_command_args(self): 40 exe, outfile = self.setup() 41 # Arguments given via the command override those in the settings. 42 self.runCmd("settings set target.run-args D E") 43 self.runCmd("platform process launch --stdout {} -s -- A B C".format(outfile)) 44 self.runCmd("continue") 45 46 stdio_log = lldbutil.read_file_on_target(self, outfile) 47 self.assertEqual( 48 dedent( 49 """\ 50 Got 4 argument(s). 51 [0]: {} 52 [1]: A 53 [2]: B 54 [3]: C 55 """.format( 56 exe 57 ) 58 ), 59 stdio_log, 60 ) 61 62 def test_process_launch_target_args(self): 63 exe, outfile = self.setup() 64 # When no arguments are passed via the command, use the setting. 65 self.runCmd("settings set target.run-args D E") 66 self.runCmd("platform process launch --stdout {} -s".format(outfile)) 67 self.runCmd("continue") 68 69 stdio_log = lldbutil.read_file_on_target(self, outfile) 70 self.assertEqual( 71 dedent( 72 """\ 73 Got 3 argument(s). 74 [0]: {} 75 [1]: D 76 [2]: E 77 """.format( 78 exe 79 ) 80 ), 81 stdio_log, 82 ) 83