Skip to content

Commit f65f141

Browse files
Merge pull request #731 from OPpuolitaival/icetea
icetea support
2 parents c30230f + d4e3f78 commit f65f141

File tree

1 file changed

+98
-20
lines changed

1 file changed

+98
-20
lines changed

mbed/mbed.py

Lines changed: 98 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'
@@ -2596,26 +2604,48 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
25962604
@subcommand('test',
25972605
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
25982606
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2599-
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'),
26002609
dict(name='--run-list', dest='run_list', action='store_true', help='List all built tests that can be ran'),
26012610
dict(name='--compile', dest='compile_only', action='store_true', help='Only compile tests'),
26022611
dict(name='--run', dest='run_only', action='store_true', help='Only run tests'),
2603-
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)'),
26042614
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
26052615
dict(name='--build', help='Build directory. Default: build/'),
2606-
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'),
26072618
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
26082619
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)"),
26092620
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\""),
26102621
dict(name='--test-config', dest="test_config", help="Path or mbed OS keyword of a test configuration file. Example: ethernet, odin_wifi, or path/to/config.json"),
2622+
dict(name='--build-data', dest="build_data", default=None, help="Dump build_data to this file"),
2623+
dict(name=['--greentea'], dest="greentea", action='store_true', default=False, help="Run Greentea tests"),
2624+
dict(name=['--icetea'], dest="icetea", action='store_true', default=False,
2625+
help="Run Icetea tests. If used without --greentea flag then run only icetea tests."),
26112626
help='Find, build and run tests',
26122627
description="Find, build, and run tests in a program and libraries")
2613-
def test_(toolchain=None, target=None, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None):
2628+
def test_(toolchain=None, target=None, compile_list=False, run_list=False, compile_only=False, run_only=False,
2629+
tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, build_data=None,
2630+
app_config=None, test_config=None, greentea=None, icetea=None):
2631+
2632+
# Default behaviour is to run only greentea tests
2633+
if not (greentea or icetea):
2634+
greentea = True
2635+
icetea = False
2636+
26142637
# Gather remaining arguments
26152638
args = remainder
26162639
# Find the root of the program
26172640
program = Program(getcwd(), True)
26182641
program.check_requirements(True)
2642+
# Check if current Mbed OS support icetea
2643+
icetea_supported = program.requirements_contains('icetea')
2644+
2645+
# Disable icetea if not supported
2646+
if not icetea_supported:
2647+
icetea = False
2648+
26192649
# Save original working directory
26202650
orig_path = getcwd()
26212651

@@ -2625,6 +2655,11 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26252655
tools_dir = program.get_tools()
26262656
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
26272657

2658+
icetea_command_base = [python_cmd, '-u', os.path.join(tools_dir, 'run_icetea.py')] \
2659+
+ (['-m', target, '-t', tchain]) \
2660+
+ (['-n', tests_by_name] if tests_by_name else []) \
2661+
+ (['-v'] if verbose else [])
2662+
26282663
# Prepare environment variables
26292664
env = program.get_env()
26302665

@@ -2646,7 +2681,15 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26462681
# Create the path to the test spec file
26472682
test_spec = os.path.join(build_path, 'test_spec.json')
26482683

2649-
if compile_list:
2684+
if build_data:
2685+
# Preserve path to given build data
2686+
build_data = os.path.relpath(os.path.join(orig_path, build_data), program.path)
2687+
elif icetea_supported:
2688+
# Build data needed only if icetea is supported
2689+
# Create the path to the test build data file
2690+
build_data = os.path.join(build_path, 'build_data.json')
2691+
2692+
if compile_list and greentea:
26502693
popen([python_cmd, '-u', os.path.join(tools_dir, 'test.py'), '--list']
26512694
+ list(chain.from_iterable(list(zip(repeat('--profile'), profile or []))))
26522695
+ ['-t', tchain, '-m', target]
@@ -2655,10 +2698,28 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26552698
+ (['-v'] if verbose else [])
26562699
+ (['--app-config', app_config] if app_config else [])
26572700
+ (['--test-config', test_config] if test_config else [])
2701+
+ (['--greentea'] if icetea_supported and greentea else [])
26582702
+ args,
26592703
env=env)
26602704

