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