From 6da324fa3fe114f03120aa9ff5024615256f77d3 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 14 Jun 2016 14:17:38 -0500 Subject: [PATCH] [build tools] Added test coverage for config features feature --- tools/build_api.py | 30 ++++++++++++---- tools/test/config_test/config_test.py | 36 ++++++++++++------- tools/test/config_test/test21/mbed_app.json | 7 ++++ tools/test/config_test/test21/test_data.py | 8 +++++ .../config_test/test22/lib1/mbed_lib.json | 8 +++++ tools/test/config_test/test22/mbed_app.json | 7 ++++ tools/test/config_test/test22/test_data.py | 8 +++++ .../config_test/test23/lib1/mbed_lib.json | 8 +++++ .../config_test/test23/lib2/mbed_lib.json | 8 +++++ tools/test/config_test/test23/mbed_app.json | 7 ++++ tools/test/config_test/test23/test_data.py | 8 +++++ .../test24/FEATURE_IPV4/lib1/mbed_lib.json | 8 +++++ .../test24/FEATURE_IPV6/lib2/mbed_lib.json | 8 +++++ tools/test/config_test/test24/mbed_app.json | 7 ++++ tools/test/config_test/test24/test_data.py | 8 +++++ .../FEATURE_IPV4/lib1/mbed_lib.json | 8 +++++ .../test25/FEATURE_IPV6/lib2/mbed_lib.json | 8 +++++ tools/test/config_test/test25/mbed_app.json | 7 ++++ tools/test/config_test/test25/test_data.py | 8 +++++ 19 files changed, 178 insertions(+), 19 deletions(-) create mode 100644 tools/test/config_test/test21/mbed_app.json create mode 100644 tools/test/config_test/test21/test_data.py create mode 100644 tools/test/config_test/test22/lib1/mbed_lib.json create mode 100644 tools/test/config_test/test22/mbed_app.json create mode 100644 tools/test/config_test/test22/test_data.py create mode 100644 tools/test/config_test/test23/lib1/mbed_lib.json create mode 100644 tools/test/config_test/test23/lib2/mbed_lib.json create mode 100644 tools/test/config_test/test23/mbed_app.json create mode 100644 tools/test/config_test/test23/test_data.py create mode 100644 tools/test/config_test/test24/FEATURE_IPV4/lib1/mbed_lib.json create mode 100644 tools/test/config_test/test24/FEATURE_IPV6/lib2/mbed_lib.json create mode 100644 tools/test/config_test/test24/mbed_app.json create mode 100644 tools/test/config_test/test24/test_data.py create mode 100644 tools/test/config_test/test25/FEATURE_IPV6/FEATURE_IPV4/lib1/mbed_lib.json create mode 100644 tools/test/config_test/test25/FEATURE_IPV6/lib2/mbed_lib.json create mode 100644 tools/test/config_test/test25/mbed_app.json create mode 100644 tools/test/config_test/test25/test_data.py diff --git a/tools/build_api.py b/tools/build_api.py index d9c6835b6c..a5f6dc93b7 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -105,8 +105,26 @@ def get_config(src_path, target, toolchain_name): for path in src_paths[1:]: resources.add(toolchain.scan_resources(path)) - config.add_config_files(resources.json_files) - return config.get_config_data() + # Update configuration files until added features creates no changes + prev_features = set() + while True: + # Update the configuration with any .json files found while scanning + config.add_config_files(resources.json_files) + + # Add features while we find new ones + features = config.get_features() + if features == prev_features: + break + + for feature in features: + if feature in resources.features: + resources += resources.features[feature] + + prev_features = features + + cfg, macros = config.get_config_data() + features = config.get_features() + return cfg, macros, features def build_project(src_path, build_path, target, toolchain_name, libraries_paths=None, options=None, linker_script=None, @@ -207,9 +225,8 @@ def build_project(src_path, build_path, target, toolchain_name, break for feature in features: - if feature not in resources.features: - raise KeyError("Feature %s is unavailable" % feature) - resources += resources.features[feature] + if feature in resources.features: + resources += resources.features[feature] prev_features = features @@ -373,7 +390,8 @@ def build_library(src_paths, build_path, target, toolchain_name, break for feature in features: - resources += resources.features[feature] + if feature in resources.features: + resources += resources.features[feature] prev_features = features diff --git a/tools/test/config_test/config_test.py b/tools/test/config_test/config_test.py index a520c2006d..a0e5eab8ff 100644 --- a/tools/test/config_test/config_test.py +++ b/tools/test/config_test/config_test.py @@ -28,7 +28,7 @@ def compare_config(cfg, expected): except KeyError: return "Unexpected key '%s' in configuration data" % k for k in expected: - if k != "desc" and k != "expected_macros" and not k in cfg: + if k not in ["desc", "expected_macros", "expected_features"] + cfg.keys(): return "Expected key '%s' was not found in configuration data" % k return "" @@ -43,7 +43,7 @@ def test_tree(full_name, name): sys.stdout.flush() err_msg = None try: - cfg, macros = get_config(full_name, target, "GCC_ARM") + cfg, macros, features = get_config(full_name, target, "GCC_ARM") except ConfigException as e: err_msg = e.message if err_msg: @@ -63,23 +63,33 @@ def test_tree(full_name, name): failed += 1 else: res = compare_config(cfg, expected) + expected_macros = expected.get("expected_macros", None) + expected_features = expected.get("expected_features", None) + if res: print "FAILED!" sys.stdout.write(" " + res + "\n") failed += 1 - else: - expected_macros = expected.get("expected_macros", None) - if expected_macros is not None: - if sorted(expected_macros) != sorted(macros): - print "FAILED!" - sys.stderr.write(" List of macros doesn't match\n") - sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros))) - sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros))) - failed += 1 - else: - print "OK" + elif expected_macros is not None: + if sorted(expected_macros) != sorted(macros): + print "FAILED!" + sys.stderr.write(" List of macros doesn't match\n") + sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros))) + sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros))) + failed += 1 else: print "OK" + elif expected_features is not None: + if sorted(expected_features) != sorted(features): + print "FAILED!" + sys.stderr.write(" List of features doesn't match\n") + sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_features))) + sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_features))) + failed += 1 + else: + print "OK" + else: + print "OK" sys.path.remove(full_name) return failed diff --git a/tools/test/config_test/test21/mbed_app.json b/tools/test/config_test/test21/mbed_app.json new file mode 100644 index 0000000000..cb3c7ed133 --- /dev/null +++ b/tools/test/config_test/test21/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "features": ["IPV4", "IPV6"] + } + } +} diff --git a/tools/test/config_test/test21/test_data.py b/tools/test/config_test/test21/test_data.py new file mode 100644 index 0000000000..ccacf26faf --- /dev/null +++ b/tools/test/config_test/test21/test_data.py @@ -0,0 +1,8 @@ +# Testing basic features + +expected_results = { + "K64F": { + "desc": "test basic features", + "expected_features": ["IPV4", "IPV6"] + } +} diff --git a/tools/test/config_test/test22/lib1/mbed_lib.json b/tools/test/config_test/test22/lib1/mbed_lib.json new file mode 100644 index 0000000000..b35e4d56c0 --- /dev/null +++ b/tools/test/config_test/test22/lib1/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib1", + "target_overrides": { + "*": { + "features_add": ["IPV4"] + } + } +} diff --git a/tools/test/config_test/test22/mbed_app.json b/tools/test/config_test/test22/mbed_app.json new file mode 100644 index 0000000000..d5126abf78 --- /dev/null +++ b/tools/test/config_test/test22/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "features_add": ["IPV6"] + } + } +} diff --git a/tools/test/config_test/test22/test_data.py b/tools/test/config_test/test22/test_data.py new file mode 100644 index 0000000000..6fcd508961 --- /dev/null +++ b/tools/test/config_test/test22/test_data.py @@ -0,0 +1,8 @@ +# Testing when adding two features + +expected_results = { + "K64F": { + "desc": "test composing features", + "expected_features": ["IPV4", "IPV6"] + } +} diff --git a/tools/test/config_test/test23/lib1/mbed_lib.json b/tools/test/config_test/test23/lib1/mbed_lib.json new file mode 100644 index 0000000000..b35e4d56c0 --- /dev/null +++ b/tools/test/config_test/test23/lib1/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib1", + "target_overrides": { + "*": { + "features_add": ["IPV4"] + } + } +} diff --git a/tools/test/config_test/test23/lib2/mbed_lib.json b/tools/test/config_test/test23/lib2/mbed_lib.json new file mode 100644 index 0000000000..6215ff57d7 --- /dev/null +++ b/tools/test/config_test/test23/lib2/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib2", + "target_overrides": { + "*": { + "features_remove": ["IPV4"] + } + } +} diff --git a/tools/test/config_test/test23/mbed_app.json b/tools/test/config_test/test23/mbed_app.json new file mode 100644 index 0000000000..d5126abf78 --- /dev/null +++ b/tools/test/config_test/test23/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "features_add": ["IPV6"] + } + } +} diff --git a/tools/test/config_test/test23/test_data.py b/tools/test/config_test/test23/test_data.py new file mode 100644 index 0000000000..0d1105a08a --- /dev/null +++ b/tools/test/config_test/test23/test_data.py @@ -0,0 +1,8 @@ +# Testing when two features collide + +expected_results = { + "K64F": { + "desc": "test feature collisions", + "exception_msg": "Configuration conflict. Feature IPV4 both added and removed." + } +} diff --git a/tools/test/config_test/test24/FEATURE_IPV4/lib1/mbed_lib.json b/tools/test/config_test/test24/FEATURE_IPV4/lib1/mbed_lib.json new file mode 100644 index 0000000000..6b23b3450a --- /dev/null +++ b/tools/test/config_test/test24/FEATURE_IPV4/lib1/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib1", + "target_overrides": { + "*": { + "features_add": ["IPV6"] + } + } +} diff --git a/tools/test/config_test/test24/FEATURE_IPV6/lib2/mbed_lib.json b/tools/test/config_test/test24/FEATURE_IPV6/lib2/mbed_lib.json new file mode 100644 index 0000000000..6acafdcdc8 --- /dev/null +++ b/tools/test/config_test/test24/FEATURE_IPV6/lib2/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib2", + "target_overrides": { + "*": { + "features_add": ["UVISOR"] + } + } +} diff --git a/tools/test/config_test/test24/mbed_app.json b/tools/test/config_test/test24/mbed_app.json new file mode 100644 index 0000000000..58a9d08845 --- /dev/null +++ b/tools/test/config_test/test24/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "features_add": ["IPV4"] + } + } +} diff --git a/tools/test/config_test/test24/test_data.py b/tools/test/config_test/test24/test_data.py new file mode 100644 index 0000000000..97ebe5bc7c --- /dev/null +++ b/tools/test/config_test/test24/test_data.py @@ -0,0 +1,8 @@ +# Testing if features can enable other features + +expected_results = { + "K64F": { + "desc": "test recursive features", + "expected_features": ["IPV4", "IPV6", "UVISOR"] + } +} diff --git a/tools/test/config_test/test25/FEATURE_IPV6/FEATURE_IPV4/lib1/mbed_lib.json b/tools/test/config_test/test25/FEATURE_IPV6/FEATURE_IPV4/lib1/mbed_lib.json new file mode 100644 index 0000000000..6b23b3450a --- /dev/null +++ b/tools/test/config_test/test25/FEATURE_IPV6/FEATURE_IPV4/lib1/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib1", + "target_overrides": { + "*": { + "features_add": ["IPV6"] + } + } +} diff --git a/tools/test/config_test/test25/FEATURE_IPV6/lib2/mbed_lib.json b/tools/test/config_test/test25/FEATURE_IPV6/lib2/mbed_lib.json new file mode 100644 index 0000000000..6acafdcdc8 --- /dev/null +++ b/tools/test/config_test/test25/FEATURE_IPV6/lib2/mbed_lib.json @@ -0,0 +1,8 @@ +{ + "name": "lib2", + "target_overrides": { + "*": { + "features_add": ["UVISOR"] + } + } +} diff --git a/tools/test/config_test/test25/mbed_app.json b/tools/test/config_test/test25/mbed_app.json new file mode 100644 index 0000000000..cb3c7ed133 --- /dev/null +++ b/tools/test/config_test/test25/mbed_app.json @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "features": ["IPV4", "IPV6"] + } + } +} diff --git a/tools/test/config_test/test25/test_data.py b/tools/test/config_test/test25/test_data.py new file mode 100644 index 0000000000..1ebfc24924 --- /dev/null +++ b/tools/test/config_test/test25/test_data.py @@ -0,0 +1,8 @@ +# Testing if feature collisions are detected accross recursive features + +expected_results = { + "K64F": { + "desc": "test recursive feature collisions", + "exception_msg": "Configuration conflict. Feature UVISOR both added and removed." + } +}