Skip to content

Commit e1da2d0

Browse files
author
Olli-Pekka Puolitaival
committed
icetea support
1 parent 59c57db commit e1da2d0

File tree

1 file changed

+94
-19
lines changed

1 file changed

+94
-19
lines changed

mbed/mbed.py

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import errno
4444
import ctypes
4545
from itertools import chain, repeat
46+
from urlparse import urlparse
4647
import zipfile
4748
import argparse
4849

@@ -218,7 +219,8 @@ def hide_progress(max_width=80):
218219
class ProcessException(Exception):
219220
pass
220221

221-
def popen(command, stdin=None, **kwargs):
222+
223+
def popen(command, **kwargs):
222224
# print for debugging
223225
info("Exec \"%s\" in \"%s\"" % (' '.join(command), getcwd()))
224226
proc = None
@@ -234,6 +236,7 @@ def popen(command, stdin=None, **kwargs):
234236

235237
if proc and proc.wait() != 0:
236238
raise ProcessException(proc.returncode, command[0], ' '.join(command), getcwd())
239+
return proc
237240

238241
def pquery(command, output_callback=None, stdin=None, **kwargs):
239242
if very_verbose:
@@ -1480,6 +1483,12 @@ def _find_file_paths(self, paths, fl):
14801483
return os.path.join(path)
14811484
return None
14821485

1486+
def requirements_contains(self, library_name):
1487+
req_path = self.get_requirements() or self.path
1488+
req_file = 'requirements.txt'
1489+
with open(os.path.join(req_path, req_file), 'r') as f:
1490+
return library_name in f.read()
1491+
14831492
def check_requirements(self, show_warning=False):
14841493
req_path = self.get_requirements() or self.path
14851494
req_file = 'requirements.txt'
@@ -2592,26 +2601,51 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
25922601
@subcommand('test',
25932602
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
25942603
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'),
2604+
dict(name='--compile-list', dest='compile_list', action='store_true',
2605+
help='List all tests that can be built'),
25962606
dict(name='--run-list', dest='run_list', action='store_true', help='List all built tests that can be ran'),
25972607
dict(name='--compile', dest='compile_only', action='store_true', help='Only compile tests'),
25982608
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)'),
2609+
dict(name=['-n', '--tests-by-name'], dest='tests_by_name',
2610+
help='Limit the tests to a list (ex. test1,test2,test3)'),
26002611
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
26012612
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'),
2613+
dict(name=['--profile'], action='append',
2614+
help='Path of a build profile configuration file. Example: mbed-os/tools/profiles/debug.json'),
26032615
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
26042616
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)"),
26052617
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\""),
26062618
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"),
2619+
dict(name='--build-data', dest="build_data", default=None, help="Dump build_data to this file"),
2620+
dict(name=['--greentea'], dest="greentea", action='store_true', default=False, help="Run Greentea tests"),
2621+
dict(name=['--icetea'], dest="icetea", action='store_true', default=False,
2622+
help="Run Icetea tests. If used without --greentea flag then run only icetea tests."),
26072623
help='Find, build and run tests',
26082624
description="Find, build, and run tests in a program and libraries")
2609-
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):
2625+
def test_(toolchain=None, target=None, compile_list=False, run_list=False, compile_only=False, run_only=False,
2626+
tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, build_data=None,
2627+
app_config=None, test_config=None, greentea=None, icetea=None):
2628+
2629+
# Default behaviour is to run only greentea tests
2630+
if not (greentea or icetea):
2631+
greentea = True
2632+
icetea = False
2633+
26102634
# Gather remaining arguments
26112635
args = remainder
26122636
# Find the root of the program
26132637
program = Program(getcwd(), True)
26142638
program.check_requirements(True)
2639+
# Check if current Mbed OS support icetea
2640+
icetea_supported = program.requirements_contains('icetea')
2641+
2642+
# TODO: Remove next line when publishing this commit
2643+
icetea_supported = True
2644+
2645+
# Disable icetea if not supported
2646+
if not icetea_supported:
2647+
icetea = False
2648+
26152649
# Save original working directory
26162650
orig_path = getcwd()
26172651

@@ -2621,6 +2655,11 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26212655
tools_dir = program.get_tools()
26222656
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
26232657

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+
26242663
# Prepare environment variables
26252664
env = program.get_env()
26262665

