Adding checks with mbedls throughout testing process

pull/1347/head
Brian Daniels 2015-09-23 10:54:41 -05:00
parent d8ad8e8bf5
commit 1d946c2160
3 changed files with 107 additions and 34 deletions

View File

@ -35,6 +35,8 @@ import host_tests_plugins
# we can find packages we want from the same level as other files do
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from workspace_tools.test_api import get_autodetected_MUTS_list
from workspace_tools.test_api import get_module_avail
class Mbed:
@ -89,6 +91,12 @@ class Mbed:
type="int",
help="When forcing a reset using option -r you can set up after reset timeout in seconds")
parser.add_option('', '--auto',
dest='auto_detect',
metavar=False,
action="store_true",
help='Use mbed-ls module to detect all connected mbed devices')
(self.options, _) = parser.parse_args()
self.DEFAULT_RESET_TOUT = 0
@ -126,6 +134,25 @@ class Mbed:
serial_baud = serial_baud if serial_baud is not None else self.serial_baud
serial_timeout = serial_timeout if serial_timeout is not None else self.serial_timeout
if get_module_avail('mbed_lstools') and self.options.auto_detect:
# Ensure serial port is up-to-date (try to find it 60 times)
found = False
for i in range(0, 60):
print('Looking for %s with MBEDLS' % self.options.micro)
muts_list = get_autodetected_MUTS_list(platform_name_filter=[self.options.micro])
if 1 in muts_list:
mut = muts_list[1]
self.port = mut['port']
found = True
break
else:
sleep(3)
if not found:
return False
# Clear serial port
if self.serial:
self.serial.close()
@ -257,7 +284,7 @@ class Mbed:
else:
copy_method = 'shell'
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk, program_cycle_s=self.program_cycle_s)
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk, program_cycle_s=self.program_cycle_s, target_mcu=self.options.micro)
return result;
def flush(self):

View File

@ -71,7 +71,7 @@ from workspace_tools.test_api import get_avail_tests_summary_table
from workspace_tools.test_api import get_default_test_options_parser
from workspace_tools.test_api import print_muts_configuration_from_json
from workspace_tools.test_api import print_test_configuration_from_json
from workspace_tools.test_api import get_autodetected_MUTS
from workspace_tools.test_api import get_autodetected_MUTS_list
from workspace_tools.test_api import get_autodetected_TEST_SPEC
from workspace_tools.test_api import get_module_avail
from workspace_tools.test_exporters import ReportExporter, ResultExporterType
@ -146,13 +146,12 @@ if __name__ == '__main__':
# parameters like 'toolchains_filter' are also set.
print "MBEDLS: Detecting connected mbed-enabled devices... "
if get_module_avail('mbed_lstools'):
mbeds = mbed_lstools.create()
muts_list = mbeds.list_mbeds_ext() if hasattr(mbeds, 'list_mbeds_ext') else mbeds.list_mbeds()
for mut in muts_list:
print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['platform_name_unique'] if 'platform_name_unique' in mut else mut['platform_name'],
mut['serial_port'],
mut['mount_point'])
MUTs = get_autodetected_MUTS_list()
for mut in MUTs.values():
print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
mut['port'],
mut['disk'])
# Set up parameters for test specification filter function (we need to set toolchains per target here)
use_default_toolchain = 'default' in opts.toolchains_filter.split(',') if opts.toolchains_filter is not None else True
@ -160,13 +159,11 @@ if __name__ == '__main__':
toolchain_filter = opts.toolchains_filter
platform_name_filter = opts.general_filter_regex.split(',') if opts.general_filter_regex is not None else opts.general_filter_regex
# Test specification with information about each target and associated toolchain
test_spec = get_autodetected_TEST_SPEC(muts_list,
test_spec = get_autodetected_TEST_SPEC(MUTs.values(),
use_default_toolchain=use_default_toolchain,
use_supported_toolchains=use_supported_toolchains,
toolchain_filter=toolchain_filter,
platform_name_filter=platform_name_filter)
# MUTs configuration auto-detection
MUTs = get_autodetected_MUTS(muts_list)
else:
# Open file with test specification
# test_spec_filename tells script which targets and their toolchain(s)
@ -254,7 +251,8 @@ if __name__ == '__main__':
_opts_jobs=opts.jobs,
_opts_waterfall_test=opts.waterfall_test,
_opts_consolidate_waterfall_test=opts.consolidate_waterfall_test,
_opts_extend_test_timeout=opts.extend_test_timeout)
_opts_extend_test_timeout=opts.extend_test_timeout,
_opts_auto_detect=opts.auto_detect)
# Runs test suite in CLI mode
if (singletest_in_cli_mode(single_test)):

View File

