mirror of https://github.com/ARMmbed/mbed-os.git
Host test plugins: Added generic error printing to host test plugin base class
parent
17f42519f0
commit
2f03b85bfc
|
|
@ -52,14 +52,23 @@ class HostTestPluginBase:
|
|||
###########################################################################
|
||||
# Interface helper methods - overload only if you need to have custom behaviour
|
||||
###########################################################################
|
||||
def print_plugin_error(self, text):
|
||||
""" Function prints error in console and exits always with False
|
||||
"""
|
||||
print "Plugin error: %s::%s: %s"% (self.name, self.type, text)
|
||||
return False
|
||||
|
||||
def check_parameters(self, capabilitity, *args, **kwargs):
|
||||
""" This function should be ran each time we call execute()
|
||||
to check if none of the required parameters is missing.
|
||||
"""
|
||||
missing_parameters = []
|
||||
for parameter in self.required_parameters:
|
||||
if parameter not in kwargs:
|
||||
print "%s::%s: Plugin parameter '%s' missing!"% (self.name, self.type, parameter)
|
||||
return False
|
||||
missing_parameters.append(parameter)
|
||||
if len(missing_parameters) > 0:
|
||||
self.print_plugin_error("execute parameter(s) '%s' missing!"% (', '.join(parameter)))
|
||||
return False
|
||||
return True
|
||||
|
||||
def run_command(self, cmd, shell=True):
|
||||
|
|
@ -69,9 +78,9 @@ class HostTestPluginBase:
|
|||
try:
|
||||
ret = call(cmd, shell=shell)
|
||||
if ret:
|
||||
print "%s::%s: [ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd))
|
||||
self.print_plugin_error("[ret=%d] Command: %s"% (self.name, self.type, ret, ' '.join(cmd)))
|
||||
except Exception, e:
|
||||
result = False
|
||||
print "%s::%s: [ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd))
|
||||
print "%s::%s: " + str(e)
|
||||
self.print_plugin_error("[ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd)))
|
||||
self.print_plugin_error("%s::%s: " + str(e))
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class HostTestPluginCopyMethod_Firefox(HostTestPluginBase):
|
|||
try:
|
||||
from selenium import webdriver
|
||||
except ImportError, e:
|
||||
print "Error: firefox copy method requires selenium library. %s"% e
|
||||
self.print_plugin_error("Error: firefox copy method requires selenium library. %s"% e)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class HostTestPluginCopyMethod_Mbed(HostTestPluginBase):
|
|||
try:
|
||||
copy(image_path, destination_disk)
|
||||
except Exception, e:
|
||||
print str(e)
|
||||
self.print_plugin_error("shutil.copy(%s, %s) failed: %s"% (image_path, destination_disk, str(e)))
|
||||
result = False
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -51,26 +51,22 @@ class HostTestPluginResetMethod_MPS2(HostTestPluginBase):
|
|||
Each capability may directly just call some command line
|
||||
program or execute building pythonic function
|
||||
"""
|
||||
for parameter in self.required_parameters:
|
||||
if parameter not in kwargs:
|
||||
print "%s. Plugin parameter '%s' missing"% (self.name, parameter)
|
||||
return False
|
||||
result = False
|
||||
if self.check_parameters(capabilitity, *args, **kwargs) is True:
|
||||
|
||||
if capabilitity == 'reboot.txt':
|
||||
# TODO: Implement touch file for reboot
|
||||
pass
|
||||
if capabilitity == 'reboot.txt':
|
||||
# TODO: Implement touch file for reboot
|
||||
pass
|
||||
|
||||
elif capabilitity == 'shutdown.txt':
|
||||
# TODO: Implement touch file for shutdown
|
||||
pass
|
||||
elif capabilitity == 'shutdown.txt':
|
||||
# TODO: Implement touch file for shutdown
|
||||
pass
|
||||
|
||||
elif capabilitity == 'reset.txt':
|
||||
# TODO: Implement touch file for reset
|
||||
pass
|
||||
elif capabilitity == 'reset.txt':
|
||||
# TODO: Implement touch file for reset
|
||||
pass
|
||||
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
return result
|
||||
|
||||
def load_plugin():
|
||||
""" Returns plugin available in this module
|
||||
|
|
|
|||
|
|
@ -600,14 +600,6 @@ class SingleTestRunner(object):
|
|||
"""
|
||||
image_dest = image_dest if image_dest is not None else ''
|
||||
_copy_res, _err_msg, _copy_method = self.file_copy_method_selector(image_path, disk, copy_method, image_dest=image_dest, verbose=verbose)
|
||||
|
||||
if images_config is not None:
|
||||
# For different targets additional configuration file has to be changed
|
||||
# Here we select target and proper function to handle configuration change
|
||||
if target_name == 'ARM_MPS2':
|
||||
images_cfg_path = images_config
|
||||
image0file_path = os.path.join(disk, image_dest, basename(image_path))
|
||||
mps2_set_board_image_file(disk, images_cfg_path, image0file_path)
|
||||
return _copy_res, _err_msg, _copy_method
|
||||
|
||||
def file_copy_method_selector(self, image_path, disk, copy_method, image_dest='', verbose=False):
|
||||
|
|
|
|||
Loading…
Reference in New Issue