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