@@ -2642,7 +2681,14 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26422681
# Create the path to the test spec file
26432682
test_spec = os.path.join(build_path, 'test_spec.json')
26442683

2645-
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+
else:
2688+
# Create the path to the test build data file
2689+
build_data = os.path.join(build_path, 'build_data.json')
2690+
2691+
if compile_list and greentea:
26462692
popen([python_cmd, '-u', os.path.join(tools_dir, 'test.py'), '--list']
26472693
+ list(chain.from_iterable(list(zip(repeat('--profile'), profile or []))))
26482694
+ ['-t', tchain, '-m', target]
@@ -2651,10 +2697,28 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26512697
+ (['-v'] if verbose else [])
26522698
+ (['--app-config', app_config] if app_config else [])
26532699
+ (['--test-config', test_config] if test_config else [])
2700+
+ (['--greentea'] if icetea_supported and greentea else [])
26542701
+ args,
26552702
env=env)
26562703

2704+
if compile_list and icetea:
2705+
popen(icetea_command_base + ['--compile-list'])
2706+
26572707
if compile_only or build_and_run_tests:
2708+
2709+
# Add icetea binaries in compile list
2710+
tests_by_name_temp = tests_by_name if tests_by_name else ''
2711+
if icetea:
2712+
proc = popen(icetea_command_base + ['--application-list'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
2713+
stderr=subprocess.STDOUT)
2714+
applications_to_add = proc.stdout.read()
2715+
# Filter right row in case that debugger print something there
2716+
if applications_to_add and 'TEST_APPS-' in applications_to_add:
2717+
applications_to_add = filter(lambda x: 'TEST_APPS-' in x, applications_to_add.split('\n'))[0]
2718+
if tests_by_name_temp:
2719+
tests_by_name_temp += ','
2720+
tests_by_name_temp += applications_to_add
2721+
26582722
# If the user hasn't supplied a build directory, ignore the default build directory
26592723
if not build:
26602724
program.ignore_build_dir()
@@ -2667,26 +2731,37 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
26672731
+ list(chain.from_iterable(zip(repeat('--source'), source)))
26682732
+ ['--build', build_path]
26692733
+ ['--test-spec', test_spec]
2670-
+ (['-n', tests_by_name] if tests_by_name else [])
2734+
+ ['--build-data', build_data]
2735+
+ (['-n', tests_by_name_temp] if tests_by_name_temp else [])
26712736
+ (['-v'] if verbose else [])
26722737
+ (['--app-config', app_config] if app_config else [])
26732738
+ (['--test-config', test_config] if test_config else [])
2739+
+ (['--icetea'] if icetea_supported and icetea else [])
2740+
+ (['--greentea'] if icetea_supported and greentea else [])
26742741
+ args,
26752742
env=env)
26762743

2677-
if run_list:
2678-
popen(['mbedgt', '--test-spec', test_spec, '--list']
2679-
+ (['-n', tests_by_name] if tests_by_name else [])
2680-
+ (['-V'] if verbose else [])
2681-
+ args,
2682-
env=env)
2744+
# Greentea tests
2745+
if greentea:
2746+
greentea_command = ['mbedgt', '--test-spec', test_spec] \
2747+
+ (['-n', tests_by_name] if tests_by_name else []) \
2748+
+ (['-V'] if verbose else []) \
2749+
+ args
26832750

2684-
if run_only or build_and_run_tests:
2685-
popen(['mbedgt', '--test-spec', test_spec]
2686-
+ (['-n', tests_by_name] if tests_by_name else [])
2687-
+ (['-V'] if verbose else [])
2688-
+ args,
2689-
env=env)
2751+
if run_only or build_and_run_tests:
2752+
popen(greentea_command, env=env)
2753+
2754+
# Icetea tests
2755+
if icetea:
2756+
icetea_command = icetea_command_base \
2757+
+ ['--build-data', build_data] \
2758+
+ ['--test-suite', os.path.join(build_path, 'test_suite.json')]
2759+
2760+
if run_list:
2761+
popen(icetea_command + ['--run-list'])
2762+
2763+
if run_only or build_and_run_tests:
2764+
popen(icetea_command)
26902765

26912766
program.set_defaults(target=target, toolchain=tchain)
26922767

0 commit comments

Comments
 (0)