Add test command switch for app config file

pull/2593/head
Conor Keegan 2016-08-31 16:20:59 +01:00 committed by Conor Keegan
parent 5b90bf7b1d
commit 7c72a22508
4 changed files with 43 additions and 25 deletions

View File

@ -276,7 +276,8 @@ def get_mbed_official_release(version):
def prepare_toolchain(src_paths, target, toolchain_name, def prepare_toolchain(src_paths, target, toolchain_name,
macros=None, options=None, clean=False, jobs=1, macros=None, options=None, clean=False, jobs=1,
notify=None, silent=False, verbose=False, notify=None, silent=False, verbose=False,
extra_verbose=False, config=None): extra_verbose=False, config=None,
app_config=None):
""" Prepares resource related objects - toolchain, target, config """ Prepares resource related objects - toolchain, target, config
Positional arguments: Positional arguments:
@ -294,6 +295,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
verbose - Write the actual tools command lines used if True verbose - Write the actual tools command lines used if True
extra_verbose - even more output! extra_verbose - even more output!
config - a Config object to use instead of creating one config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
""" """
# We need to remove all paths which are repeated to avoid # We need to remove all paths which are repeated to avoid
@ -301,7 +303,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
src_paths = [src_paths[0]] + list(set(src_paths[1:])) src_paths = [src_paths[0]] + list(set(src_paths[1:]))
# If the configuration object was not yet created, create it now # If the configuration object was not yet created, create it now
config = config or Config(target, src_paths) config = config or Config(target, src_paths, app_config=app_config)
# If the 'target' argument is a string, convert it to a target instance # If the 'target' argument is a string, convert it to a target instance
if isinstance(target, basestring): if isinstance(target, basestring):
@ -369,7 +371,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
clean=False, notify=None, verbose=False, name=None, clean=False, notify=None, verbose=False, name=None,
macros=None, inc_dirs=None, jobs=1, silent=False, macros=None, inc_dirs=None, jobs=1, silent=False,
report=None, properties=None, project_id=None, report=None, properties=None, project_id=None,
project_description=None, extra_verbose=False, config=None): project_description=None, extra_verbose=False, config=None,
app_config=None):
""" Build a project. A project may be a test or a user program. """ Build a project. A project may be a test or a user program.
Positional arguments: Positional arguments:
@ -397,6 +400,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
project_description - the human-readable version of what this thing does project_description - the human-readable version of what this thing does
extra_verbose - even more output! extra_verbose - even more output!
config - a Config object to use instead of creating one config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
""" """
# Convert src_path to a list if needed # Convert src_path to a list if needed
@ -415,7 +419,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain( toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options, src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose, clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose, config=config) extra_verbose=extra_verbose, config=config, app_config=app_config)
# The first path will give the name to the library # The first path will give the name to the library
if name is None: if name is None:
@ -489,7 +493,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
archive=True, notify=None, verbose=False, macros=None, archive=True, notify=None, verbose=False, macros=None,
inc_dirs=None, jobs=1, silent=False, report=None, inc_dirs=None, jobs=1, silent=False, report=None,
properties=None, extra_verbose=False, project_id=None, properties=None, extra_verbose=False, project_id=None,
remove_config_header_file=False): remove_config_header_file=False, app_config=None):
""" Build a library """ Build a library
Positional arguments: Positional arguments:
@ -516,6 +520,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
extra_verbose - even more output! extra_verbose - even more output!
project_id - the name that goes in the report project_id - the name that goes in the report
remove_config_header_file - delete config header file when done building remove_config_header_file - delete config header file when done building
app_config - location of a chosen mbed_app.json file
""" """
# Convert src_path to a list if needed # Convert src_path to a list if needed
@ -539,7 +544,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain( toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options, src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose, clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose) extra_verbose=extra_verbose, app_config=app_config)
# The first path will give the name to the library # The first path will give the name to the library
if name is None: if name is None:

View File

@ -350,7 +350,7 @@ class Config(object):
"UVISOR", "BLE", "CLIENT", "IPV4", "IPV6", "COMMON_PAL", "STORAGE" "UVISOR", "BLE", "CLIENT", "IPV4", "IPV6", "COMMON_PAL", "STORAGE"
] ]
def __init__(self, target, top_level_dirs=None): def __init__(self, target, top_level_dirs=None, app_config=None):
"""Construct a mbed configuration """Construct a mbed configuration
Positional arguments: Positional arguments:
@ -359,7 +359,8 @@ class Config(object):
Keyword argumets: Keyword argumets:
top_level_dirs - a list of top level source directories (where top_level_dirs - a list of top level source directories (where
mbed_abb_config.json could be found) mbed_app_config.json could be found)
app_config - location of a chosen mbed_app.json file
NOTE: Construction of a Config object will look for the application NOTE: Construction of a Config object will look for the application
configuration file in top_level_dirs. If found once, it'll parse it and configuration file in top_level_dirs. If found once, it'll parse it and
@ -368,7 +369,8 @@ class Config(object):
exception is raised. top_level_dirs may be None (in this case, exception is raised. top_level_dirs may be None (in this case,
the constructor will not search for a configuration file) the constructor will not search for a configuration file)
""" """
app_config_location = None app_config_location = app_config
if app_config_location is None:
for directory in top_level_dirs or []: for directory in top_level_dirs or []:
full_path = os.path.join(directory, self.__mbed_app_config_name) full_path = os.path.join(directory, self.__mbed_app_config_name)
if os.path.isfile(full_path): if os.path.isfile(full_path):
@ -384,6 +386,7 @@ class Config(object):
except ValueError as exc: except ValueError as exc:
sys.stderr.write(str(exc) + "\n") sys.stderr.write(str(exc) + "\n")
self.app_config_data = {} self.app_config_data = {}
# Check the keys in the application configuration data # Check the keys in the application configuration data
unknown_keys = set(self.app_config_data.keys()) - \ unknown_keys = set(self.app_config_data.keys()) - \
self.__allowed_keys["application"] self.__allowed_keys["application"]

