xref: /llvm-project/lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py (revision bf93f4b85fd4efbd7a3083935a2ddbbb00f1a35f)
1"""
2Test that plugins that load commands work correctly.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class PluginCommandTestCase(TestBase):
12    def setUp(self):
13        TestBase.setUp(self)
14
15    @skipIfNoSBHeaders
16    @skipIfHostIncompatibleWithTarget
17    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
18    @no_debug_info_test
19    def test_load_plugin(self):
20        """Test that plugins that load commands work correctly."""
21        self.generateSource("plugin.cpp")
22
23        plugin_name = "plugin"
24        if sys.platform.startswith("darwin"):
25            plugin_lib_name = "lib%s.dylib" % plugin_name
26        else:
27            plugin_lib_name = "lib%s.so" % plugin_name
28
29        # Invoke the library build rule.
30        self.buildLibrary("plugin.cpp", plugin_name)
31
32        retobj = lldb.SBCommandReturnObject()
33
34        retval = self.dbg.GetCommandInterpreter().HandleCommand(
35            "plugin load %s" % self.getBuildArtifact(plugin_lib_name), retobj
36        )
37
38        retobj.Clear()
39
40        retval = self.dbg.GetCommandInterpreter().HandleCommand(
41            "plugin_loaded_command child abc def ghi", retobj
42        )
43
44        if self.TraceOn():
45            print(retobj.GetOutput())
46
47        self.expect(retobj, substrs=["abc def ghi"], exe=False)
48
49        retobj.Clear()
50
51        # check that abbreviations work correctly in plugin commands.
52        retval = self.dbg.GetCommandInterpreter().HandleCommand(
53            "plugin_loaded_ ch abc def ghi", retobj
54        )
55
56        if self.TraceOn():
57            print(retobj.GetOutput())
58
59        self.expect(retobj, substrs=["abc def ghi"], exe=False)
60
61    @no_debug_info_test
62    def test_invalid_plugin_invocation(self):
63        self.expect(
64            "plugin load a b",
65            error=True,
66            startstr="error: 'plugin load' requires one argument",
67        )
68        self.expect(
69            "plugin load",
70            error=True,
71            startstr="error: 'plugin load' requires one argument",
72        )
73
74    @no_debug_info_test
75    def test_invalid_plugin_target(self):
76        self.expect(
77            "plugin load ThisIsNotAValidPluginName",
78            error=True,
79            startstr="error: no such file",
80        )
81