Use only one flag for test configuration file

Tools will figure out if user passed in a custom path (to indicate configration file for module) or whether they used a keyword (to indicate they'd like to use an mbed OS configuration)
pull/4795/head
Sarah Marsh 2017-07-21 15:07:07 -05:00
parent e982eed4ad
commit ba6eb98b5c
6 changed files with 55 additions and 23 deletions

View File

@ -608,9 +608,6 @@
"detect_code": ["0240"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "TRNG", "FLASH"],
"features": ["LWIP", "STORAGE"],
"network_test_configurations" : {
"EthernetInterface" : "mbed-os/tools/test/network_test_configs/EthernetInterface.json"
},
"release_versions": ["2", "5"],
"device_name": "MK64FN1M0xxx12",
"bootloader_supported": true

View File

@ -27,7 +27,7 @@ ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, ROOT)
from tools.config import ConfigException
from tools.test_api import test_path_to_name, find_tests, find_configs, print_tests, build_tests, test_spec_from_test_builds
from tools.test_api import test_path_to_name, find_tests, get_test_config, print_tests, build_tests, test_spec_from_test_builds
from tools.options import get_default_options_parser, extract_profile, extract_mcus
from tools.build_api import build_project, build_library
from tools.build_api import print_build_memory_usage
@ -84,10 +84,7 @@ if __name__ == '__main__':
parser.add_argument("-n", "--names", dest="names", type=argparse_many(str),
default=None, help="Limit the tests to a comma separated list of names")
parser.add_argument("--net-config", dest="net_config", type=str,
default="EthernetInterface", help="Limit the tests to a networkinterface")
parser.add_argument("--module-config", dest="module_config", type=str,
parser.add_argument("--test-config", dest="test_config", type=str,
default=None, help="Test config for a module")
parser.add_argument("--test-spec", dest="test_spec",
@ -139,13 +136,15 @@ if __name__ == '__main__':
"Currently set search path: %s"
% (toolchain, search_path))
# Assign config file. Precedence: module_config>net_config>app_config
# TODO: merge configs if there are multiple
if options.module_config:
config = options.module_config
elif find_configs(mcu):
net_configs = find_configs(mcu) # will be {} if target has no network configs
config = net_configs[options.net_config]
# boolean, true if test configuration file is for module false if mbed-os interface
module_conf = False
# Assign config file. Precedence: test_config>app_config
# TODO: merge configs if both given
if options.test_config:
config, module_conf = get_test_config(options.test_config, mcu)
if not config:
args_error(parser, "argument --test-config contains invalid path or identifier")
else:
config = options.app_config
@ -153,7 +152,7 @@ if __name__ == '__main__':
for path in all_paths:
all_tests.update(find_tests(path, mcu, toolchain,
app_config=config,
module_config=options.module_config))
module_config=module_conf))
# Filter tests by name if specified
if options.names:

View File

@ -50,6 +50,7 @@ from tools.utils import NotSupportedException
from tools.utils import construct_enum
from tools.memap import MemapParser
from tools.targets import TARGET_MAP
from tools.test_configs import TestConfig
from tools.test_db import BaseDBAccess
from tools.build_api import build_project, build_mbed_libs, build_lib
from tools.build_api import get_target_supported_toolchains
@ -1999,12 +2000,18 @@ def test_path_to_name(path, base):
return "-".join(name_parts).lower()
def find_configs(target_name):
target = TARGET_MAP[target_name]
try:
return target.network_test_configurations
except AttributeError:
return {}
def get_test_config(config_name, target_name):
"""Finds the path to a test configuration file
config_name: path to a custom configuration file OR mbed OS interface "ethernet, wifi_odin, etc"
target_name: name of target to determing if mbed OS interface given is valid
returns path to config, boolean of whether it is a module or mbed OS interface
"""
# If they passed in a full path
if exists(config_name):
# This is a module config
return config_name, True
# Otherwise find the path to configuration file based on mbed OS interface
return TestConfig.get_config_path(config_name, target_name), False
def find_tests(base_dir, target_name, toolchain_name, app_config=None, module_config=None):
""" Finds all tests in a directory recursively
@ -2017,7 +2024,7 @@ def find_tests(base_dir, target_name, toolchain_name, app_config=None, module_co
tests = {}
configs = find_configs(target_name)
configs = TestConfig.get_valid_configs(target_name)
# Prepare the toolchain
toolchain = prepare_toolchain([base_dir], None, target_name, toolchain_name,

View File

@ -0,0 +1,25 @@
from os.path import dirname, abspath, join
from tools.utils import json_file_to_dict
from tools.targets import TARGET_MAP
class TestConfig:
CONFIG_DIR = dirname(abspath(__file__))
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
@classmethod
def get_valid_configs(cls, target_name):
target = TARGET_MAP[target_name]
config_dict = {}
for attr in cls.CONFIG_MAP:
if attr in target.device_has:
config_dict[attr] = cls.CONFIG_MAP[attr]
return config_dict
@classmethod
def get_config_path(cls, conf_name, target_name):
configs = cls.get_valid_configs(target_name)
if configs and conf_name.upper() in configs:
return join(cls.CONFIG_DIR, configs[conf_name.upper()])
else:
return None

View File

@ -0,0 +1,4 @@
{
"ETHERNET" : "EthernetInterface.json",
"ODIN_WIFI" : "OdinInterface.json"
}