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