From 8c0bc781d938116457d58d03535c352301f22ae7 Mon Sep 17 00:00:00 2001 From: Sarah Marsh Date: Wed, 19 Jul 2017 17:10:34 -0500 Subject: [PATCH] Allow tools to use networkinterface configs in tests --- targets/targets.json | 3 +++ tools/test.py | 20 +++++++++++--- .../EthernetInterface.json | 27 +++++++++++++++++++ tools/test_api.py | 9 +++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tools/test/network_test_configs/EthernetInterface.json diff --git a/targets/targets.json b/targets/targets.json index 452e29db01..1b315a3335 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -608,6 +608,9 @@ "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 diff --git a/tools/test.py b/tools/test.py index 91fad7ed50..6470360a47 100644 --- a/tools/test.py +++ b/tools/test.py @@ -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, print_tests, build_tests, test_spec_from_test_builds +from tools.test_api import test_path_to_name, find_tests, find_configs, 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,6 +84,9 @@ 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("--test-spec", dest="test_spec", default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool") @@ -133,10 +136,19 @@ if __name__ == '__main__': "Currently set search path: %s" % (toolchain, search_path)) + net_configs = find_configs(mcu) # will be {} if target has no network configs + # If there is no app config and the target has network configs + # TODO: merge app_config and net_config if there is both + if net_configs and not options.app_config: + # use a specified network config + config = net_configs[options.net_config] + else: + config = options.app_config + # Find all tests in the relevant paths for path in all_paths: all_tests.update(find_tests(path, mcu, toolchain, - app_config=options.app_config)) + app_config=config)) # Filter tests by name if specified if options.names: @@ -192,7 +204,7 @@ if __name__ == '__main__': properties=build_properties, name="mbed-build", macros=options.macros, verbose=options.verbose, notify=notify, archive=False, - app_config=options.app_config, + app_config=config, build_profile=profile) library_build_success = True @@ -220,7 +232,7 @@ if __name__ == '__main__': notify=notify, jobs=options.jobs, continue_on_build_fail=options.continue_on_build_fail, - app_config=options.app_config, + app_config=config, build_profile=profile, stats_depth=options.stats_depth) diff --git a/tools/test/network_test_configs/EthernetInterface.json b/tools/test/network_test_configs/EthernetInterface.json new file mode 100644 index 0000000000..69bbac0b3a --- /dev/null +++ b/tools/test/network_test_configs/EthernetInterface.json @@ -0,0 +1,27 @@ +{ + "config": { + "header-file": { + "help" : "String for including your driver header file", + "value" : "\"EthernetInterface.h\"" + }, + "object-construction" : { + "value" : "new EthernetInterface()" + }, + "connect-statement" : { + "help" : "Must use 'net' variable name", + "value" : "((EthernetInterface *)net)->connect()" + }, + "echo-server-addr" : { + "help" : "IP address of echo server", + "value" : "\"195.34.89.241\"" + }, + "echo-server-port" : { + "help" : "Port of echo server", + "value" : "7" + }, + "tcp-echo-prefix" : { + "help" : "Some servers send a prefix before echoed message", + "value" : "\"u-blox AG TCP/UDP test service\\n\"" + } + } +} diff --git a/tools/test_api.py b/tools/test_api.py index 985c318e85..564c349603 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -1999,6 +1999,13 @@ 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 find_tests(base_dir, target_name, toolchain_name, app_config=None): """ Finds all tests in a directory recursively base_dir: path to the directory to scan for tests (ex. 'path/to/project') @@ -2010,6 +2017,8 @@ def find_tests(base_dir, target_name, toolchain_name, app_config=None): tests = {} + configs = find_configs(target_name) + # Prepare the toolchain toolchain = prepare_toolchain([base_dir], None, target_name, toolchain_name, silent=True, app_config=app_config)