Skip to content

Commit 6da324f

Browse files
committed
[build tools] Added test coverage for config features feature
1 parent d9749b0 commit 6da324f

File tree

19 files changed

+178
-19
lines changed

19 files changed

+178
-19
lines changed

tools/build_api.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,26 @@ def get_config(src_path, target, toolchain_name):
105105
for path in src_paths[1:]:
106106
resources.add(toolchain.scan_resources(path))
107107

108-
config.add_config_files(resources.json_files)
109-
return config.get_config_data()
108+
# Update configuration files until added features creates no changes
109+
prev_features = set()
110+
while True:
111+
# Update the configuration with any .json files found while scanning
112+
config.add_config_files(resources.json_files)
113+
114+
# Add features while we find new ones
115+
features = config.get_features()
116+
if features == prev_features:
117+
break
118+
119+
for feature in features:
120+
if feature in resources.features:
121+
resources += resources.features[feature]
122+
123+
prev_features = features
124+
125+
cfg, macros = config.get_config_data()
126+
features = config.get_features()
127+
return cfg, macros, features
110128

111129
def build_project(src_path, build_path, target, toolchain_name,
112130
libraries_paths=None, options=None, linker_script=None,
@@ -207,9 +225,8 @@ def build_project(src_path, build_path, target, toolchain_name,
207225
break
208226

209227
for feature in features:
210-
if feature not in resources.features:
211-
raise KeyError("Feature %s is unavailable" % feature)
212-
resources += resources.features[feature]
228+
if feature in resources.features:
229+
resources += resources.features[feature]
213230

214231
prev_features = features
215232

@@ -373,7 +390,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
373390
break
374391

375392
for feature in features:
376-
resources += resources.features[feature]
393+
if feature in resources.features:
394+
resources += resources.features[feature]
377395

378396
prev_features = features
379397

tools/test/config_test/config_test.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def compare_config(cfg, expected):
2828
except KeyError:
2929
return "Unexpected key '%s' in configuration data" % k
3030
for k in expected:
31-
if k != "desc" and k != "expected_macros" and not k in cfg:
31+
if k not in ["desc", "expected_macros", "expected_features"] + cfg.keys():
3232
return "Expected key '%s' was not found in configuration data" % k
3333
return ""
3434

@@ -43,7 +43,7 @@ def test_tree(full_name, name):
4343
sys.stdout.flush()
4444
err_msg = None
4545
try:
46-
cfg, macros = get_config(full_name, target, "GCC_ARM")
46+
cfg, macros, features = get_config(full_name, target, "GCC_ARM")
4747
except ConfigException as e:
4848
err_msg = e.message
4949
if err_msg:
@@ -63,23 +63,33 @@ def test_tree(full_name, name):
6363
failed += 1
6464
else:
6565
res = compare_config(cfg, expected)
66+
expected_macros = expected.get("expected_macros", None)
67+
expected_features = expected.get("expected_features", None)
68+
6669
if res:
6770
print "FAILED!"
6871
sys.stdout.write(" " + res + "\n")
6972
failed += 1
70-
else:
71-
expected_macros = expected.get("expected_macros", None)
72-
if expected_macros is not None:
73-
if sorted(expected_macros) != sorted(macros):
74-
print "FAILED!"
75-
sys.stderr.write(" List of macros doesn't match\n")
76-
sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros)))
77-
sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros)))
78-
failed += 1
79-
else:
80-
print "OK"
73+
elif expected_macros is not None:
74+
if sorted(expected_macros) != sorted(macros):
75+
print "FAILED!"
76+
sys.stderr.write(" List of macros doesn't match\n")
77+
sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros)))
78+
sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros)))
79+
failed += 1
8180
else:
8281
print "OK"
82+
elif expected_features is not None:
83+
if sorted(expected_features) != sorted(features):
84+
print "FAILED!"
85+
sys.stderr.write(" List of features doesn't match\n")
86+
sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_features)))
87+
sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_features)))
88+
failed += 1
89+
else:
90+
print "OK"
91+
else:
92+
print "OK"
8393
sys.path.remove(full_name)
8494
return failed
8595

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"features": ["IPV4", "IPV6"]
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing basic features
2+
3+
expected_results = {
4+
"K64F": {
5+
"desc": "test basic features",
6+
"expected_features": ["IPV4", "IPV6"]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib1",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["IPV4"]
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"features_add": ["IPV6"]
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing when adding two features
2+
3+
expected_results = {
4+
"K64F": {
5+
"desc": "test composing features",
6+
"expected_features": ["IPV4", "IPV6"]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib1",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["IPV4"]
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib2",
3+
"target_overrides": {
4+
"*": {
5+
"features_remove": ["IPV4"]
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"features_add": ["IPV6"]
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing when two features collide
2+
3+
expected_results = {
4+
"K64F": {
5+
"desc": "test feature collisions",
6+
"exception_msg": "Configuration conflict. Feature IPV4 both added and removed."
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib1",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["IPV6"]
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib2",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["UVISOR"]
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"features_add": ["IPV4"]
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing if features can enable other features
2+
3+
expected_results = {
4+
"K64F": {
5+
"desc": "test recursive features",
6+
"expected_features": ["IPV4", "IPV6", "UVISOR"]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib1",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["IPV6"]
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "lib2",
3+
"target_overrides": {
4+
"*": {
5+
"features_add": ["UVISOR"]
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"features": ["IPV4", "IPV6"]
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing if feature collisions are detected accross recursive features
2+
3+
expected_results = {
4+
"K64F": {
5+
"desc": "test recursive feature collisions",
6+
"exception_msg": "Configuration conflict. Feature UVISOR both added and removed."
7+
}
8+
}

0 commit comments

Comments
 (0)