xref: /llvm-project/lldb/test/API/commands/platform/process/launch/TestPlatformProcessLaunch.py (revision 1a25b723628e439d62dfb28ca5fa52e4b2a78e5a)
1728101f9SDavid Spickett"""
2728101f9SDavid SpickettTest platform process launch.
3728101f9SDavid Spickett"""
4728101f9SDavid Spickett
5728101f9SDavid Spickettfrom textwrap import dedent
6*1a25b723SDmitry Vasilyevfrom lldbsuite.test import lldbutil
7728101f9SDavid Spickettfrom lldbsuite.test.lldbtest import TestBase
8728101f9SDavid Spickett
9728101f9SDavid Spickett
10728101f9SDavid Spickettclass ProcessLaunchTestCase(TestBase):
11728101f9SDavid Spickett    NO_DEBUG_INFO_TESTCASE = True
12728101f9SDavid Spickett
13728101f9SDavid Spickett    def setup(self):
14728101f9SDavid Spickett        self.build()
15*1a25b723SDmitry Vasilyev        self.runCmd("file " + self.getBuildArtifact("a.out"))
16*1a25b723SDmitry Vasilyev        exe = lldbutil.append_to_process_working_directory(self, "a.out")
17*1a25b723SDmitry Vasilyev        outfile = lldbutil.append_to_process_working_directory(self, "stdio.log")
18*1a25b723SDmitry Vasilyev        return (exe, outfile)
19728101f9SDavid Spickett
20728101f9SDavid Spickett    def test_process_launch_no_args(self):
21728101f9SDavid Spickett        # When there are no extra arguments we just have 0, the program name.
22728101f9SDavid Spickett        exe, outfile = self.setup()
23728101f9SDavid Spickett        self.runCmd("platform process launch --stdout {} -s".format(outfile))
24728101f9SDavid Spickett        self.runCmd("continue")
25728101f9SDavid Spickett
26*1a25b723SDmitry Vasilyev        stdio_log = lldbutil.read_file_on_target(self, outfile)
27ecbe78c1SJonas Devlieghere        self.assertEqual(
28ecbe78c1SJonas Devlieghere            dedent(
29ecbe78c1SJonas Devlieghere                """\
30728101f9SDavid Spickett            Got 1 argument(s).
31728101f9SDavid Spickett            [0]: {}
32ecbe78c1SJonas Devlieghere            """.format(
33ecbe78c1SJonas Devlieghere                    exe
34ecbe78c1SJonas Devlieghere                )
35ecbe78c1SJonas Devlieghere            ),
36*1a25b723SDmitry Vasilyev            stdio_log,
37ecbe78c1SJonas Devlieghere        )
38728101f9SDavid Spickett
39728101f9SDavid Spickett    def test_process_launch_command_args(self):
40728101f9SDavid Spickett        exe, outfile = self.setup()
41728101f9SDavid Spickett        # Arguments given via the command override those in the settings.
42728101f9SDavid Spickett        self.runCmd("settings set target.run-args D E")
43728101f9SDavid Spickett        self.runCmd("platform process launch --stdout {} -s -- A B C".format(outfile))
44728101f9SDavid Spickett        self.runCmd("continue")
45728101f9SDavid Spickett
46*1a25b723SDmitry Vasilyev        stdio_log = lldbutil.read_file_on_target(self, outfile)
47ecbe78c1SJonas Devlieghere        self.assertEqual(
48ecbe78c1SJonas Devlieghere            dedent(
49ecbe78c1SJonas Devlieghere                """\
50728101f9SDavid Spickett            Got 4 argument(s).
51728101f9SDavid Spickett            [0]: {}
52728101f9SDavid Spickett            [1]: A
53728101f9SDavid Spickett            [2]: B
54728101f9SDavid Spickett            [3]: C
55ecbe78c1SJonas Devlieghere            """.format(
56ecbe78c1SJonas Devlieghere                    exe
57ecbe78c1SJonas Devlieghere                )
58ecbe78c1SJonas Devlieghere            ),
59*1a25b723SDmitry Vasilyev            stdio_log,
60ecbe78c1SJonas Devlieghere        )
61728101f9SDavid Spickett
62728101f9SDavid Spickett    def test_process_launch_target_args(self):
63728101f9SDavid Spickett        exe, outfile = self.setup()
64728101f9SDavid Spickett        # When no arguments are passed via the command, use the setting.
65728101f9SDavid Spickett        self.runCmd("settings set target.run-args D E")
66728101f9SDavid Spickett        self.runCmd("platform process launch --stdout {} -s".format(outfile))
67728101f9SDavid Spickett        self.runCmd("continue")
68728101f9SDavid Spickett
69*1a25b723SDmitry Vasilyev        stdio_log = lldbutil.read_file_on_target(self, outfile)
70ecbe78c1SJonas Devlieghere        self.assertEqual(
71ecbe78c1SJonas Devlieghere            dedent(
72ecbe78c1SJonas Devlieghere                """\
73728101f9SDavid Spickett            Got 3 argument(s).
74728101f9SDavid Spickett            [0]: {}
75728101f9SDavid Spickett            [1]: D
76728101f9SDavid Spickett            [2]: E
77ecbe78c1SJonas Devlieghere            """.format(
78ecbe78c1SJonas Devlieghere                    exe
79ecbe78c1SJonas Devlieghere                )
80ecbe78c1SJonas Devlieghere            ),
81*1a25b723SDmitry Vasilyev            stdio_log,
82ecbe78c1SJonas Devlieghere        )
83