Skip to content

Commit 2d67c67

Browse files
Qinghao Shihugueskamba
authored andcommitted
TEST: update example scripts for cmake
1 parent 062bb5f commit 2d67c67

File tree

3 files changed

+177
-28
lines changed

3 files changed

+177
-28
lines changed

tools/test/examples/examples.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ def parse_args():
8080
official_target_names, "MCU")),
8181
default=official_target_names)
8282

83-
compile_cmd.add_argument(
84-
"--profiles",
85-
nargs='+',
86-
metavar="profile",
87-
help="build profile(s)")
83+
compile_cmd.add_argument("--profiles",
84+
nargs='+',
85+
metavar="profile",
86+
help="build profile(s)")
8887

8988
compile_cmd.add_argument("-j", "--jobs",
9089
dest='jobs',
@@ -160,7 +159,7 @@ def do_deploy(_, config, examples):
160159

161160
def do_compile(args, config, examples):
162161
"""Do the compile step"""
163-
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profiles, args.verbose, examples, args.jobs)
162+
results = lib.compile_repos(config, args.toolchains, args.mcu, args.profiles, args.verbose, examples, args.cmake, args.jobs)
164163
failures = lib.get_build_summary(results)
165164
return failures
166165

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"examples": [
3+
{
4+
"name": "mbed-os-example-blinky",
5+
"github": "https://github.com/ARMmbed/mbed-os-example-blinky",
6+
"sub-repo-example": false,
7+
"subs": [],
8+
"features" : [],
9+
"targets" : [],
10+
"toolchains" : [],
11+
"exporters": [],
12+
"compile" : true,
13+
"export": true,
14+
"test" : false,
15+
"baud_rate": 9600,
16+
"auto-update" : true
17+
},
18+
{
19+
"name": "mbed-os-example-sockets",
20+
"github":"https://github.com/ARMmbed/mbed-os-example-sockets",
21+
"sub-repo-example": false,
22+
"subs": [],
23+
"features" : [],
24+
"targets" : ["K64F", "K66F"],
25+
"toolchains" : [],
26+
"exporters": [],
27+
"compile" : true,
28+
"export": true,
29+
"test" : true,
30+
"baud_rate": 9600,
31+
"compare_log": ["mbed-os-example-sockets/tests/sockets.log"],
32+
"auto-update" : true
33+
},
34+
{
35+
"name": "mbed-os-example-cellular",
36+
"github":"https://github.com/ARMmbed/mbed-os-example-cellular",
37+
"sub-repo-example": false,
38+
"subs": [],
39+
"features" : [],
40+
"targets" : ["WIO_3G"],
41+
"toolchains" : [],
42+
"exporters": [],
43+
"compile" : true,
44+
"export": true,
45+
"test" : false,
46+
"auto-update" : true
47+
},
48+
{
49+
"name": "mbed-os-example-lorawan",
50+
"github":"https://github.com/ARMmbed/mbed-os-example-lorawan",
51+
"sub-repo-example": false,
52+
"subs": [],
53+
"features" : [],
54+
"targets" : ["K64F"],
55+
"toolchains" : [],
56+
"exporters": [],
57+
"compile" : true,
58+
"export": false,
59+
"test" : false,
60+
"auto-update" : true
61+
},
62+
{
63+
"name": "mbed-os-example-devicekey",
64+
"github":"https://github.com/ARMmbed/mbed-os-example-devicekey",
65+
"sub-repo-example": false,
66+
"subs": [],
67+
"features" : [],
68+
"targets" : ["K66F"],
69+
"toolchains" : [],
70+
"exporters": [],
71+
"compile" : true,
72+
"export": true,
73+
"test" : true,
74+
"baud_rate": 9600,
75+
"compare_log": ["mbed-os-example-devicekey/tests/devicekey.log"],
76+
"auto-update" : true
77+
},
78+
{
79+
"name": "mbed-os-example-mbed-crypto",
80+
"github":"https://github.com/ARMmbed/mbed-os-example-mbed-crypto",
81+
"sub-repo-example": true,
82+
"subs": ["getting-started"],
83+
"features" : [],
84+
"targets" : ["K64F"],
85+
"toolchains" : [],
86+
"exporters": [],
87+
"compile" : true,
88+
"export": true,
89+
"test" : true,
90+
"baud_rate": 9600,
91+
"compare_log": ["mbed-os-example-mbed-crypto/tests/getting-started.log"],
92+
"auto-update" : true
93+
},
94+
{
95+
"name": "mbed-os-example-nfc",
96+
"github": "https://github.com/ARMmbed/mbed-os-example-nfc",
97+
"sub-repo-example": true,
98+
"subs": [
99+
"NFC_EEPROM",
100+
"NFC_SmartPoster"
101+
],
102+
"features" : [],
103+
"targets" : ["NUCLEO_F401RE"],
104+
"toolchains" : [],
105+
"exporters": [],
106+
"compile" : true,
107+
"export": true,
108+
"test" : true,
109+
"baud_rate": 9600,
110+
"compare_log": [
111+
"mbed-os-example-nfc/tests/EEPROM.log",
112+
"mbed-os-example-nfc/tests/SmartPoster_noShield.log"
113+
],
114+
"auto-update" : true
115+
},
116+
{
117+
"name": "mbed-os-example-kvstore",
118+
"github":"https://github.com/ARMmbed/mbed-os-example-kvstore",
119+
"sub-repo-example": false,
120+
"subs": [],
121+
"features" : [],
122+
"targets" : ["K64F", "DISCO_L475VG_IOT01A"],
123+
"toolchains" : [],
124+
"exporters": [],
125+
"compile" : true,
126+
"export": true,
127+
"test" : true,
128+
"baud_rate": 9600,
129+
"compare_log": ["mbed-os-example-kvstore/tests/kvstore.log"],
130+
"auto-update" : true
131+
}
132+
]
133+
}