2705+
if compile_list and icetea:
2706+
popen(icetea_command_base + ['--compile-list'])
2707+
26612708
if compile_only or build_and_run_tests:
2709+
2710+
# Add icetea binaries in compile list
2711+
tests_by_name_temp = tests_by_name if tests_by_name else ''
2712+
if icetea:
2713+
proc = popen(icetea_command_base + ['--application-list'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
2714+
stderr=subprocess.STDOUT)
2715+
applications_to_add = proc.stdout.read()
2716+
# Filter right row in case that debugger print something there
2717+
if applications_to_add and 'TEST_APPS-' in applications_to_add:
2718+
applications_to_add = list(filter(lambda x: 'TEST_APPS-' in x, applications_to_add.split('\n')))[0]
2719+
if tests_by_name_temp:
2720+
tests_by_name_temp += ','
2721+
tests_by_name_temp += applications_to_add
2722+
26622723
# If the user hasn't supplied a build directory, ignore the default build directory
26632724
if not build:
26642725
program.ignore_build_dir()
@@ -2671,26 +2732,43 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26712732
+ list(chain.from_iterable(zip(repeat('--source'), source)))
26722733
+ ['--build', build_path]
26732734
+ ['--test-spec', test_spec]
2674-
+ (['-n', tests_by_name] if tests_by_name else [])
2735+
+ (['--build-data', build_data] if build_data else [])
2736+
+ (['-n', tests_by_name_temp] if tests_by_name_temp else [])
26752737
+ (['-v'] if verbose else [])
26762738
+ (['--app-config', app_config] if app_config else [])
26772739
+ (['--test-config', test_config] if test_config else [])
2740+
+ (['--icetea'] if icetea_supported and icetea else [])
2741+
+ (['--greentea'] if icetea_supported and greentea else [])
26782742
+ args,
26792743
env=env)
26802744

2681-
if run_list:
2682-
popen(['mbedgt', '--test-spec', test_spec, '--list']
2683-
+ (['-n', tests_by_name] if tests_by_name else [])
2684-
+ (['-V'] if verbose else [])
2685-
+ args,
2686-
env=env)
2687-
2688-
if run_only or build_and_run_tests:
2689-
popen(['mbedgt', '--test-spec', test_spec]
2690-
+ (['-n', tests_by_name] if tests_by_name else [])
2691-
+ (['-V'] if verbose else [])
2692-
+ args,
2693-
env=env)
2745+
# Greentea tests
2746+
if greentea:
2747+
if run_list:
2748+
popen(['mbedgt', '--test-spec', test_spec, '--list']
2749+
+ (['-n', tests_by_name] if tests_by_name else [])
2750+
+ (['-V'] if verbose else [])
2751+
+ args,
2752+
env=env)
2753+
2754+
if run_only or build_and_run_tests:
2755+
popen(['mbedgt', '--test-spec', test_spec]
2756+
+ (['-n', tests_by_name] if tests_by_name else [])
2757+
+ (['-V'] if verbose else [])
2758+
+ args,
2759+
env=env)
2760+
2761+
# Icetea tests
2762+
if icetea:
2763+
icetea_command = icetea_command_base \
2764+
+ ['--build-data', build_data] \
2765+
+ ['--test-suite', os.path.join(build_path, 'test_suite.json')]
2766+
2767+
if run_list:
2768+
popen(icetea_command + ['--run-list'])
2769+
2770+
if run_only or build_and_run_tests:
2771+
popen(icetea_command)
26942772

26952773
program.set_defaults(target=target, toolchain=tchain)
26962774

0 commit comments

Comments
 (0)