Skip to content

Commit c3c89b9

Browse files
committed
Merge branch 'master' into unittests
2 parents 27c1de5 + f65f141 commit c3c89b9

File tree

2 files changed

+153
-22
lines changed

2 files changed

+153
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Methods for configuring toolchains that appear earlier in the above list overrid
346346
Edit `mbed_settings.py` to set your toolchain:
347347

348348
* To use [Arm Compiler 5](https://developer.arm.com/products/software-development-tools/compilers/arm-compiler-5/downloads), set `ARM_PATH` to the *base* directory of your Arm Compiler installation (example: C:\Program Files\ARM\armcc5.06). Use version 5.06 of Arm Compiler 5.
349-
* To use [Arm Compiler 6](https://developer.arm.com/products/software-development-tools/compilers/arm-compiler-6/downloads), set `ARMC6_PATH` to the *binary* directory of your Arm Compiler installation (example: C:\Program Files\ARM\armcc6.8\bin). Use version 6.8 of Arm Compiler 6.
349+
* To use [Arm Compiler 6](https://developer.arm.com/products/software-development-tools/compilers/arm-compiler-6/downloads), set `ARMC6_PATH` to the *binary* directory of your Arm Compiler installation (example: C:\Program Files\ARM\armcc6.10\bin). Use version 6.10 of Arm Compiler 6.
350350
* To use the [GNU Arm Embedded toolchain (GCC) version 6](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads), set `GCC_ARM_PATH` to the *binary* directory of your GCC Arm installation (example: C:\Program Files\GNU Tools ARM Embedded\6 2017q2\bin). Use version 6 of GCC Arm Embedded; version 5.0 or any older version might be incompatible with the tools.
351351
* To use the [IAR EWARM toolchain](https://www.iar.com/iar-embedded-workbench/#!?architecture=ARM), set `IAR_PATH` to the *base* directory of your IAR installation (example: C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.5\arm). Use versions 7.70 to 7.80.x of the IAR EWARM; newer (or older) versions might be incompatible with the tools.
352352

@@ -540,7 +540,7 @@ For example, to export to uVision, run:
540540
$ mbed export -i uvision -m K64F
541541
```
542542

543-
Mbed CLI creates a `.uvprojx` file in the projectfiles/uvision folder. You can open the project file with uVision.
543+
Mbed CLI creates a `.uvprojx` file in the root project directory. You can open the project file with uVision.
544544

545545
### Serial terminal
546546

mbed/mbed.py

Lines changed: 151 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def hide_progress(max_width=80):
218218
class ProcessException(Exception):
219219
pass
220220

221-
def popen(command, stdin=None, **kwargs):
221+
222+
def popen(command, **kwargs):
222223
# print for debugging
223224
info("Exec \"%s\" in \"%s\"" % (' '.join(command), getcwd()))
224225
proc = None
@@ -234,6 +235,7 @@ def popen(command, stdin=None, **kwargs):
234235

235236
if proc and proc.wait() != 0:
236237
raise ProcessException(proc.returncode, command[0], ' '.join(command), getcwd())
238+
return proc
237239

238240
def pquery(command, output_callback=None, stdin=None, **kwargs):
239241
if very_verbose:
@@ -1480,6 +1482,12 @@ def _find_file_paths(self, paths, fl):
14801482
return os.path.join(path)
14811483
return None
14821484

1485+
def requirements_contains(self, library_name):
1486+
req_path = self.get_requirements() or self.path
1487+
req_file = 'requirements.txt'
1488+
with open(os.path.join(req_path, req_file), 'r') as f:
1489+
return library_name in f.read()
1490+
14831491
def check_requirements(self, show_warning=False):
14841492
req_path = self.get_requirements() or self.path
14851493
req_file = 'requirements.txt'
@@ -1576,6 +1584,10 @@ def get_env(self):
15761584
for c in compilers:
15771585
if self.get_cfg(c+'_PATH'):
15781586
env['MBED_'+c+'_PATH'] = self.get_cfg(c+'_PATH')
1587+
config_options = ['COLOR', 'CLOUD_SDK_API_KEY', 'CLOUD_SDK_HOST']
1588+
for opt in config_options:
1589+
if self.get_cfg(opt):
1590+
env['MBED_' + opt] = self.get_cfg(opt)
15791591

15801592
return env
15811593

@@ -2592,14 +2604,17 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
25922604
@subcommand('test',
25932605
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
25942606
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2595-
dict(name='--compile-list', dest='compile_list', action='store_true', help='List all tests that can be built'),
2607+
dict(name='--compile-list', dest='compile_list', action='store_true',
2608+
help='List all tests that can be built'),
25962609
dict(name='--run-list', dest='run_list', action='store_true', help='List all built tests that can be ran'),
25972610
dict(name='--compile', dest='compile_only', action='store_true', help='Only compile tests'),
25982611
dict(name='--run', dest='run_only', action='store_true', help='Only run tests'),
2599-
dict(name=['-n', '--tests-by-name'], dest='tests_by_name', help='Limit the tests to a list (ex. test1,test2,test3)'),
2612+
dict(name=['-n', '--tests-by-name'], dest='tests_by_name',
2613+
help='Limit the tests to a list (ex. test1,test2,test3)'),
26002614
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
26012615
dict(name='--build', help='Build directory. Default: build/'),
2602-
dict(name=['--profile'], action='append', help='Path of a build profile configuration file. Example: mbed-os/tools/profiles/debug.json'),
2616+
dict(name=['--profile'], action='append',
2617+
help='Path of a build profile configuration file. Example: mbed-os/tools/profiles/debug.json'),
26032618
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
26042619
dict(name='--test-spec', dest="test_spec", help="Path used for the test spec file used when building and running tests (the default path is the build directory)"),
26052620
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\""),
@@ -2610,18 +2625,36 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
26102625
dict(name='--new', help='generate files for a new unit test', metavar="FILEPATH"),
26112626
dict(name=['-r', '--regex'], help='Run unit tests matching regular expression'),
26122627
dict(name=['--unittests'], action="store_true", help='Run only unit tests'),
2628+
dict(name='--build-data', dest="build_data", default=None, help="Dump build_data to this file"),
2629+
dict(name=['--greentea'], dest="greentea", action='store_true', default=False, help="Run Greentea tests"),
2630+
dict(name=['--icetea'], dest="icetea", action='store_true', default=False,
2631+
help="Run Icetea tests. If used without --greentea flag then run only icetea tests."),
26132632
help='Find, build and run tests',
26142633
description="Find, build, and run tests in a program and libraries")
26152634
def test_(toolchain=None, target=None, compile_list=False, run_list=False,
26162635
compile_only=False, run_only=False, tests_by_name=None, source=False,
26172636
profile=False, build=False, clean=False, test_spec=None,
26182637
app_config=None, test_config=None, coverage=None, make_program=None,
2619-
new=None, generator=None, regex=None, unittests=None):
2638+
new=None, generator=None, regex=None, unittests=None,
2639+
build_data=None, greentea=None, icetea=None):
2640+
# Default behaviour is to run only greentea tests
2641+
if not (greentea or icetea or unittests):
2642+
greentea = True
2643+
icetea = False
2644+
unittests = False
2645+
26202646
# Gather remaining arguments
26212647
args = remainder
26222648
# Find the root of the program
26232649
program = Program(getcwd(), True)
26242650
program.check_requirements(True)
2651+
# Check if current Mbed OS support icetea
2652+
icetea_supported = program.requirements_contains('icetea')
2653+
2654+
# Disable icetea if not supported
2655+
if not icetea_supported:
2656+
icetea = False
2657+
26252658
# Save original working directory
26262659
orig_path = getcwd()
26272660

@@ -2631,6 +2664,11 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
26312664
tools_dir = program.get_tools()
26322665
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
26332666

2667+
icetea_command_base = [python_cmd, '-u', os.path.join(tools_dir, 'run_icetea.py')] \
2668+
+ (['-m', target, '-t', tchain]) \
2669+
+ (['-n', tests_by_name] if tests_by_name else []) \
2670+
+ (['-v'] if verbose else [])
2671+
26342672
# Prepare environment variables
26352673
env = program.get_env()
26362674

@@ -2683,7 +2721,15 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
26832721
# Create the path to the test spec file
26842722
test_spec = os.path.join(build_path, 'test_spec.json')
26852723

2686-
if compile_list:
2724+
if build_data:
2725+
# Preserve path to given build data
2726+
build_data = os.path.relpath(os.path.join(orig_path, build_data), program.path)
2727+
elif icetea_supported:
2728+
# Build data needed only if icetea is supported
2729+
# Create the path to the test build data file
2730+
build_data = os.path.join(build_path, 'build_data.json')
2731+
2732+
if compile_list and greentea:
26872733
popen([python_cmd, '-u', os.path.join(tools_dir, 'test.py'), '--list']
26882734
+ list(chain.from_iterable(list(zip(repeat('--profile'), profile or []))))
26892735
+ ['-t', tchain, '-m', target]
@@ -2692,10 +2738,28 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
26922738
+ (['-v'] if verbose else [])
26932739
+ (['--app-config', app_config] if app_config else [])
26942740
+ (['--test-config', test_config] if test_config else [])
2741+
+ (['--greentea'] if icetea_supported and greentea else [])
26952742
+ args,
26962743
env=env)
26972744

2745+
if compile_list and icetea:
2746+
popen(icetea_command_base + ['--compile-list'])
2747+
26982748
if compile_only or build_and_run_tests:
2749+
2750+
# Add icetea binaries in compile list
2751+
tests_by_name_temp = tests_by_name if tests_by_name else ''
2752+
if icetea:
2753+
proc = popen(icetea_command_base + ['--application-list'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
2754+
stderr=subprocess.STDOUT)
2755+
applications_to_add = proc.stdout.read()
2756+
# Filter right row in case that debugger print something there
2757+
if applications_to_add and 'TEST_APPS-' in applications_to_add:
2758+
applications_to_add = list(filter(lambda x: 'TEST_APPS-' in x, applications_to_add.split('\n')))[0]
2759+
if tests_by_name_temp:
2760+
tests_by_name_temp += ','
2761+
tests_by_name_temp += applications_to_add
2762+
26992763
# If the user hasn't supplied a build directory, ignore the default build directory
27002764
if not build:
27012765
program.ignore_build_dir()
@@ -2708,30 +2772,97 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
27082772
+ list(chain.from_iterable(zip(repeat('--source'), source)))
27092773
+ ['--build', build_path]
27102774
+ ['--test-spec', test_spec]
2711-
+ (['-n', tests_by_name] if tests_by_name else [])
2775+
+ (['--build-data', build_data] if build_data else [])
2776+
+ (['-n', tests_by_name_temp] if tests_by_name_temp else [])
27122777
+ (['-v'] if verbose else [])
27132778
+ (['--app-config', app_config] if app_config else [])
27142779
+ (['--test-config', test_config] if test_config else [])
2780+
+ (['--icetea'] if icetea_supported and icetea else [])
2781+
+ (['--greentea'] if icetea_supported and greentea else [])
27152782
+ args,
27162783
env=env)
27172784

2718-
if run_list:
2719-
popen(['mbedgt', '--test-spec', test_spec, '--list']
2720-
+ (['-n', tests_by_name] if tests_by_name else [])
2721-
+ (['-V'] if verbose else [])
2722-
+ args,
2723-
env=env)
2785+
# Greentea tests
2786+
if greentea:
2787+
if run_list:
2788+
popen(['mbedgt', '--test-spec', test_spec, '--list']
2789+
+ (['-n', tests_by_name] if tests_by_name else [])
2790+
+ (['-V'] if verbose else [])
2791+
+ args,
2792+
env=env)
2793+
2794+
if run_only or build_and_run_tests:
2795+
popen(['mbedgt', '--test-spec', test_spec]
2796+
+ (['-n', tests_by_name] if tests_by_name else [])
2797+
+ (['-V'] if verbose else [])
2798+
+ args,
2799+
env=env)
2800+
2801+
# Icetea tests
2802+
if icetea:
2803+
icetea_command = icetea_command_base \
2804+
+ ['--build-data', build_data] \
2805+
+ ['--test-suite', os.path.join(build_path, 'test_suite.json')]
2806+
2807+
if run_list:
2808+
popen(icetea_command + ['--run-list'])
2809+
2810+
if run_only or build_and_run_tests:
2811+
popen(icetea_command)
27242812

2725-
if run_only or build_and_run_tests:
2726-
popen(['mbedgt', '--test-spec', test_spec]
2727-
+ (['-n', tests_by_name] if tests_by_name else [])
2728-
+ (['-V'] if verbose else [])
2729-
+ args,
2730-
env=env)
2813+
program.set_defaults(target=target, toolchain=tchain)
27312814

27322815

2733-
program.set_defaults(target=target, toolchain=tchain)
2816+
# device management commands
2817+
@subcommand('device-management',
2818+
dict(name=['-t', '--toolchain'], help='Toolchain used for mbed compile'),
2819+
dict(name=['-m', '--target'], help='Target used for compile for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2820+
dict(name=['--profile'], help=""),
2821+
dict(name='--build', help='Build directory. Default: build/'),
2822+
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
2823+
help='device management supcommand',
2824+
hidden_aliases=['dev-mgmt', 'dm'],
2825+
description=("Manage Device with Pelion"))
2826+
def dev_mgmt(toolchain=None, target=None, source=False, profile=False, build=False):
2827+
orig_path = getcwd()
2828+
program = Program(getcwd(), True)
2829+
program.check_requirements(True)
2830+
with cd(program.path):
2831+
tools_dir = program.get_tools()
27342832

2833+
script = os.path.join(tools_dir, 'device_management.py')
2834+
if not os.path.exists(script):
2835+
error('device management is not supported by this version of Mbed OS. Please upgrade.')
2836+
2837+
2838+
target = target or program.get_cfg("TARGET")
2839+
toolchain = toolchain or program.get_cfg("TOOLCHAIN")
2840+
2841+
if build:
2842+
build_path = build
2843+
elif (not build) and target and toolchain:
2844+
build_path = os.path.join(
2845+
os.path.relpath(program.path, orig_path),
2846+
program.build_dir,
2847+
target.upper(),
2848+
toolchain.upper()
2849+
)
2850+
build_path = _safe_append_profile_to_build_path(build_path, profile)
2851+
else:
2852+
build_path = None
2853+
2854+
args = remainder
2855+
if args[0] in ('update', 'create'):
2856+
args += (['--toolchain', toolchain] if toolchain else [])
2857+
args += (['--mcu', target] if target else [])
2858+
args += (['--build', build_path] if build_path else [])
2859+
env = program.get_env()
2860+
if "MBED_CLOUD_SDK_HOST" not in env:
2861+
env["MBED_CLOUD_SDK_HOST"] = "https://api.us-east-1.mbedcloud.com"
2862+
popen([python_cmd, '-u', script]
2863+
+ args
2864+
+ list(chain.from_iterable(zip(repeat('--source'), source or []))),
2865+
env=env)
27352866

27362867
# Export command
27372868
@subcommand('export',

0 commit comments

Comments
 (0)