diff options
| author | Med Ismail Bennani <ismail@bennani.ma> | 2023-11-07 22:01:21 -0800 |
|---|---|---|
| committer | Med Ismail Bennani <ismail@bennani.ma> | 2023-11-07 22:01:41 -0800 |
| commit | 0a21144614950ce063d8dac6394307bd3be604cd (patch) | |
| tree | 4cd20f82195bfc848452b035cb7e4bd177ca555f /lldb/test/API/functionalities/scripted_process | |
| parent | 14e7846d6e2c5c99c52ba3882e59bfb021a5f0fa (diff) | |
| download | llvm-0a21144614950ce063d8dac6394307bd3be604cd.tar.gz llvm-0a21144614950ce063d8dac6394307bd3be604cd.tar.bz2 llvm-0a21144614950ce063d8dac6394307bd3be604cd.zip | |
[lldb] Check for abstract methods implementation in Scripted Plugin Objects (#71260)
This patch enforces that every scripted object implements all the
necessary abstract methods.
Every scripted affordance language interface can implement a list of
abstract methods name that checked when the object is instanciated.
Since some scripting affordances implementations can be derived from
template base classes, we can't check the object dictionary since it
will contain the definition of the base class, so instead, this checks
the scripting class dictionary.
Previously, for the various python interfaces, we used
`ABC.abstractmethod` decorators but this is too language specific and
doesn't work for scripting affordances that are not derived from
template base classes (i.e OperatingSystem, ScriptedThreadPlan, ...), so
this patch provides generic/language-agnostic checks for every scripted
affordance.
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
Diffstat (limited to 'lldb/test/API/functionalities/scripted_process')
| -rw-r--r-- | lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py | 49 | ||||
| -rw-r--r-- | lldb/test/API/functionalities/scripted_process/missing_methods_scripted_process.py | 19 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py index 1761122999f8..8c6b9c74bde4 100644 --- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py +++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py @@ -60,6 +60,55 @@ class ScriptedProcesTestCase(TestBase): ) shutil.copy(blueprint_origin_path, blueprint_destination_path) + def test_missing_methods_scripted_register_context(self): + """Test that we only instanciate scripted processes if they implement + all the required abstract methods.""" + self.build() + + os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"] = "1" + + def cleanup(): + del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"] + + self.addTearDownHook(cleanup) + + target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + self.assertTrue(target, VALID_TARGET) + log_file = self.getBuildArtifact("script.log") + self.runCmd("log enable lldb script -f " + log_file) + self.assertTrue(os.path.isfile(log_file)) + script_path = os.path.join( + self.getSourceDir(), "missing_methods_scripted_process.py" + ) + self.runCmd("command script import " + script_path) + + launch_info = lldb.SBLaunchInfo(None) + launch_info.SetProcessPluginName("ScriptedProcess") + launch_info.SetScriptedProcessClassName( + "missing_methods_scripted_process.MissingMethodsScriptedProcess" + ) + error = lldb.SBError() + + process = target.Launch(launch_info, error) + + self.assertFailure(error) + + with open(log_file, "r") as f: + log = f.read() + + self.assertIn( + "Abstract method MissingMethodsScriptedProcess.read_memory_at_address not implemented", + log, + ) + self.assertIn( + "Abstract method MissingMethodsScriptedProcess.is_alive not implemented", + log, + ) + self.assertIn( + "Abstract method MissingMethodsScriptedProcess.get_scripted_thread_plugin not implemented", + log, + ) + @skipUnlessDarwin def test_invalid_scripted_register_context(self): """Test that we can launch an lldb scripted process with an invalid diff --git a/lldb/test/API/functionalities/scripted_process/missing_methods_scripted_process.py b/lldb/test/API/functionalities/scripted_process/missing_methods_scripted_process.py new file mode 100644 index 000000000000..a1db0640033e --- /dev/null +++ b/lldb/test/API/functionalities/scripted_process/missing_methods_scripted_process.py @@ -0,0 +1,19 @@ +import os + + +class MissingMethodsScriptedProcess: + def __init__(self, exe_ctx, args): + pass + + +def __lldb_init_module(debugger, dict): + if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ: + debugger.HandleCommand( + "process launch -C %s.%s" + % (__name__, MissingMethodsScriptedProcess.__name__) + ) + else: + print( + "Name of the class that will manage the scripted process: '%s.%s'" + % (__name__, MissingMethodsScriptedProcess.__name__) + ) |
