43
43
import errno
44
44
import ctypes
45
45
from itertools import chain , repeat
46
+ from urlparse import urlparse
46
47
import zipfile
47
48
import argparse
48
49
@@ -218,7 +219,8 @@ def hide_progress(max_width=80):
218
219
class ProcessException (Exception ):
219
220
pass
220
221
221
- def popen (command , stdin = None , ** kwargs ):
222
+
223
+ def popen (command , ** kwargs ):
222
224
# print for debugging
223
225
info ("Exec \" %s\" in \" %s\" " % (' ' .join (command ), getcwd ()))
224
226
proc = None
@@ -234,6 +236,7 @@ def popen(command, stdin=None, **kwargs):
234
236
235
237
if proc and proc .wait () != 0 :
236
238
raise ProcessException (proc .returncode , command [0 ], ' ' .join (command ), getcwd ())
239
+ return proc
237
240
238
241
def pquery (command , output_callback = None , stdin = None , ** kwargs ):
239
242
if very_verbose :
@@ -1480,6 +1483,12 @@ def _find_file_paths(self, paths, fl):
1480
1483
return os .path .join (path )
1481
1484
return None
1482
1485
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
+
1483
1492
def check_requirements (self , show_warning = False ):
1484
1493
req_path = self .get_requirements () or self .path
1485
1494
req_file = 'requirements.txt'
@@ -2592,26 +2601,51 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2592
2601
@subcommand ('test' ,
2593
2602
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2594
2603
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' ),
2596
2606
dict (name = '--run-list' , dest = 'run_list' , action = 'store_true' , help = 'List all built tests that can be ran' ),
2597
2607
dict (name = '--compile' , dest = 'compile_only' , action = 'store_true' , help = 'Only compile tests' ),
2598
2608
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)' ),
2600
2611
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
2601
2612
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' ),
2603
2615
dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
2604
2616
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)" ),
2605
2617
dict (name = '--app-config' , dest = "app_config" , help = "Path of an application configuration file. Default is to look for \" mbed_app.json\" " ),
2606
2618
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." ),
2607
2623
help = 'Find, build and run tests' ,
2608
2624
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
+
2610
2634
# Gather remaining arguments
2611
2635
args = remainder
2612
2636
# Find the root of the program
2613
2637
program = Program (getcwd (), True )
2614
2638
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
+
2615
2649
# Save original working directory
2616
2650
orig_path = getcwd ()
2617
2651
@@ -2621,6 +2655,11 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2621
2655
tools_dir = program .get_tools ()
2622
2656
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
2623
2657
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
+
2624
2663
# Prepare environment variables
2625
2664
env = program .get_env ()
2626
2665
@@ -2642,7 +2681,14 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2642
2681
# Create the path to the test spec file
2643
2682
test_spec = os .path .join (build_path , 'test_spec.json' )
2644
2683
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 :
2646
2692
popen ([python_cmd , '-u' , os .path .join (tools_dir , 'test.py' ), '--list' ]
2647
2693
+ list (chain .from_iterable (list (zip (repeat ('--profile' ), profile or []))))
2648
2694
+ ['-t' , tchain , '-m' , target ]
@@ -2651,10 +2697,28 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2651
2697
+ (['-v' ] if verbose else [])
2652
2698
+ (['--app-config' , app_config ] if app_config else [])
2653
2699
+ (['--test-config' , test_config ] if test_config else [])
2700
+ + (['--greentea' ] if icetea_supported and greentea else [])
2654
2701
+ args ,
2655
2702
env = env )
2656
2703
2704
+ if compile_list and icetea :
2705
+ popen (icetea_command_base + ['--compile-list' ])
2706
+
2657
2707
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
+
2658
2722
# If the user hasn't supplied a build directory, ignore the default build directory
2659
2723
if not build :
2660
2724
program .ignore_build_dir ()
@@ -2667,26 +2731,37 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2667
2731
+ list (chain .from_iterable (zip (repeat ('--source' ), source )))
2668
2732
+ ['--build' , build_path ]
2669
2733
+ ['--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 [])
2671
2736
+ (['-v' ] if verbose else [])
2672
2737
+ (['--app-config' , app_config ] if app_config else [])
2673
2738
+ (['--test-config' , test_config ] if test_config else [])
2739
+ + (['--icetea' ] if icetea_supported and icetea else [])
2740
+ + (['--greentea' ] if icetea_supported and greentea else [])
2674
2741
+ args ,
2675
2742
env = env )
2676
2743
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
2683
2750
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 )
2690
2765
2691
2766
program .set_defaults (target = target , toolchain = tchain )
2692
2767
0 commit comments