View File

@ -94,6 +94,10 @@ if __name__ == '__main__':
default=False, default=False,
help="Verbose diagnostic output") help="Verbose diagnostic output")
parser.add_argument("--app-config", default=None, dest="app_config",
type=argparse_filestring_type,
help="Path of an app configuration file (Default is to look for 'mbed_app.json')")
options = parser.parse_args() options = parser.parse_args()
# Filter tests by path if specified # Filter tests by path if specified
@ -117,7 +121,8 @@ if __name__ == '__main__':
# Find all tests in the relevant paths # Find all tests in the relevant paths
for path in all_paths: for path in all_paths:
all_tests.update(find_tests(path, mcu, toolchain, options.options)) all_tests.update(find_tests(path, mcu, toolchain, options.options,
app_config=options.app_config))
# Filter tests by name if specified # Filter tests by name if specified
if options.names: if options.names:
@ -177,7 +182,8 @@ if __name__ == '__main__':
verbose=options.verbose, verbose=options.verbose,
notify=notify, notify=notify,
archive=False, archive=False,
remove_config_header_file=True) remove_config_header_file=True,
app_config=options.app_config)
library_build_success = True library_build_success = True
except ToolException, e: except ToolException, e:
@ -203,7 +209,8 @@ if __name__ == '__main__':
verbose=options.verbose, verbose=options.verbose,
notify=notify, notify=notify,
jobs=options.jobs, jobs=options.jobs,
continue_on_build_fail=options.continue_on_build_fail) continue_on_build_fail=options.continue_on_build_fail,
app_config=options.app_config)
# If a path to a test spec is provided, write it to a file # If a path to a test spec is provided, write it to a file
if options.test_spec: if options.test_spec:

View File

@ -1990,18 +1990,20 @@ def test_path_to_name(path, base):
return "-".join(name_parts).lower() return "-".join(name_parts).lower()
def find_tests(base_dir, target_name, toolchain_name, options=None): def find_tests(base_dir, target_name, toolchain_name, options=None, app_config=None):
""" Finds all tests in a directory recursively """ Finds all tests in a directory recursively
base_dir: path to the directory to scan for tests (ex. 'path/to/project') base_dir: path to the directory to scan for tests (ex. 'path/to/project')
target_name: name of the target to use for scanning (ex. 'K64F') target_name: name of the target to use for scanning (ex. 'K64F')
toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM') toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM')
options: Compile options to pass to the toolchain (ex. ['debug-info']) options: Compile options to pass to the toolchain (ex. ['debug-info'])
app_config - location of a chosen mbed_app.json file
""" """
tests = {} tests = {}
# Prepare the toolchain # Prepare the toolchain
toolchain = prepare_toolchain([base_dir], target_name, toolchain_name, options=options, silent=True) toolchain = prepare_toolchain([base_dir], target_name, toolchain_name, options=options,
silent=True, app_config=app_config)
# Scan the directory for paths to probe for 'TESTS' folders # Scan the directory for paths to probe for 'TESTS' folders
base_resources = scan_resources([base_dir], toolchain) base_resources = scan_resources([base_dir], toolchain)
@ -2060,7 +2062,7 @@ def norm_relative_path(path, start):
def build_tests(tests, base_source_paths, build_path, target, toolchain_name, def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
options=None, clean=False, notify=None, verbose=False, jobs=1, options=None, clean=False, notify=None, verbose=False, jobs=1,
macros=None, silent=False, report=None, properties=None, macros=None, silent=False, report=None, properties=None,
continue_on_build_fail=False): continue_on_build_fail=False, app_config=None):
"""Given the data structure from 'find_tests' and the typical build parameters, """Given the data structure from 'find_tests' and the typical build parameters,
build all the tests build all the tests
@ -2101,7 +2103,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
project_id=test_name, project_id=test_name,
report=report, report=report,
properties=properties, properties=properties,
verbose=verbose) verbose=verbose,
app_config=app_config)
except Exception, e: except Exception, e:
if not isinstance(e, NotSupportedException): if not isinstance(e, NotSupportedException):