@ -27,6 +27,7 @@ import random
import optparse
import datetime
import threading
import ctypes
from types import ListType
from colorama import Fore, Back, Style
from prettytable import PrettyTable
@ -180,7 +181,8 @@ class SingleTestRunner(object):
_opts_jobs=None,
_opts_waterfall_test=None,
_opts_consolidate_waterfall_test=None,
_opts_extend_test_timeout=None):
_opts_extend_test_timeout=None,
_opts_auto_detect=None):
""" Let's try hard to init this object
"""
from colorama import init
@ -240,6 +242,7 @@ class SingleTestRunner(object):
self.opts_consolidate_waterfall_test = _opts_consolidate_waterfall_test
self.opts_extend_test_timeout = _opts_extend_test_timeout
self.opts_clean = _clean
self.opts_auto_detect = _opts_auto_detect
# File / screen logger initialization
self.logger = CLITestLogger(file_name=self.opts_log_file_name) # Default test logger
@ -855,26 +858,9 @@ class SingleTestRunner(object):
print "Error: No Mbed available: MUT[%s]" % data['mcu']
return None
disk = mut.get('disk')
port = mut.get('port')
if disk is None or port is None:
return None
target_by_mcu = TARGET_MAP[mut['mcu']]
target_name_unique = mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu']
# Some extra stuff can be declared in MUTs structure
reset_type = mut.get('reset_type') # reboot.txt, reset.txt, shutdown.txt
reset_tout = mut.get('reset_tout') # COPY_IMAGE -> RESET_PROC -> SLEEP(RESET_TOUT)
image_dest = mut.get('image_dest') # Image file destination DISK + IMAGE_DEST + BINARY_NAME
images_config = mut.get('images_config') # Available images selection via config file
mobo_config = mut.get('mobo_config') # Available board configuration selection e.g. core selection etc.
mcu = mut['mcu']
copy_method = mut.get('copy_method') # Available board configuration selection e.g. core selection etc.
# When the build and test system were separate, this was relative to a
# base network folder base path: join(NETWORK_BASE_PATH, )
image_path = image
if self.db_logger:
self.db_logger.reconnect()
@ -886,6 +872,46 @@ class SingleTestRunner(object):
detailed_test_results = {} # { Loop_number: { results ... } }
for test_index in range(test_loops):
# If mbedls is available and we are auto detecting MUT info,
# update MUT info (mounting may changed)
if get_module_avail('mbed_lstools') and self.opts_auto_detect:
platform_name_filter = [mcu]
muts_list = {}
found = False
for i in range(0, 60):
print('Looking for %s with MBEDLS' % mcu)
muts_list = get_autodetected_MUTS_list(platform_name_filter=platform_name_filter)
if 1 not in muts_list:
sleep(3)
else:
found = True
break
if not found:
print "Error: mbed not found with MBEDLS: %s" % data['mcu']
return None
else:
mut = muts_list[1]
disk = mut.get('disk')
port = mut.get('port')
if disk is None or port is None:
return None
target_by_mcu = TARGET_MAP[mut['mcu']]
target_name_unique = mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu']
# Some extra stuff can be declared in MUTs structure
reset_type = mut.get('reset_type') # reboot.txt, reset.txt, shutdown.txt
reset_tout = mut.get('reset_tout') # COPY_IMAGE -> RESET_PROC -> SLEEP(RESET_TOUT)
# When the build and test system were separate, this was relative to a
# base network folder base path: join(NETWORK_BASE_PATH, )
image_path = image
# Host test execution
start_host_exec_time = time()
@ -1066,6 +1092,9 @@ class SingleTestRunner(object):
'-t', str(duration),
'-C', str(program_cycle_s)]
if get_module_avail('mbed_lstools') and self.opts_auto_detect:
cmd += ['--auto']
# Add extra parameters to host_test
if copy_method is not None:
cmd += ["-c", copy_method]
@ -1642,6 +1671,20 @@ def get_module_avail(module_name):
return module_name in sys.modules.keys()
def get_autodetected_MUTS_list(platform_name_filter=None):
oldError = None
if os.name == 'nt':
# Disable Windows error box temporarily
oldError = ctypes.windll.kernel32.SetErrorMode(1) #note that SEM_FAILCRITICALERRORS = 1
mbeds = mbed_lstools.create()
detect_muts_list = mbeds.list_mbeds()
if os.name == 'nt':
ctypes.windll.kernel32.SetErrorMode(oldError)
return get_autodetected_MUTS(detect_muts_list, platform_name_filter=platform_name_filter)
def get_autodetected_MUTS(mbeds_list, platform_name_filter=None):
""" Function detects all connected to host mbed-enabled devices and generates artificial MUTS file.
If function fails to auto-detect devices it will return empty dictionary.
@ -1658,6 +1701,11 @@ def get_autodetected_MUTS(mbeds_list, platform_name_filter=None):
# mbeds_list = [{'platform_name': 'NUCLEO_F302R8', 'mount_point': 'E:', 'target_id': '07050200623B61125D5EF72A', 'serial_port': u'COM34'}]
index = 1
for mut in mbeds_list:
# Filter the MUTS if a filter is specified
if platform_name_filter and not mut['platform_name'] in platform_name_filter:
continue
# For mcu_unique - we are assigning 'platform_name_unique' value from mbedls output (if its existing)
# if not we are creating our own unique value (last few chars from platform's target_id).
m = {'mcu': mut['platform_name'],
@ -1688,8 +1736,8 @@ def get_autodetected_TEST_SPEC(mbeds_list,
result = {'targets': {} }
for mut in mbeds_list:
mcu = mut['platform_name']
if platform_name_filter is None or (platform_name_filter and mut['platform_name'] in platform_name_filter):
mcu = mut['mcu']
if platform_name_filter is None or (platform_name_filter and mut['mcu'] in platform_name_filter):
if mcu in TARGET_MAP:
default_toolchain = TARGET_MAP[mcu].default_toolchain
supported_toolchains = TARGET_MAP[mcu].supported_toolchains