Skip to content

Commit ba6eb98

Browse files
committed
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)
1 parent e982eed commit ba6eb98

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

targets/targets.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,6 @@
608608
"detect_code": ["0240"],
609609
"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"],
610610
"features": ["LWIP", "STORAGE"],
611-
"network_test_configurations" : {
612-
"EthernetInterface" : "mbed-os/tools/test/network_test_configs/EthernetInterface.json"
613-
},
614611
"release_versions": ["2", "5"],
615612
"device_name": "MK64FN1M0xxx12",
616613
"bootloader_supported": true

tools/test.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
sys.path.insert(0, ROOT)
2828

2929
from tools.config import ConfigException
30-
from tools.test_api import test_path_to_name, find_tests, find_configs, print_tests, build_tests, test_spec_from_test_builds
30+
from tools.test_api import test_path_to_name, find_tests, get_test_config, print_tests, build_tests, test_spec_from_test_builds
3131
from tools.options import get_default_options_parser, extract_profile, extract_mcus
3232
from tools.build_api import build_project, build_library
3333
from tools.build_api import print_build_memory_usage
@@ -84,10 +84,7 @@
8484
parser.add_argument("-n", "--names", dest="names", type=argparse_many(str),
8585
default=None, help="Limit the tests to a comma separated list of names")
8686

87-
parser.add_argument("--net-config", dest="net_config", type=str,
88-
default="EthernetInterface", help="Limit the tests to a networkinterface")
89-
90-
parser.add_argument("--module-config", dest="module_config", type=str,
87+
parser.add_argument("--test-config", dest="test_config", type=str,
9188
default=None, help="Test config for a module")
9289

9390
parser.add_argument("--test-spec", dest="test_spec",
@@ -139,21 +136,23 @@
139136
"Currently set search path: %s"
140137
% (toolchain, search_path))
141138

142-
# Assign config file. Precedence: module_config>net_config>app_config
143-
# TODO: merge configs if there are multiple
144-
if options.module_config:
145-
config = options.module_config
146-
elif find_configs(mcu):
147-
net_configs = find_configs(mcu) # will be {} if target has no network configs
148-
config = net_configs[options.net_config]
139+
# boolean, true if test configuration file is for module false if mbed-os interface
140+
module_conf = False
141+
142+
# Assign config file. Precedence: test_config>app_config
143+
# TODO: merge configs if both given
144+
if options.test_config:
145+
config, module_conf = get_test_config(options.test_config, mcu)
146+
if not config:
147+
args_error(parser, "argument --test-config contains invalid path or identifier")
149148
else:
150149
config = options.app_config
151150

152151
# Find all tests in the relevant paths
153152
for path in all_paths:
154153
all_tests.update(find_tests(path, mcu, toolchain,
155154
app_config=config,
156-
module_config=options.module_config))
155+
module_config=module_conf))
157156

158157
# Filter tests by name if specified
159158
if options.names:

tools/test_api.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from tools.utils import construct_enum
5151
from tools.memap import MemapParser
5252
from tools.targets import TARGET_MAP
53+
from tools.test_configs import TestConfig
5354
from tools.test_db import BaseDBAccess
5455
from tools.build_api import build_project, build_mbed_libs, build_lib
5556
from tools.build_api import get_target_supported_toolchains
@@ -1999,12 +2000,18 @@ def test_path_to_name(path, base):
19992000

20002001
return "-".join(name_parts).lower()
20012002

2002-
def find_configs(target_name):
2003-
target = TARGET_MAP[target_name]
2004-
try:
2005-
return target.network_test_configurations
2006-
except AttributeError:
2007-
return {}
2003+
def get_test_config(config_name, target_name):
2004+
"""Finds the path to a test configuration file
2005+
config_name: path to a custom configuration file OR mbed OS interface "ethernet, wifi_odin, etc"
2006+
target_name: name of target to determing if mbed OS interface given is valid
2007+
returns path to config, boolean of whether it is a module or mbed OS interface
2008+
"""
2009+
# If they passed in a full path
2010+
if exists(config_name):
2011+
# This is a module config
2012+
return config_name, True
2013+
# Otherwise find the path to configuration file based on mbed OS interface
2014+
return TestConfig.get_config_path(config_name, target_name), False
20082015

20092016
def find_tests(base_dir, target_name, toolchain_name, app_config=None, module_config=None):
20102017
""" 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
20172024

20182025
tests = {}
20192026

2020-
configs = find_configs(target_name)
2027+
configs = TestConfig.get_valid_configs(target_name)
20212028

20222029
# Prepare the toolchain
20232030
toolchain = prepare_toolchain([base_dir], None, target_name, toolchain_name,

tools/test_configs/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from os.path import dirname, abspath, join
2+
3+
from tools.utils import json_file_to_dict
4+
from tools.targets import TARGET_MAP
5+
6+
class TestConfig:
7+
CONFIG_DIR = dirname(abspath(__file__))
8+
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
9+
10+
@classmethod
11+
def get_valid_configs(cls, target_name):
12+
target = TARGET_MAP[target_name]
13+
config_dict = {}
14+
for attr in cls.CONFIG_MAP:
15+
if attr in target.device_has:
16+
config_dict[attr] = cls.CONFIG_MAP[attr]
17+
return config_dict
18+
19+
@classmethod
20+
def get_config_path(cls, conf_name, target_name):
21+
configs = cls.get_valid_configs(target_name)
22+
if configs and conf_name.upper() in configs:
23+
return join(cls.CONFIG_DIR, configs[conf_name.upper()])
24+
else:
25+
return None

tools/test_configs/config_paths.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ETHERNET" : "EthernetInterface.json",
3+
"ODIN_WIFI" : "OdinInterface.json"
4+
}

0 commit comments

Comments
 (0)