28
28
import datetime
29
29
import threading
30
30
import ctypes
31
+ import functools
31
32
from types import ListType
32
33
from colorama import Fore , Back , Style
33
34
from prettytable import PrettyTable
71
72
from tools .utils import argparse_uppercase_type
72
73
from tools .utils import argparse_lowercase_type
73
74
from tools .utils import argparse_many
74
- from tools .utils import get_path_depth
75
75
76
76
import tools .host_tests .host_tests_plugins as host_tests_plugins
77
77
@@ -2019,9 +2019,15 @@ def find_tests(base_dir, target_name, toolchain_name, app_config=None):
2019
2019
toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM')
2020
2020
options: Compile options to pass to the toolchain (ex. ['debug-info'])
2021
2021
app_config - location of a chosen mbed_app.json file
2022
+
2023
+ returns a dictionary where keys are the test name, and the values are
2024
+ lists of paths needed to biuld the test.
2022
2025
"""
2023
2026
2027
+ # Temporary structure: tests referenced by (name, base, group, case) tuple
2024
2028
tests = {}
2029
+ # List of common folders: (predicate function, path) tuple
2030
+ commons = []
2025
2031
2026
2032
# Prepare the toolchain
2027
2033
toolchain = prepare_toolchain ([base_dir ], None , target_name , toolchain_name ,
@@ -2042,32 +2048,52 @@ def find_tests(base_dir, target_name, toolchain_name, app_config=None):
2042
2048
# Loop through all subdirectories
2043
2049
for d in test_resources .inc_dirs :
2044
2050
2045
- # If the test case folder is not called 'host_tests' and it is
2051
+ # If the test case folder is not called 'host_tests' or 'COMMON' and it is
2046
2052
# located two folders down from the main 'TESTS' folder (ex. TESTS/testgroup/testcase)
2047
2053
# then add it to the tests
2048
- path_depth = get_path_depth (relpath (d , walk_base_dir ))
2049
- if path_depth == 2 :
2054
+ relative_path = relpath (d , walk_base_dir )
2055
+ relative_path_parts = os .path .normpath (relative_path ).split (os .sep )
2056
+ if len (relative_path_parts ) == 2 :
2050
2057
test_group_directory_path , test_case_directory = os .path .split (d )
2051
2058
test_group_directory = os .path .basename (test_group_directory_path )
2052
2059
2053
- # Check to make sure discoverd folder is not in a host test directory
2054
- if test_case_directory != 'host_tests' and test_group_directory != 'host_tests' :
2060
+ # Check to make sure discoverd folder is not in a host test directory or common directory
2061
+ special_dirs = ['host_tests' , 'COMMON' ]
2062
+ if test_group_directory not in special_dirs and test_case_directory not in special_dirs :
2055
2063
test_name = test_path_to_name (d , base_dir )
2056
- tests [test_name ] = d
2064
+ tests [(test_name , walk_base_dir , test_group_directory , test_case_directory )] = [d ]
2065
+
2066
+ # Also find any COMMON paths, we'll add these later once we find all the base tests
2067
+ if 'COMMON' in relative_path_parts :
2068
+ if relative_path_parts [0 ] != 'COMMON' :
2069
+ def predicate (base_pred , group_pred , (name , base , group , case )):
2070
+ return base == base_pred and group == group_pred
2071
+ commons .append ((functools .partial (predicate , walk_base_dir , relative_path_parts [0 ]), d ))
2072
+ else :
2073
+ def predicate (base_pred , (name , base , group , case )):
2074
+ return base == base_pred
2075
+ commons .append ((functools .partial (predicate , walk_base_dir ), d ))
2057
2076
2058
- return tests
2077
+ # Apply common directories
2078
+ for pred , path in commons :
2079
+ for test_identity , test_paths in tests .iteritems ():
2080
+ if pred (test_identity ):
2081
+ test_paths .append (path )
2082
+
2083
+ # Drop identity besides name
2084
+ return {name : paths for (name , _ , _ , _ ), paths in tests .iteritems ()}
2059
2085
2060
2086
def print_tests (tests , format = "list" , sort = True ):
2061
2087
"""Given a dictionary of tests (as returned from "find_tests"), print them
2062
2088
in the specified format"""
2063
2089
if format == "list" :
2064
2090
for test_name in sorted (tests .keys ()):
2065
- test_path = tests [test_name ]
2091
+ test_path = tests [test_name ][ 0 ]
2066
2092
print "Test Case:"
2067
2093
print " Name: %s" % test_name
2068
2094
print " Path: %s" % test_path
2069
2095
elif format == "json" :
2070
- print json .dumps (tests , indent = 2 )
2096
+ print json .dumps ({ test_name : test_path [ 0 ] for test_name , test_paths in tests } , indent = 2 )
2071
2097
else :
2072
2098
print "Unknown format '%s'" % format
2073
2099
sys .exit (1 )
@@ -2164,13 +2190,16 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
2164
2190
jobs_count = int (jobs if jobs else cpu_count ())
2165
2191
p = Pool (processes = jobs_count )
2166
2192
results = []
2167
- for test_name , test_path in tests .iteritems ():
2168
- test_build_path = os .path .join (build_path , test_path )
2169
- src_path = base_source_paths + [test_path ]
2193
+ for test_name , test_paths in tests .iteritems ():
2194
+ if type (test_paths ) != ListType :
2195
+ test_paths = [test_paths ]
2196
+
2197
+ test_build_path = os .path .join (build_path , test_paths [0 ])
2198
+ src_paths = base_source_paths + test_paths
2170
2199
bin_file = None
2171
- test_case_folder_name = os .path .basename (test_path )
2200
+ test_case_folder_name = os .path .basename (test_paths [ 0 ] )
2172
2201
2173
- args = (src_path , test_build_path , target , toolchain_name )
2202
+ args = (src_paths , test_build_path , target , toolchain_name )
2174
2203
kwargs = {
2175
2204
'jobs' : 1 ,
2176
2205
'clean' : clean ,
0 commit comments