tools/test/examples/examples_lib.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def export_repos(config, ides, targets, exp_filter):
329329
return results
330330

331331

332-
def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jobs=0):
332+
def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, cmake=False ,jobs=0):
333333
"""Compiles combinations of example programs, targets and compile chains.
334334
335335
The results are returned in a [key: value] dictionary format:
@@ -382,27 +382,36 @@ def compile_repos(config, toolchains, targets, profiles, verbose, exp_filter, jo
382382
summary_string = "%s %s %s" % (name, target, toolchain)
383383
logging.info("Compiling %s" % summary_string)
384384

385-
build_command = ["mbed-cli", "compile", "-t", toolchain, "-m", target, "-j", str(jobs)] + (['-vv'] if verbose else [])
386-
if profiles:
387-
for profile in profiles:
388-
build_command.extend(["--profile", profile])
389-
390-
logging.info("Executing command '%s'..." % " ".join(build_command))
391-
proc = subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
392-
393-
std_out, std_err = proc.communicate()
394-
std_out = std_out.decode()
395-
std_err = std_err.decode()
396-
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
397-
398-
if proc.returncode:
399-
failures.append(example_summary)
385+
if cmake:
386+
build_command_seq = ["mbed-tools configure -t {} -m {}".format(toolchain,target), "cmake -S . -B CMAKE_BUILD -GNinja", "cmake --build CMAKE_BUILD"]
400387
else:
388+
build_command_seq = ["mbed-cli compile -t {} -m {} -j {} {}".format(toolchain, target, str(jobs), '-vv' if verbose else '') ]
389+
if profiles:
390+
for profile in profiles:
391+
build_command_seq[0] += " --profile {}".format(profile)
392+
393+
failed_flag = False
394+
for build_command in build_command_seq:
395+
logging.info("Executing command '%s'..." % build_command)
396+
proc = subprocess.Popen(build_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
397+
398+
std_out, std_err = proc.communicate()
399+
std_out = std_out.decode()
400+
std_err = std_err.decode()
401+
print ("\n#### STDOUT ####\n%s\n#### STDERR ####\n%s\n#### End of STDOUT/STDERR ####\n" % (std_out,std_err))
402+
403+
if proc.returncode:
404+
failures.append(example_summary)
405+
failed_flag = True
406+
break
407+
408+
409+
if not failed_flag:
401410
if example['test']:
402411
log = example['compare_log'].pop(0)
403412
# example['compare_log'] is a list of log file/files, which matches each examples/sub-examples from same repo.
404413
# pop the log file out of list regardless the compilation for each example pass of fail
405-
image = fetch_output_image(std_out)
414+
image = fetch_output_image(std_out,cmake)
406415
if image:
407416
image_info = [{"binary_type": "bootable","path": normpath(join(name,image)),"compare_log":log}]
408417
test_group = "{}-{}-{}".format(target, toolchain, example['baud_rate'])
@@ -484,17 +493,25 @@ def symlink_mbedos(config, path, exp_filter):
484493
else:
485494
logging.info("Creating Symbolic link '%s'->'mbed-os'" % path)
486495
os.symlink(path, "mbed-os")
496+
open('mbed-os.lib', 'a').close()
487497
os.chdir(CWD)
488498
return 0
489499

490-
def fetch_output_image(output):
500+
def fetch_output_image(output,cmake):
491501
"""Find the build image from the last 30 lines of a given log"""
492502
lines = output.splitlines()
493503
last_index = -31 if len(lines)>29 else (-1 - len(lines))
494504
for index in range(-1,last_index,-1):
495-
if lines[index].startswith("Image:"):
496-
image = lines[index][7:]
497-
if os.path.isfile(image):
498-
return image
505+
if cmake:
506+
if lines[index].startswith("-- built:") and lines[index].endswith(".bin"):
507+
image = lines[index][10:]
508+
print("IMAGE is " + image)
509+
if os.path.isfile(image):
510+
return os.path.relpath(image)
511+
else:
512+
if lines[index].startswith("Image:"):
513+
image = lines[index][7:]
514+
if os.path.isfile(image):
515+
return image
499516
return False
500517

0 commit comments

Comments
 (0)