[build tools] Added test coverage for config features feature

pull/1940/head
Christopher Haster 2016-06-14 14:17:38 -05:00
parent d9749b0447
commit 6da324fa3f
19 changed files with 178 additions and 19 deletions

View File

@ -105,8 +105,26 @@ def get_config(src_path, target, toolchain_name):
for path in src_paths[1:]: for path in src_paths[1:]:
resources.add(toolchain.scan_resources(path)) resources.add(toolchain.scan_resources(path))
# 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) config.add_config_files(resources.json_files)
return config.get_config_data()
# 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, def build_project(src_path, build_path, target, toolchain_name,
libraries_paths=None, options=None, linker_script=None, libraries_paths=None, options=None, linker_script=None,
@ -207,8 +225,7 @@ def build_project(src_path, build_path, target, toolchain_name,
break break
for feature in features: for feature in features:
if feature not in resources.features: if feature in resources.features:
raise KeyError("Feature %s is unavailable" % feature)
resources += resources.features[feature] resources += resources.features[feature]
prev_features = features prev_features = features
@ -373,6 +390,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
break break
for feature in features: for feature in features:
if feature in resources.features:
resources += resources.features[feature] resources += resources.features[feature]
prev_features = features prev_features = features

View File

@ -28,7 +28,7 @@ def compare_config(cfg, expected):
except KeyError: except KeyError:
return "Unexpected key '%s' in configuration data" % k return "Unexpected key '%s' in configuration data" % k
for k in expected: 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 "Expected key '%s' was not found in configuration data" % k
return "" return ""
@ -43,7 +43,7 @@ def test_tree(full_name, name):
sys.stdout.flush() sys.stdout.flush()
err_msg = None err_msg = None
try: try:
cfg, macros = get_config(full_name, target, "GCC_ARM") cfg, macros, features = get_config(full_name, target, "GCC_ARM")
except ConfigException as e: except ConfigException as e:
err_msg = e.message err_msg = e.message
if err_msg: if err_msg:
@ -63,13 +63,14 @@ def test_tree(full_name, name):
failed += 1 failed += 1
else: else:
res = compare_config(cfg, expected) res = compare_config(cfg, expected)
expected_macros = expected.get("expected_macros", None)
expected_features = expected.get("expected_features", None)
if res: if res:
print "FAILED!" print "FAILED!"
sys.stdout.write(" " + res + "\n") sys.stdout.write(" " + res + "\n")
failed += 1 failed += 1
else: elif expected_macros is not None:
expected_macros = expected.get("expected_macros", None)
if expected_macros is not None:
if sorted(expected_macros) != sorted(macros): if sorted(expected_macros) != sorted(macros):
print "FAILED!" print "FAILED!"
sys.stderr.write(" List of macros doesn't match\n") sys.stderr.write(" List of macros doesn't match\n")
@ -78,6 +79,15 @@ def test_tree(full_name, name):
failed += 1 failed += 1
else: else:
print "OK" 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: else:
print "OK" print "OK"
sys.path.remove(full_name) sys.path.remove(full_name)

View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"features": ["IPV4", "IPV6"]
}
}
}

View File

@ -0,0 +1,8 @@
# Testing basic features
expected_results = {
"K64F": {
"desc": "test basic features",
"expected_features": ["IPV4", "IPV6"]
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib1",
"target_overrides": {
"*": {
"features_add": ["IPV4"]
}
}
}

View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"features_add": ["IPV6"]
}
}
}

View File

@ -0,0 +1,8 @@
# Testing when adding two features
expected_results = {
"K64F": {
"desc": "test composing features",
"expected_features": ["IPV4", "IPV6"]
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib1",
"target_overrides": {
"*": {
"features_add": ["IPV4"]
}
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib2",
"target_overrides": {
"*": {
"features_remove": ["IPV4"]
}
}
}

View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"features_add": ["IPV6"]
}
}
}

View File

@ -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."
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib1",
"target_overrides": {
"*": {
"features_add": ["IPV6"]
}
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib2",
"target_overrides": {
"*": {
"features_add": ["UVISOR"]
}
}
}

View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"features_add": ["IPV4"]
}
}
}

View File

@ -0,0 +1,8 @@
# Testing if features can enable other features
expected_results = {
"K64F": {
"desc": "test recursive features",
"expected_features": ["IPV4", "IPV6", "UVISOR"]
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib1",
"target_overrides": {
"*": {
"features_add": ["IPV6"]
}
}
}

View File

@ -0,0 +1,8 @@
{
"name": "lib2",
"target_overrides": {
"*": {
"features_add": ["UVISOR"]
}
}
}

View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"features": ["IPV4", "IPV6"]
}
}
}

View File

@ -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."
}
}