@@ -218,7 +218,8 @@ def hide_progress(max_width=80):
218
218
class ProcessException (Exception ):
219
219
pass
220
220
221
- def popen (command , stdin = None , ** kwargs ):
221
+
222
+ def popen (command , ** kwargs ):
222
223
# print for debugging
223
224
info ("Exec \" %s\" in \" %s\" " % (' ' .join (command ), getcwd ()))
224
225
proc = None
@@ -234,6 +235,7 @@ def popen(command, stdin=None, **kwargs):
234
235
235
236
if proc and proc .wait () != 0 :
236
237
raise ProcessException (proc .returncode , command [0 ], ' ' .join (command ), getcwd ())
238
+ return proc
237
239
238
240
def pquery (command , output_callback = None , stdin = None , ** kwargs ):
239
241
if very_verbose :
@@ -1480,6 +1482,12 @@ def _find_file_paths(self, paths, fl):
1480
1482
return os .path .join (path )
1481
1483
return None
1482
1484
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
+
1483
1491
def check_requirements (self , show_warning = False ):
1484
1492
req_path = self .get_requirements () or self .path
1485
1493
req_file = 'requirements.txt'
@@ -2596,26 +2604,48 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2596
2604
@subcommand ('test' ,
2597
2605
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2598
2606
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' ),
2600
2609
dict (name = '--run-list' , dest = 'run_list' , action = 'store_true' , help = 'List all built tests that can be ran' ),
2601
2610
dict (name = '--compile' , dest = 'compile_only' , action = 'store_true' , help = 'Only compile tests' ),
2602
2611
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)' ),
2604
2614
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
2605
2615
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' ),
2607
2618
dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
2608
2619
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)" ),
2609
2620
dict (name = '--app-config' , dest = "app_config" , help = "Path of an application configuration file. Default is to look for \" mbed_app.json\" " ),
2610
2621
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." ),
2611
2626
help = 'Find, build and run tests' ,
2612
2627
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
+
2614
2637
# Gather remaining arguments
2615
2638
args = remainder
2616
2639
# Find the root of the program
2617
2640
program = Program (getcwd (), True )
2618
2641
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
+
2619
2649
# Save original working directory
2620
2650
orig_path = getcwd ()
2621
2651
@@ -2625,6 +2655,11 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2625
2655
tools_dir = program .get_tools ()
2626
2656
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
2627
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
+
2628
2663
# Prepare environment variables
2629
2664
env = program .get_env ()
2630
2665
@@ -2646,7 +2681,15 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2646
2681
# Create the path to the test spec file
2647
2682
test_spec = os .path .join (build_path , 'test_spec.json' )
2648
2683
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 :
2650
2693
popen ([python_cmd , '-u' , os .path .join (tools_dir , 'test.py' ), '--list' ]
2651
2694
+ list (chain .from_iterable (list (zip (repeat ('--profile' ), profile or []))))
2652
2695
+ ['-t' , tchain , '-m' , target ]
@@ -2655,10 +2698,28 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2655
2698
+ (['-v' ] if verbose else [])
2656
2699
+ (['--app-config' , app_config ] if app_config else [])
2657
2700
+ (['--test-config' , test_config ] if test_config else [])
2701
+ + (['--greentea' ] if icetea_supported and greentea else [])
2658
2702
+ args ,
2659
2703
env = env )
2660
2704
2705
+ if compile_list and icetea :
2706
+ popen (icetea_command_base + ['--compile-list' ])
2707
+
2661
2708
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
+
2662
2723
# If the user hasn't supplied a build directory, ignore the default build directory
2663
2724
if not build :
2664
2725
program .ignore_build_dir ()
@@ -2671,26 +2732,43 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2671
2732
+ list (chain .from_iterable (zip (repeat ('--source' ), source )))
2672
2733
+ ['--build' , build_path ]
2673
2734
+ ['--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 [])
2675
2737
+ (['-v' ] if verbose else [])
2676
2738
+ (['--app-config' , app_config ] if app_config else [])
2677
2739
+ (['--test-config' , test_config ] if test_config else [])
2740
+ + (['--icetea' ] if icetea_supported and icetea else [])
2741
+ + (['--greentea' ] if icetea_supported and greentea else [])
2678
2742
+ args ,
2679
2743
env = env )
2680
2744
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 )
2694
2772
2695
2773
program .set_defaults (target = target , toolchain = tchain )
2696
2774
0 commit comments