From f3d20141a3ded997a18cade1fec8a39ccbe3aa88 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Thu, 6 Oct 2016 17:40:25 -0500 Subject: [PATCH] Allowing mbed_app.json files to be discovered for tests. Before, mbed_app.json files were explicitly ignored when building tests. This was mostly because you could have multiple mbed_app.json files in the tree (for instance, in test case folders) and the behavior would be undefined. Now the tools explicitly ensure that there aren't multiple mbed_app.json files in your source files. So auto discovery of mbed_app.json for testing is being reintroduced. --- docs/testing_mbed_OS_5.md | 4 +++- tools/test.py | 13 ++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/testing_mbed_OS_5.md b/docs/testing_mbed_OS_5.md index f21565a913e..d119f745bca 100644 --- a/docs/testing_mbed_OS_5.md +++ b/docs/testing_mbed_OS_5.md @@ -78,7 +78,9 @@ The full build process is: When building an mbed application, the presence of a `mbed_app.json` file allows you to set or override different config settings from libraries and targets. However, because the tests share a common build, this can cause issues when tests have different configurations that affect the OS. -If you need to use app config, this must be set via the `--app-config` option when calling `mbed test`. **If this option is not specified, the build system will ignore all `mbed_app.json` files and use the default config values.** +The build system will look for an `mbed_app.json` file in your shared project files (any directory not inside of a `TESTS` folder). If this is found, this configuration file will be used for both the non-test code as well as each test case inside your project's source tree. If there is more than one `mbed_app.json` files in the source tree, the config system will error. + +If you need to test with multiple configurations, then you can use the `--app-config` option. This will override the search for an `mbed_app.json` file and use the config file you specify for the build. ### Running tests diff --git a/tools/test.py b/tools/test.py index 9e520d59b29..ec153d499a2 100644 --- a/tools/test.py +++ b/tools/test.py @@ -26,6 +26,7 @@ ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, ROOT) +from tools.config import ConfigException from tools.test_api import test_path_to_name, find_tests, print_tests, build_tests, test_spec_from_test_builds from tools.options import get_default_options_parser, extract_profile from tools.build_api import build_project, build_library @@ -121,15 +122,6 @@ "Currently set search path: %s" % (toolchain, search_path)) - # App config - # Disable finding `mbed_app.json` files in the source tree if not - # explicitly defined on the command line. Config system searches for - # `mbed_app.json` files if `app_config` is None, but will set the - # app config data to an empty dictionary if the path value is another - # falsey value besides None. - if options.app_config is None: - options.app_config = '' - # Find all tests in the relevant paths for path in all_paths: all_tests.update(find_tests(path, mcu, toolchain, @@ -261,6 +253,9 @@ except KeyboardInterrupt, e: print "\n[CTRL+c] exit" + except ConfigException, e: + # Catching ConfigException here to prevent a traceback + print "[ERROR] %s" % str(e) except Exception,e: import traceback traceback.print_exc(file=sys.stdout)