Skip to content

Commit 6876362

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
EXAMPLES: update build_repo function
1 parent 3f0add7 commit 6876362

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

tools/test/examples/examples.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ def do_deploy(_, config, examples):
152152
def do_compile(args, config, examples):
153153
"""Do the compile step"""
154154
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profile, args.verbose, examples, args.jobs)
155-
lib.print_summary(results)
156-
failures = lib.get_num_failures(results)
157-
print("Number of failures = %d" % failures)
155+
failures = lib.get_build_summary(results)
158156
return failures
159157

160158
def do_update(args, config, examples):

tools/test/examples/examples_lib.py

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def export_repos(config, ides, targets, exp_filter):
316316
return results
317317

318318

319-
def compile_repos(config, toolchains, targets, profile, verbose, examples, jobs=0):
319+
def compile_repos(config, toolchains, targets, profile, verbose, exp_filter, jobs=0):
320320
"""Compiles combinations of example programs, targets and compile chains.
321321
322322
The results are returned in a [key: value] dictionary format:
@@ -337,68 +337,61 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples, jobs=
337337
targets - list of target names
338338
profile - build profile path or name if in default place
339339
verbose - enabling verbose
340-
examples - List of examples to be build
340+
exp_filter - List of exp_filter to be build
341341
jobs - Number of compile jobs
342342
343343
"""
344344
results = {}
345345
test_json = {"builds":{}}
346-
valid_examples = set(examples)
347346
base_path = os.getcwd()
348347
print("\nCompiling example repos....\n")
349348
for example in config['examples']:
350-
example_names = [basename(x['repo']) for x in get_repo_list(example)]
351-
common_examples = valid_examples.intersection(set(example_names))
352-
if not common_examples:
349+
if example['name'] not in exp_filter:
353350
continue
354351
failures = []
355352
successes = []
356353
compiled = True
357354
pass_status = True
358-
if 'test' in example and example['test'] and 'baud_rate' in example and 'compare_log'in example:
359-
test_example = True
360-
else:
361-
test_example = False
355+
if example['test']:
356+
if not ('baud_rate' in example and 'compare_log'in example):
357+
logging.warning("'baud_rate' or 'compare_log' keys are missing from config json file")
358+
example['test'] = False
362359
if example['compile']:
363-
for repo_info in get_repo_list(example):
364-
name = basename(repo_info['repo'])
360+
for name in get_sub_examples_list(example):
365361
os.chdir(name)
362+
logging.info("In folder '%s'" % name)
366363
# Check that the target, toolchain and features combinations are valid and return a
367364
# list of valid combinations to work through
368365
for target, toolchain in target_cross_toolchain(valid_choices(example['targets'], targets),
369366
valid_choices(example['toolchains'], toolchains),
370367
example['features']):
368+
example_summary = {"name" : name, "target" : target, "toolchain" : toolchain, "test": "UNSET"}
369+
summary_string = "%s %s %s" % (name, target, toolchain)
370+
logging.info("Compiling %s" % summary_string)
371371

372372
build_command = ["mbed-cli", "compile", "-t", toolchain, "-m", target, "-j", str(jobs)] + (['-vv'] if verbose else [])
373373
if profile:
374374
build_command.append("--profile")
375375
build_command.append(profile)
376376

377-
print("Compiling [%s] for [%s] with toolchain [%s]\n\n> %s" % (name, target, toolchain, " ".join(build_command)))
378-
377+
logging.info("Executing command '%s'..." % " ".join(build_command))
379378
proc = subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
380379

381380
std_out, std_err = proc.communicate()
382381
std_out = std_out.decode('utf-8')
383382
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
384383

385-
if test_example:
386-
log = example['compare_log'].pop(0)
387-
# example['compare_log'] is a list of log file/files, which matches each examples/sub-examples from same repo.
388-
# pop the log file out of list regardless the compilation for each example pass of fail
389-
image = fetch_output_image(std_out)
390-
if image:
391-
image_info = [{"binary_type": "bootable","path": normpath(join(name,image)),"compare_log":log}]
392-
else:
393-
print ("Warning: could not find built image for example %s" % name)
394-
395-
example_summary = "{} {} {}".format(name, target, toolchain)
396384
if proc.returncode:
397385
failures.append(example_summary)
398386
else:
399-
if test_example:
400-
test_group = "{}-{}-{}".format(target, toolchain, example['baud_rate'])
387+
if example['test']:
388+
log = example['compare_log'].pop(0)
389+
# example['compare_log'] is a list of log file/files, which matches each examples/sub-examples from same repo.
390+
# pop the log file out of list regardless the compilation for each example pass of fail
391+
image = fetch_output_image(std_out)
401392
if image:
393+
image_info = [{"binary_type": "bootable","path": normpath(join(name,image)),"compare_log":log}]
394+
test_group = "{}-{}-{}".format(target, toolchain, example['baud_rate'])
402395
if not test_group in test_json['builds']:
403396
test_json['builds'][test_group] = {
404397
"platform":target ,
@@ -407,16 +400,17 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples, jobs=
407400
"baud_rate": int(example['baud_rate']),
408401
"tests":{} }
409402
test_json['builds'][test_group]['tests'][name]={"binaries":image_info}
410-
test_status = "TEST_ON"
403+
example_summary["test"] = "TEST_ON"
404+
411405
else:
412-
test_status = "NO_IMAGE"
406+
logging.warning("could not find built image for example %s" % name)
407+
example_summary["test"] = "NO_IMAGE"
413408
else:
414-
print("Warning: Test for %s will not be generated." % name)
415-
print("One or more of 'test', 'baud_rate', and 'compare_log' keys are missing from the example config json file\n")
416-
test_status = "TEST_OFF"
417-
successes.append(example_summary + " " + test_status)
409+
logging.warning("Test for %s will not be generated." % name)
410+
example_summary["test"] = "TEST_OFF"
411+
successes.append(example_summary)
418412

419-
os.chdir("..")
413+
os.chdir(CWD)
420414

421415
# If there are any compilation failures for the example 'set' then the overall status is fail.
422416
if len(failures) > 0:
@@ -476,9 +470,9 @@ def symlink_mbedos(config, path, exp_filter):
476470
return 0
477471

478472
def fetch_output_image(output):
479-
"""Find the build image from the last 5 lines of a given log"""
473+
"""Find the build image from the last 30 lines of a given log"""
480474
lines = output.splitlines()
481-
last_index = -6 if len(lines)>4 else (-1 - len(lines))
475+
last_index = -31 if len(lines)>29 else (-1 - len(lines))
482476
for index in range(-1,last_index,-1):
483477
if lines[index].startswith("Image:"):
484478
image = lines[index][7:]

0 commit comments

Comments
 (0)