|
31 | 31 | from types import ListType
|
32 | 32 | from colorama import Fore, Back, Style
|
33 | 33 | from prettytable import PrettyTable
|
| 34 | +from copy import copy |
34 | 35 |
|
35 | 36 | from time import sleep, time
|
36 | 37 | from Queue import Queue, Empty
|
37 |
| -from os.path import join, exists, basename |
| 38 | +from os.path import join, exists, basename, relpath |
38 | 39 | from threading import Thread, Lock
|
39 | 40 | from subprocess import Popen, PIPE
|
40 | 41 |
|
|
56 | 57 | from tools.build_api import prep_properties
|
57 | 58 | from tools.build_api import create_result
|
58 | 59 | from tools.build_api import add_result_to_report
|
59 |
| -from tools.build_api import scan_for_source_paths |
| 60 | +from tools.build_api import prepare_toolchain |
| 61 | +from tools.build_api import scan_resources |
60 | 62 | from tools.libraries import LIBRARIES, LIBRARY_MAP
|
61 | 63 | from tools.toolchains import TOOLCHAIN_PATHS
|
62 | 64 | from tools.toolchains import TOOLCHAINS
|
|
65 | 67 | from tools.utils import argparse_uppercase_type
|
66 | 68 | from tools.utils import argparse_lowercase_type
|
67 | 69 | from tools.utils import argparse_many
|
| 70 | +from tools.utils import get_path_depth |
68 | 71 |
|
69 | 72 | import tools.host_tests.host_tests_plugins as host_tests_plugins
|
70 | 73 |
|
@@ -1987,33 +1990,46 @@ def test_path_to_name(path):
|
1987 | 1990 |
|
1988 | 1991 | return "-".join(name_parts).lower()
|
1989 | 1992 |
|
1990 |
| -def find_tests(base_dir): |
1991 |
| - """Given any directory, walk through the subdirectories and find all tests""" |
1992 |
| - |
1993 |
| - def find_test_in_directory(directory, tests_path): |
1994 |
| - """Given a 'TESTS' directory, return a dictionary of test names and test paths. |
1995 |
| - The formate of the dictionary is {"test-name": "./path/to/test"}""" |
1996 |
| - test = None |
1997 |
| - if tests_path in directory: |
1998 |
| - head, test_case_directory = os.path.split(directory) |
1999 |
| - if test_case_directory != tests_path and test_case_directory != "host_tests": |
2000 |
| - head, test_group_directory = os.path.split(head) |
2001 |
| - if test_group_directory != tests_path and test_case_directory != "host_tests": |
2002 |
| - test = { |
2003 |
| - "name": test_path_to_name(directory), |
2004 |
| - "path": directory |
2005 |
| - } |
2006 |
| - |
2007 |
| - return test |
| 1993 | +def find_tests(base_dir, target_name, toolchain_name, options=None): |
| 1994 | + """ Finds all tests in a directory recursively |
| 1995 | + base_dir: path to the directory to scan for tests (ex. 'path/to/project') |
| 1996 | + target_name: name of the target to use for scanning (ex. 'K64F') |
| 1997 | + toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM') |
| 1998 | + options: Compile options to pass to the toolchain (ex. ['debug-info']) |
| 1999 | + """ |
2008 | 2000 |
|
2009 |
| - tests_path = 'TESTS' |
2010 | 2001 | tests = {}
|
2011 |
| - dirs = scan_for_source_paths(base_dir) |
2012 | 2002 |
|
| 2003 | + # Prepare the toolchain |
| 2004 | + toolchain = prepare_toolchain(base_dir, target_name, toolchain_name, options=options, silent=True) |
| 2005 | + |
| 2006 | + # Scan the directory for paths to probe for 'TESTS' folders |
| 2007 | + base_resources = scan_resources(base_dir, toolchain) |
| 2008 | + |
| 2009 | + dirs = base_resources.inc_dirs |
2013 | 2010 | for directory in dirs:
|
2014 |
| - test = find_test_in_directory(directory, tests_path) |
2015 |
| - if test: |
2016 |
| - tests[test['name']] = test['path'] |
| 2011 | + subdirs = os.listdir(directory) |
| 2012 | + |
| 2013 | + # If the directory contains a subdirectory called 'TESTS', scan it for test cases |
| 2014 | + if 'TESTS' in subdirs: |
| 2015 | + walk_base_dir = join(directory, 'TESTS') |
| 2016 | + test_resources = toolchain.scan_resources(walk_base_dir, base_path=base_dir) |
| 2017 | + |
| 2018 | + # Loop through all subdirectories |
| 2019 | + for d in test_resources.inc_dirs: |
| 2020 | + |
| 2021 | + # If the test case folder is not called 'host_tests' and it is |
| 2022 | + # located two folders down from the main 'TESTS' folder (ex. TESTS/testgroup/testcase) |
| 2023 | + # then add it to the tests |
| 2024 | + path_depth = get_path_depth(relpath(d, walk_base_dir)) |
| 2025 | + if path_depth == 2: |
| 2026 | + test_group_directory_path, test_case_directory = os.path.split(d) |
| 2027 | + test_group_directory = os.path.basename(test_group_directory_path) |
| 2028 | + |
| 2029 | + # Check to make sure discoverd folder is not in a host test directory |
| 2030 | + if test_case_directory != 'host_tests' and test_group_directory != 'host_tests': |
| 2031 | + test_name = test_path_to_name(d) |
| 2032 | + tests[test_name] = d |
2017 | 2033 |
|
2018 | 2034 | return tests
|
2019 | 2035 |
|
|
0 commit comments