mirror of https://github.com/ARMmbed/mbed-os.git
Host test plugins: Cleaned preliminary code before next round of refactoring and improvements
parent
fd2142f3bf
commit
8af8250b48
|
|
@ -1,24 +1,29 @@
|
|||
# Interfaces and utils for host test plugin architecture
|
||||
|
||||
|
||||
def construct_enum(**enums):
|
||||
""" Create your own pseudo-enums
|
||||
"""
|
||||
return type('Enum', (), enums)
|
||||
|
||||
|
||||
class HostTestPluginBase:
|
||||
""" Base class for all plug-ins used with host tests.
|
||||
"""
|
||||
def register(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def unregister(self):
|
||||
pass
|
||||
###########################################################################
|
||||
# Interface
|
||||
###########################################################################
|
||||
|
||||
###########################################################################
|
||||
# Attributes defining plugin name, type etc.
|
||||
# This values across plugin should be unique
|
||||
name = "HostTestPluginBase"
|
||||
type = "BasePlugin"
|
||||
capabilities = []
|
||||
###########################################################################
|
||||
name = "HostTestPluginBase" # Plugin name, can be plugin class name
|
||||
type = "BasePlugin" # Plugin type: ResetMethod, Copymethod etc.
|
||||
capabilities = [] # Capabilities names: what plugin can achieve (e.g. reset using some external command line tool)
|
||||
|
||||
def setup(self, *args, **kwargs):
|
||||
""" Configure plugin, this function should be called before plugin execute() method is used.
|
||||
"""
|
||||
pass
|
||||
|
||||
def execute(self, capabilitity, *args, **kwargs):
|
||||
""" Executes capability by name.
|
||||
Each capability e.g. may directly just call some command line
|
||||
program or execute building pythonic function
|
||||
"""
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -31,13 +31,21 @@ class HostTestRegistry:
|
|||
print "Plugin load failed. Reason: %s"% text
|
||||
|
||||
def register_plugin(self, plugin):
|
||||
""" Registers and stores plugin inside registry for further use.
|
||||
Method also calls plugin's setup() function to configure plugin if needed.
|
||||
|
||||
Note: Different groups of plugins may demand different extra parameter. Plugins
|
||||
should be at least for one type of plugin configured with the same parameters
|
||||
because we do not know which of them will actually use particular parameter.
|
||||
"""
|
||||
# TODO:
|
||||
# - check for unique caps for specified type
|
||||
if plugin.name not in self.PLUGINS:
|
||||
plugin.setup() # Setup plugin
|
||||
self.PLUGINS[plugin.name] = plugin
|
||||
else:
|
||||
self.print_error("%s already loaded"% plugin.name)
|
||||
return True
|
||||
self.print_error("%s already loaded"% plugin.name)
|
||||
return False
|
||||
|
||||
def call_plugin(self, type, capability, *args, **kwargs):
|
||||
""" Execute plugin functionality respectively to its purpose
|
||||
|
|
@ -48,7 +56,13 @@ class HostTestRegistry:
|
|||
return plugin.execute(capability, *args, **kwargs)
|
||||
return False
|
||||
|
||||
def get_string(self):
|
||||
def load_plugin(self.name):
|
||||
""" Used to load module from
|
||||
"""
|
||||
mod = __import__("module_%s"% name)
|
||||
return mod
|
||||
|
||||
def __str__(self):
|
||||
""" User friendly printing method to show hooked plugins
|
||||
"""
|
||||
from prettytable import PrettyTable
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ class HostTestPluginResetMethod_Mbed(HostTestPluginBase):
|
|||
required_parameters = ['serial']
|
||||
|
||||
def setup(self, *args, **kwargs):
|
||||
""" Configure plugin, this function should be called before plugin execute() method is used.
|
||||
"""
|
||||
pass
|
||||
|
||||
def execute(self, capabilitity, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
import os
|
||||
from host_test_plugins import HostTestPluginBase
|
||||
|
||||
# Note: This plugin is not fully functional, needs improvements
|
||||
|
||||
class HostTestPluginResetMethod_MPS2(HostTestPluginBase):
|
||||
"""
|
||||
""" Plugin used to reset ARM_MPS2 platform
|
||||
Supports:
|
||||
reboot.txt - startup from standby state, reboots when in run mode.
|
||||
shutdown.txt - shutdown from run mode.
|
||||
|
|
@ -41,12 +42,15 @@ class HostTestPluginResetMethod_MPS2(HostTestPluginBase):
|
|||
return False
|
||||
|
||||
if capabilitity == 'reboot.txt':
|
||||
# TODO: Implement touch file for reboot
|
||||
pass
|
||||
|
||||
elif capabilitity == 'shutdown.txt':
|
||||
# TODO: Implement touch file for shutdown
|
||||
pass
|
||||
|
||||
elif capabilitity == 'reset.txt':
|
||||
# TODO: Implement touch file for reset
|
||||
pass
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ class HostTestPluginResetMethod_SiLabs(HostTestPluginBase):
|
|||
required_parameters = ['disk']
|
||||
|
||||
def setup(self, *args, **kwargs):
|
||||
""" Configure plugin, this function should be called before plugin execute() method is used.
|
||||
"""
|
||||
self.EACOMMANDER_CMD = 'c:/SiliconLabs/SimplicityStudio/v2/commander/eACommander.exe'
|
||||
pass
|
||||
|
||||
def execute(self, capabilitity, *args, **kwargs):
|
||||
""" Executes capability by name.
|
||||
|
|
|
|||
Loading…
Reference in New Issue