Skip to content

Commit 71d7970

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
fix issues base on the review
1 parent b2611fb commit 71d7970

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

tools/test/examples/examples_lib.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from tools.export import EXPORTERS
3939
from tools.project import EXPORTER_ALIASES
4040
from tools.toolchains import TOOLCHAINS
41+
from tools.utils import write_json_to_file
4142

4243
SUPPORTED_TOOLCHAINS = list(TOOLCHAINS - set(u'uARM'))
4344
SUPPORTED_IDES = [exp for exp in EXPORTERS.keys() + EXPORTER_ALIASES.keys()
@@ -382,7 +383,7 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples):
382383
successes = []
383384
compiled = True
384385
pass_status = True
385-
if example.has_key('test') and example.has_key('baud_rate') and example.has_key('compare_log'):
386+
if example.has_key('test') and example['test'] and example.has_key('baud_rate') and example.has_key('compare_log'):
386387
test_example = True
387388
else:
388389
test_example = False
@@ -414,16 +415,15 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples):
414415
if image:
415416
image_info = [{"binary_type": "bootable","path": normpath(join(name,image)),"compare_log":log}]
416417
else:
417-
print ("Warning: could not found built image for example %s" % name)
418+
print ("Warning: could not find built image for example %s" % name)
418419

419420
example_summary = "{} {} {}".format(name, target, toolchain)
420421
if proc.returncode:
421422
failures.append(example_summary)
422423
else:
423-
successes.append(example_summary)
424424
if test_example:
425425
test_group = "{}-{}-{}".format(target, toolchain, example['baud_rate'])
426-
if example['test'] and image:
426+
if image:
427427
if not test_json['builds'].has_key(test_group):
428428
test_json['builds'][test_group] = {
429429
"platform":target ,
@@ -432,9 +432,14 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples):
432432
"baud_rate": int(example['baud_rate']),
433433
"tests":{} }
434434
test_json['builds'][test_group]['tests'][name]={"binaries":image_info}
435+
test_status = "TEST_ON"
436+
else:
437+
test_status = "NO_IMAGE"
435438
else:
436439
print("Warning: Test for %s will not be generated." % name)
437-
print("One or more of 'test' 'baud_rate' and 'compare_log' keys are missing from the json file\n")
440+
print("One or more of 'test', 'baud_rate', and 'compare_log' keys are missing from the example config json file\n")
441+
test_status = "TEST_OFF"
442+
successes.append(example_summary + " " + test_status)
438443

439444
os.chdir("..")
440445

@@ -446,7 +451,7 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples):
446451

447452
results[example['name']] = [compiled, pass_status, successes, failures]
448453

449-
save_test_spec(test_json)
454+
write_json_to_file(test_json, "test_spec.json")
450455
return results
451456

452457

@@ -475,15 +480,9 @@ def update_mbedos_version(config, tag, examples):
475480
return result
476481

477482
return 0
478-
479-
def save_test_spec(json_spec, name="test_spec.json"):
480-
"""save the given json data to test_spec.json"""
481-
print ("Dumping json test_specs file {}".format(name))
482-
with open(name, 'w') as outfile:
483-
json.dump(json_spec, outfile , indent=4)
484-
483+
485484
def fetch_output_image(output):
486-
"""find the mbed build image from thet last 5 lines of a given log """
485+
"""Find the build image from the last 5 lines of a given log"""
487486
lines = output.splitlines()
488487
for index in range(-1,-6,-1):
489488
if lines[index].startswith("Image:"):

0 commit comments

Comments
 (0)