diff --git a/.github/workflows/basic_checks.yml b/.github/workflows/basic_checks.yml index a9f82e7fdc3..45eab7a5f1d 100644 --- a/.github/workflows/basic_checks.yml +++ b/.github/workflows/basic_checks.yml @@ -158,7 +158,6 @@ jobs: doxyfile-path: ./doxyfile_options python-tests: - # these tests run in 3.7, hence running in vm not in pre-built docker runs-on: ubuntu-latest steps: - diff --git a/tools/cmake/mbed-run-greentea-test.in.cmake b/tools/cmake/mbed-run-greentea-test.in.cmake index 36739b22543..e5980564416 100644 --- a/tools/cmake/mbed-run-greentea-test.in.cmake +++ b/tools/cmake/mbed-run-greentea-test.in.cmake @@ -16,7 +16,6 @@ set(MBEDHTRUN_ARGS --skip-flashing @MBED_HTRUN_ARGUMENTS@) # filled in by config string(REPLACE ";" " " MBEDHTRUN_ARGS_FOR_DISPLAY "${MBEDHTRUN_ARGS}") message("Executing: @Python3_EXECUTABLE@ -m mbed_host_tests.mbedhtrun ${MBEDHTRUN_ARGS_FOR_DISPLAY}") -# Note: For this command, we need to survive mbedhtrun not being on the PATH, so we import the package and call the main function using "python -c" execute_process( COMMAND @Python3_EXECUTABLE@ -m mbed_host_tests.mbedhtrun ${MBEDHTRUN_ARGS} WORKING_DIRECTORY "@mbed-os_SOURCE_DIR@/tools/python" diff --git a/tools/python/mbed_greentea/README.md b/tools/python/mbed_greentea/README.md deleted file mode 100644 index dabd26b8951..00000000000 --- a/tools/python/mbed_greentea/README.md +++ /dev/null @@ -1,227 +0,0 @@ -# Development moved - -The development of Greentea has been moved into the [mbed-os-tools](../../src/mbed_os_tools) package. You can continue to use this module for legacy reasons, however all further development should be continued in the new package. - -------------- - -[![PyPI version](https://badge.fury.io/py/mbed-greentea.svg)](https://badge.fury.io/py/mbed-greentea) - -# Greentea - test automation for mbed -_**G**eneric **re**gression **en**vironment for **te**st **a**utomation_ - -## Introduction - -Greentea is the automated testing tool for mbed OS development. It automates the process of flashing mbed boards, driving the test and accumulating test results into test reports. Developers use it for local development as well as for automation in a Continuous Integration environment. - -This document should help you start using Greentea. Please see the [htrun documentation](https://github.com/ARMmbed/htrun), the tool Greentea uses to drive tests, for the technical details of the interactions between the platform and the host machine. - -Because Greentea is an open source project, we accept contributions! Please see our [contributing document](CONTRIBUTING.md) for more information. - -### Prerequistes - -Greentea requires [Python version 2.7](https://www.python.org/downloads/). It supports the following OSes: - -- Windows -- Linux (Ubuntu preferred) -- OS X (experimental) - -### Installing - -Tools that depend on Greentea usually install it. Determine if Greentea is already installed by running: -``` -$ mbedgt --version -1.2.5 -``` - -You can also install it manually via pip. - -``` -pip install mbed-greentea -``` - -## Test specification JSON format - -The Greentea test specification format decouples the tool from your build system. It provides important data, such as test names, paths to test binaries and the platform on which the binaries should run. - -Greentea automatically looks for files called `test_spec.json` in your working directory. You can also use the `--test-spec` argument to direct Greentea to a specific test specification file. - -When you use the `-t` / `--target` argument with the `--test-spec` argument, you can select which "build" should be used. In the example below, you could provide the arguments `--test-spec test_spec.json -t K64F-ARM` to only run that build's tests. - -### Example of test specification file - -In the below example, there are two defined builds: -* Build `K64F-ARM` for NXP `K64F` platform compiled with `ARMCC` compiler. -* Build `K64F-GCC` for NXP `K64F` platform compiled with `GCC ARM` compiler. - -```json -{ - "builds": { - "K64F-ARM": { - "platform": "K64F", - "toolchain": "ARM", - "base_path": "./BUILD/K64F/ARM", - "baud_rate": 9600, - "tests": { - "tests-mbedmicro-rtos-mbed-mail": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/ARM/tests-mbedmicro-rtos-mbed-mail.bin" - } - ] - }, - "tests-mbed_drivers-c_strings": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/ARM/tests-mbed_drivers-c_strings.bin" - } - ] - } - } - }, - "K64F-GCC": { - "platform": "K64F", - "toolchain": "GCC_ARM", - "base_path": "./BUILD/K64F/GCC_ARM", - "baud_rate": 9600, - "tests": { - "tests-mbedmicro-rtos-mbed-mail": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/GCC_ARM/tests-mbedmicro-rtos-mbed-mail.bin" - } - ] - } - } - } - } -} -``` - -The examples below use the above test specification file. - -## Command-line usage -This section highlights a few of the capabilities of the Greentea command-line interface. For a full list of the available options, please run `mbedgt --help`. - -Assume for the examples below that the above `test_spec.json` file is in the current directory. - -### Listing all tests -You can use the `-l` argument to list all available tests: - -``` -$ mbedgt -l -mbedgt: greentea test automation tool ver. 1.2.5 -mbedgt: using multiple test specifications from current directory! - using 'BUILD\tests\K64F\ARM\test_spec.json' - using 'BUILD\tests\K64F\GCC_ARM\test_spec.json' -mbedgt: available tests for built 'K64F-GCC_ARM', location 'BUILD/tests/K64F/GCC_ARM' - test 'tests-mbedmicro-rtos-mbed-mail' -mbedgt: available tests for built 'K64F-ARM', location 'BUILD/tests/K64F/ARM' - test 'tests-mbed_drivers-c_strings' - test 'tests-mbedmicro-rtos-mbed-mail' -``` - -### Executing all tests -The default action of Greentea using `mbedgt` is to execute all tests that are found in `test_spec.json` files. You can also add `-V` to make the output more verbose. - - -### Limiting tests -You can select test cases by name using the `-n` argument. This command executes all tests named `tests-mbedmicro-rtos-mbed-mail` from all builds in the test specification: -``` -$ mbedgt -n tests-mbedmicro-rtos-mbed-mail -``` - -When using the `-n` argument, you can use the `*` character at the end of a test name to match all tests that share a prefix. This command executes all tests that start with `tests*`: - -``` -$ mbedgt -n tests* -``` - -You can use the `-t` argument to select which build to use when finding tests. This command executes the test `tests-mbedmicro-rtos-mbed-mail` for the `K64F-ARM` build in the test specification: -``` -$ mbedgt -n tests-mbedmicro-rtos-mbed-mail -t K64F-ARM -``` - -You can use a comma (`,`) to separate test names (argument `-n`) and build names (argument `-t`). This command executes the tests `tests-mbedmicro-rtos-mbed-mail` and `tests-mbed_drivers-c_strings` for the `K64F-ARM` and `K64F-GCC_ARM` builds in the test specification: -``` -$ mbedgt -n tests-mbedmicro-rtos-mbed-mail,tests-mbed_drivers-c_strings -t K64F-ARM,K64F-GCC_ARM -``` - -### Selecting platforms -You can limit which boards Greentea uses for testing by using the `--use-tids` argument. - -``` -$ mbedgt --use-tids 02400203C3423E603EBEC3D8,024002031E031E6AE3FFE3D2 -``` - -Where ```02400203C3423E603EBEC3D8``` and ```024002031E031E6AE3FFE3D2``` are the target IDs of platforms attached to your system. - -You can view target IDs using the [mbed-ls](https://pypi.org/project/mbed-ls) tool (installed with Greentea). - -``` -$ mbedls -+--------------+---------------------+------------+------------+-------------------------+ -|platform_name |platform_name_unique |mount_point |serial_port |target_id | -+--------------+---------------------+------------+------------+-------------------------+ -|K64F |K64F[0] |E: |COM160 |024002031E031E6AE3FFE3D2 | -|K64F |K64F[1] |F: |COM162 |02400203C3423E603EBEC3D8 | -|LPC1768 |LPC1768[0] |G: |COM5 |1010ac87cfc4f23c4c57438d | -+--------------+---------------------+------------+------------+-------------------------+ -``` -In this case, you won't test one target, the LPC1768. - -### Testing on Fast Model FVPs - -Fast Models FVPs are software models for Arm reference design platfrom - -Greentea supports running test on Fast Models. And [mbed-fastmodel-agent](https://github.com/ARMmbed/mbed-fastmodel-agent) module is required for this purpose. - -The "--fm" option only available when the `mbed-fastmodel-agent` module is installed : - -You can run tests for FVP_MPS2_Cortex-M3 models, by '--fm' option: -``` -$ mbedgt --fm FVP_MPS2_M3:DEFAULT -``` - -Where ```FVP_MPS2_M3``` is the platfrom name for the ```FVP_MPS2_Cortex-M3``` models in mbed OS. - -And ```DEFAULT``` is the config to the Fast Model, you can find out using ```mbedfm``` command - -### Creating reports -Greentea supports a number of report formats. - -#### HTML -This creates an interactive HTML page with test results and logs. -``` -mbedgt --report-html html_report.html -``` - -#### JUnit -This creates an XML JUnit report, which you can use with popular Continuous Integration software, such as [Jenkins](https://jenkins.io/index.html). -``` -mbedgt --report-junit junit_report.xml -``` - -#### JSON -This creates a general JSON report. -``` -mbedgt --report-json json_report.json -``` - -#### Plain text -This creates a human-friendly text summary of the test run. -``` -mbedgt --report-text text_report.text -``` - -## Host test detection -When developing with mbed OS, Greentea detects host tests automatically if you place them in the correct location. All tests in mbed OS are placed under a `TESTS` directory. You may place custom host test scripts in a folder named `host_tests` in this folder. For more information about the mbed OS test directory structure, please see the [mbed CLI documentation](https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/cli/#test-directory-structure). - -## Common issues - -### `IOERR_SERIAL` errors -Possible causes: -- Another program is using the serial port. Be sure all terminals and other instances of Greentea are closed before trying again. -- The mbed interface firmware is out of date. Please see the platform's page on [developer.mbed.org](https://developer.mbed.org/) for details about how to update it. diff --git a/tools/python/mbed_greentea/__init__.py b/tools/python/mbed_greentea/__init__.py deleted file mode 100644 index 2ad93138a21..00000000000 --- a/tools/python/mbed_greentea/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from .mbed_greentea_cli import main - -"""! @package mbed-greentea - -This is a test suite used by mbed project. If you have yotta package with tests you can run them on supported hardware -This test suite supports: -* mbed-ls - mbed-enabled device auto detection module -* mbed-host-test - mbed-enabled device test framework (flash, reset and make host tests) - -""" diff --git a/tools/python/mbed_greentea/__main__.py b/tools/python/mbed_greentea/__main__.py deleted file mode 100644 index 91b45f03001..00000000000 --- a/tools/python/mbed_greentea/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -from mbed_greentea.mbed_greentea_cli import main -exit(main()) \ No newline at end of file diff --git a/tools/python/mbed_greentea/cmake_handlers.py b/tools/python/mbed_greentea/cmake_handlers.py deleted file mode 100644 index 54954a78236..00000000000 --- a/tools/python/mbed_greentea/cmake_handlers.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.cmake_handlers import ( - load_ctest_testsuite, - parse_ctesttestfile_line, - list_binaries_for_targets, - list_binaries_for_builds, -) diff --git a/tools/python/mbed_greentea/mbed_common_api.py b/tools/python/mbed_greentea/mbed_common_api.py deleted file mode 100644 index ce0251c7791..00000000000 --- a/tools/python/mbed_greentea/mbed_common_api.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_common_api import ( - run_cli_command, - run_cli_process, -) diff --git a/tools/python/mbed_greentea/mbed_coverage_api.py b/tools/python/mbed_greentea/mbed_coverage_api.py deleted file mode 100644 index 4a025bb27d3..00000000000 --- a/tools/python/mbed_greentea/mbed_coverage_api.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_coverage_api import ( - coverage_pack_hex_payload, - coverage_dump_file, -) diff --git a/tools/python/mbed_greentea/mbed_greentea_cli.py b/tools/python/mbed_greentea/mbed_greentea_cli.py deleted file mode 100644 index be3ab81770c..00000000000 --- a/tools/python/mbed_greentea/mbed_greentea_cli.py +++ /dev/null @@ -1,1053 +0,0 @@ - -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -import os -import sys -import random -import optparse -import imp -import io -from time import time -try: - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - -from threading import Thread - - -from mbed_os_tools.test.mbed_test_api import ( - get_test_build_properties, - get_test_spec, - log_mbed_devices_in_table, - TEST_RESULTS, - TEST_RESULT_OK, - TEST_RESULT_FAIL, - parse_global_resource_mgr, - parse_fast_model_connection -) - -from mbed_os_tools.test.mbed_report_api import ( - exporter_text, - exporter_testcase_text, - exporter_json, - exporter_testcase_junit, - exporter_html, - exporter_memory_metrics_csv, -) - -from mbed_os_tools.test.mbed_greentea_log import gt_logger - -from mbed_os_tools.test.mbed_greentea_dlm import ( - GREENTEA_KETTLE_PATH, - greentea_get_app_sem, - greentea_update_kettle, - greentea_clean_kettle, -) - -from mbed_os_tools.test.mbed_greentea_hooks import GreenteaHooks -from mbed_os_tools.test.tests_spec import TestBinary -from mbed_os_tools.test.mbed_target_info import get_platform_property - -from .mbed_test_api import run_host_test - -import mbed_os_tools.detect -import mbed_os_tools.test.host_tests_plugins as host_tests_plugins -from mbed_os_tools.test.mbed_greentea_cli import ( - RET_NO_DEVICES, - RET_YOTTA_BUILD_FAIL, - LOCAL_HOST_TESTS_DIR, - get_local_host_tests_dir, - create_filtered_test_list, -) - -LOCAL_HOST_TESTS_DIR = './test/host_tests' # Used by mbedhtrun -e - - -def get_greentea_version(): - """! Get Greentea (mbed-greentea) Python module version - """ - import mbed_os_tools - return mbed_os_tools.VERSION - -def print_version(): - """! Print current package version - """ - print(get_greentea_version()) - -def get_hello_string(): - """! Hello string used as first print - """ - version = get_greentea_version() - return "greentea test automation tool ver. " + version - -def main(): - """ Closure for main_cli() function """ - parser = optparse.OptionParser() - - parser.add_option('-t', '--target', - dest='list_of_targets', - help='You can specify list of yotta targets you want to build. Use comma to separate them.' + - 'Note: If --test-spec switch is defined this list becomes optional list of builds you want to filter in your test:' + - 'Comma separated list of builds from test specification. Applicable if --test-spec switch is specified') - - parser.add_option('-n', '--test-by-names', - dest='test_by_names', - help='Runs only test enumerated it this switch. Use comma to separate test case names.') - - parser.add_option('-i', '--skip-test', - dest='skip_test', - help='Skip tests enumerated it this switch. Use comma to separate test case names.') - - parser.add_option("-O", "--only-build", - action="store_true", - dest="only_build_tests", - default=False, - help="Only build repository and tests, skips actual test procedures (flashing etc.)") - - parser.add_option("-S", "--skip-build", - action="store_true", - dest="skip_yotta_build", - default=True, - help="Skip calling 'yotta build' on this module") - - copy_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('CopyMethod')) - parser.add_option("-c", "--copy", - dest="copy_method", - help="Copy (flash the target) method selector. " + copy_methods_str, - metavar="COPY_METHOD") - - reset_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('ResetMethod')) - parser.add_option("-r", "--reset", - dest="reset_method", - help="Reset method selector. " + reset_methods_str, - metavar="RESET_METHOD") - - parser.add_option('', '--parallel', - dest='parallel_test_exec', - default=1, - help='Experimental, you execute test runners for connected to your host MUTs in parallel (speeds up test result collection)') - - parser.add_option("-e", "--enum-host-tests", - dest="enum_host_tests", - help="Define directory with yotta module local host tests. Default: ./test/host_tests") - - parser.add_option('', '--config', - dest='verbose_test_configuration_only', - default=False, - action="store_true", - help='Displays connected boards and detected targets and exits.') - - parser.add_option('', '--release', - dest='build_to_release', - default=False, - action="store_true", - help='If possible force build in release mode (yotta -r).') - - parser.add_option('', '--debug', - dest='build_to_debug', - default=False, - action="store_true", - help='If possible force build in debug mode (yotta -d).') - - parser.add_option('-l', '--list', - dest='list_binaries', - default=False, - action="store_true", - help='List available binaries') - - parser.add_option('-g', '--grm', - dest='global_resource_mgr', - help=( - 'Global resource manager: ":' - ':[:]", ' - 'Ex. "K64F:module_name:10.2.123.43:3334", ' - '"K64F:module_name:https://example.com"' - ) - ) - - # Show --fm option only if "fm_agent" module installed - try: - imp.find_module('fm_agent') - except ImportError: - fm_help=optparse.SUPPRESS_HELP - else: - fm_help='Fast Model Connection: fastmodel name, config name, example FVP_MPS2_M3:DEFAULT' - parser.add_option('', '--fm', - dest='fast_model_connection', - help=fm_help) - - parser.add_option('-m', '--map-target', - dest='map_platform_to_yt_target', - help='List of custom mapping between platform name and yotta target. Comma separated list of YOTTA_TARGET:PLATFORM tuples') - - parser.add_option('', '--use-tids', - dest='use_target_ids', - help='Specify explicitly which devices can be used by Greentea for testing by creating list of allowed Target IDs (use comma separated list)') - - parser.add_option('-u', '--shuffle', - dest='shuffle_test_order', - default=False, - action="store_true", - help='Shuffles test execution order') - - parser.add_option('', '--shuffle-seed', - dest='shuffle_test_seed', - default=None, - help='Shuffle seed (If you want to reproduce your shuffle order please use seed provided in test summary)') - - parser.add_option('', '--sync', - dest='num_sync_packtes', - default=5, - help='Define how many times __sync packet will be sent to device: 0: none; -1: forever; 1,2,3... - number of times (the default is 5 packets)') - - parser.add_option('-P', '--polling-timeout', - dest='polling_timeout', - default=60, - metavar="NUMBER", - type="int", - help='Timeout in sec for readiness of mount point and serial port of local or remote device. Default 60 sec') - - parser.add_option('', '--tag-filters', - dest='tags', - default=None, - help='Filter list of available devices under test to only run on devices with the provided list of tags [tag-filters tag1,tag]') - - parser.add_option('', '--lock', - dest='lock_by_target', - default=False, - action="store_true", - help='Use simple resource locking mechanism to run multiple application instances') - - parser.add_option('', '--digest', - dest='digest_source', - help='Redirect input from where test suite should take console input. You can use stdin or file name to get test case console output') - - parser.add_option('-H', '--hooks', - dest='hooks_json', - help='Load hooks used drive extra functionality') - - parser.add_option('', '--test-spec', - dest='test_spec', - help='Test specification generated by build system.') - - parser.add_option('', '--test-cfg', - dest='json_test_configuration', - help='Pass to host test data with host test configuration') - - parser.add_option('', '--run', - dest='run_app', - help='Flash, reset and dump serial from selected binary application') - - parser.add_option('', '--report-junit', - dest='report_junit_file_name', - help='You can log test suite results in form of JUnit compliant XML report') - - parser.add_option('', '--report-text', - dest='report_text_file_name', - help='You can log test suite results to text file') - - parser.add_option('', '--report-json', - dest='report_json_file_name', - help='You can log test suite results to JSON formatted file') - - parser.add_option('', '--report-html', - dest='report_html_file_name', - help='You can log test suite results in the form of a HTML page') - - parser.add_option('', '--report-fails', - dest='report_fails', - default=False, - action="store_true", - help='Prints console outputs for failed tests') - - parser.add_option('', '--retry-count', - dest='retry_count', - default=1, - type=int, - help='retry count for individual test failure. By default, there is no retry') - - parser.add_option('', '--report-memory-metrics-csv', - dest='report_memory_metrics_csv_file_name', - help='You can log test suite memory metrics in the form of a CSV file') - - parser.add_option('', '--yotta-registry', - dest='yotta_search_for_mbed_target', - default=False, - action="store_true", - help='Use on-line yotta registry to search for compatible with connected mbed devices yotta targets. Default: search is done in yotta_targets directory') - - parser.add_option('-V', '--verbose-test-result', - dest='verbose_test_result_only', - default=False, - action="store_true", - help='Prints test serial output') - - parser.add_option('-v', '--verbose', - dest='verbose', - default=False, - action="store_true", - help='Verbose mode (prints some extra information)') - - parser.add_option('', '--plain', - dest='plain', - default=False, - action="store_true", - help='Do not use colours while logging') - - parser.add_option('', '--version', - dest='version', - default=False, - action="store_true", - help='Prints package version and exits') - - parser.description = """This automated test script is used to test mbed SDK 3.0 on mbed-enabled devices with support from yotta build tool""" - parser.epilog = """Example: mbedgt --target frdm-k64f-gcc""" - - (opts, args) = parser.parse_args() - - cli_ret = 0 - - if not opts.version: - # This string should not appear when fetching plain version string - gt_logger.gt_log(get_hello_string()) - - start = time() - if opts.lock_by_target: - # We are using Greentea proprietary locking mechanism to lock between platforms and targets - gt_logger.gt_log("using (experimental) simple locking mechanism") - gt_logger.gt_log_tab("kettle: %s"% GREENTEA_KETTLE_PATH) - gt_file_sem, gt_file_sem_name, gt_instance_uuid = greentea_get_app_sem() - with gt_file_sem: - greentea_update_kettle(gt_instance_uuid) - try: - cli_ret = main_cli(opts, args, gt_instance_uuid) - except KeyboardInterrupt: - greentea_clean_kettle(gt_instance_uuid) - gt_logger.gt_log_err("ctrl+c keyboard interrupt!") - return 1 # Keyboard interrupt - except: - greentea_clean_kettle(gt_instance_uuid) - gt_logger.gt_log_err("unexpected error:") - gt_logger.gt_log_tab(sys.exc_info()[0]) - raise - greentea_clean_kettle(gt_instance_uuid) - else: - # Standard mode of operation - # Other instance must provide mutually exclusive access control to platforms and targets - try: - cli_ret = main_cli(opts, args) - except KeyboardInterrupt: - gt_logger.gt_log_err("ctrl+c keyboard interrupt!") - return 1 # Keyboard interrupt - except Exception as e: - gt_logger.gt_log_err("unexpected error:") - gt_logger.gt_log_tab(str(e)) - raise - - if not any([opts.list_binaries, opts.version]): - delta = time() - start # Test execution time delta - gt_logger.gt_log("completed in %.2f sec"% delta) - - if cli_ret: - if cli_ret < 0 or cli_ret > 255: - cli_ret = 1 - gt_logger.gt_log_err("exited with code %d"% cli_ret) - - return(cli_ret) - -def run_test_thread(test_result_queue, test_queue, opts, mut, build, build_path, greentea_hooks): - test_exec_retcode = 0 - test_platforms_match = 0 - test_report = {} - - disk = mut['mount_point'] - # Set serial portl format used by mbedhtrun: 'serial_port' = ':' - port = "{}:{}".format(mut['serial_port'],mut['baud_rate']) - micro = mut['platform_name'] - program_cycle_s = get_platform_property(micro, "program_cycle_s") - forced_reset_timeout = get_platform_property(micro, "forced_reset_timeout") - copy_method = get_platform_property(micro, "copy_method") - reset_method = get_platform_property(micro, "reset_method") - - while not test_queue.empty(): - try: - test = test_queue.get(False) - except Exception as e: - gt_logger.gt_log_err(str(e)) - break - - test_result = 'SKIPPED' - - if opts.copy_method: - copy_method = opts.copy_method - elif not copy_method: - copy_method = 'shell' - - if opts.reset_method: - reset_method = opts.reset_method - - verbose = opts.verbose_test_result_only - enum_host_tests_path = get_local_host_tests_dir(opts.enum_host_tests) - - test_platforms_match += 1 - host_test_result = run_host_test(test['image_path'], - disk, - port, - build_path, - mut['target_id'], - micro=micro, - copy_method=copy_method, - reset=reset_method, - program_cycle_s=program_cycle_s, - forced_reset_timeout=forced_reset_timeout, - digest_source=opts.digest_source, - json_test_cfg=opts.json_test_configuration, - enum_host_tests_path=enum_host_tests_path, - global_resource_mgr=opts.global_resource_mgr, - fast_model_connection=opts.fast_model_connection, - compare_log=test['compare_log'], - num_sync_packtes=opts.num_sync_packtes, - tags=opts.tags, - retry_count=opts.retry_count, - polling_timeout=opts.polling_timeout, - verbose=verbose) - - # Some error in htrun, abort test execution - if isinstance(host_test_result, int): - # int(host_test_result) > 0 - Call to mbedhtrun failed - # int(host_test_result) < 0 - Something went wrong while executing mbedhtrun - gt_logger.gt_log_err("run_test_thread.run_host_test() failed, aborting...") - break - - # If execution was successful 'run_host_test' return tuple with results - single_test_result, single_test_output, single_testduration, single_timeout, result_test_cases, test_cases_summary, memory_metrics = host_test_result - test_result = single_test_result - - build_path_abs = os.path.abspath(build_path) - - if single_test_result != TEST_RESULT_OK: - test_exec_retcode += 1 - - if single_test_result in [TEST_RESULT_OK, TEST_RESULT_FAIL]: - if greentea_hooks: - # Test was successful - # We can execute test hook just after test is finished ('hook_test_end') - format = { - "test_name": test['test_bin'], - "test_bin_name": os.path.basename(test['image_path']), - "image_path": test['image_path'], - "build_path": build_path, - "build_path_abs": build_path_abs, - "build_name": build, - } - greentea_hooks.run_hook_ext('hook_test_end', format) - - # Update report for optional reporting feature - test_suite_name = test['test_bin'].lower() - if build not in test_report: - test_report[build] = {} - - if test_suite_name not in test_report[build]: - test_report[build][test_suite_name] = {} - - if not test_cases_summary and not result_test_cases: - gt_logger.gt_log_warn("test case summary event not found") - gt_logger.gt_log_tab("no test case report present, assuming test suite to be a single test case!") - - # We will map test suite result to test case to - # output valid test case in report - - # Generate "artificial" test case name from test suite name# - # E.g: - # mbed-drivers-test-dev_null -> dev_null - test_case_name = test_suite_name - test_str_idx = test_suite_name.find("-test-") - if test_str_idx != -1: - test_case_name = test_case_name[test_str_idx + 6:] - - gt_logger.gt_log_tab("test suite: %s"% test_suite_name) - gt_logger.gt_log_tab("test case: %s"% test_case_name) - - # Test case result: OK, FAIL or ERROR - tc_result_text = { - "OK": "OK", - "FAIL": "FAIL", - }.get(single_test_result, 'ERROR') - - # Test case integer success code OK, FAIL and ERROR: (0, >0, <0) - tc_result = { - "OK": 0, - "FAIL": 1024, - "ERROR": -1024, - }.get(tc_result_text, '-2048') - - # Test case passes and failures: (1 pass, 0 failures) or (0 passes, 1 failure) - tc_passed, tc_failed = { - 0: (1, 0), - }.get(tc_result, (0, 1)) - - # Test case report build for whole binary - # Add test case made from test suite result to test case report - result_test_cases = { - test_case_name: { - 'duration': single_testduration, - 'time_start': 0.0, - 'time_end': 0.0, - 'utest_log': single_test_output.splitlines(), - 'result_text': tc_result_text, - 'passed': tc_passed, - 'failed': tc_failed, - 'result': tc_result, - } - } - - # Test summary build for whole binary (as a test case) - test_cases_summary = (tc_passed, tc_failed, ) - - gt_logger.gt_log("test on hardware with target id: %s"% (mut['target_id'])) - gt_logger.gt_log("test suite '%s' %s %s in %.2f sec"% (test['test_bin'], - '.' * (80 - len(test['test_bin'])), - test_result, - single_testduration)) - - # Test report build for whole binary - test_report[build][test_suite_name]['single_test_result'] = single_test_result - test_report[build][test_suite_name]['single_test_output'] = single_test_output - test_report[build][test_suite_name]['elapsed_time'] = single_testduration - test_report[build][test_suite_name]['platform_name'] = micro - test_report[build][test_suite_name]['copy_method'] = copy_method - test_report[build][test_suite_name]['testcase_result'] = result_test_cases - test_report[build][test_suite_name]['memory_metrics'] = memory_metrics - - test_report[build][test_suite_name]['build_path'] = build_path - test_report[build][test_suite_name]['build_path_abs'] = build_path_abs - test_report[build][test_suite_name]['image_path'] = test['image_path'] - test_report[build][test_suite_name]['test_bin_name'] = os.path.basename(test['image_path']) - - passes_cnt, failures_cnt = 0, 0 - for tc_name in sorted(result_test_cases.keys()): - gt_logger.gt_log_tab("test case: '%s' %s %s in %.2f sec"% (tc_name, - '.' * (80 - len(tc_name)), - result_test_cases[tc_name].get('result_text', '_'), - result_test_cases[tc_name].get('duration', 0.0))) - if result_test_cases[tc_name].get('result_text', '_') == 'OK': - passes_cnt += 1 - else: - failures_cnt += 1 - - if test_cases_summary: - passes, failures = test_cases_summary - gt_logger.gt_log("test case summary: %d pass%s, %d failur%s"% (passes, - '' if passes == 1 else 'es', - failures, - 'e' if failures == 1 else 'es')) - if passes != passes_cnt or failures != failures_cnt: - gt_logger.gt_log_err("utest test case summary mismatch: utest reported passes and failures miscount!") - gt_logger.gt_log_tab("reported by utest: passes = %d, failures %d)"% (passes, failures)) - gt_logger.gt_log_tab("test case result count: passes = %d, failures %d)"% (passes_cnt, failures_cnt)) - - if single_test_result != 'OK' and not verbose and opts.report_fails: - # In some cases we want to print console to see why test failed - # even if we are not in verbose mode - gt_logger.gt_log_tab("test failed, reporting console output (specified with --report-fails option)") - print() - print(single_test_output) - - #greentea_release_target_id(mut['target_id'], gt_instance_uuid) - test_result_queue.put({'test_platforms_match': test_platforms_match, - 'test_exec_retcode': test_exec_retcode, - 'test_report': test_report}) - return - -def main_cli(opts, args, gt_instance_uuid=None): - """! This is main CLI function with all command line parameters - @details This function also implements CLI workflow depending on CLI parameters inputed - @return This function doesn't return, it exits to environment with proper success code - """ - - def filter_ready_devices(mbeds_list): - """! Filters list of MUTs to check if all MUTs are correctly detected with mbed-ls module. - @details This function logs a lot to help users figure out root cause of their problems - @param mbeds_list List of MUTs to verify - @return Tuple of (MUTS detected correctly, MUTs not detected fully) - """ - ready_mbed_devices = [] # Devices which can be used (are fully detected) - not_ready_mbed_devices = [] # Devices which can't be used (are not fully detected) - - required_mut_props = ['target_id', 'platform_name', 'serial_port', 'mount_point'] - - gt_logger.gt_log("detected %d device%s"% (len(mbeds_list), 's' if len(mbeds_list) != 1 else '')) - for mut in mbeds_list: - for prop in required_mut_props: - if not mut[prop]: - # Adding MUT to NOT DETECTED FULLY list - if mut not in not_ready_mbed_devices: - not_ready_mbed_devices.append(mut) - gt_logger.gt_log_err("mbed-ls was unable to enumerate correctly all properties of the device!") - gt_logger.gt_log_tab("check with 'mbedls -j' command if all properties of your device are enumerated properly") - - gt_logger.gt_log_err("mbed-ls property '%s' is '%s'"% (prop, str(mut[prop]))) - if prop == 'serial_port': - gt_logger.gt_log_tab("check if your serial port driver is correctly installed!") - if prop == 'mount_point': - gt_logger.gt_log_tab('check if your OS can detect and mount mbed device mount point!') - else: - # Adding MUT to DETECTED CORRECTLY list - ready_mbed_devices.append(mut) - return (ready_mbed_devices, not_ready_mbed_devices) - - def get_parallel_value(value): - """! Get correct value for parallel switch (--parallel) - @param value Value passed from --parallel - @return Refactored version of parallel number - """ - try: - parallel_test_exec = int(value) - if parallel_test_exec < 1: - parallel_test_exec = 1 - except ValueError: - gt_logger.gt_log_err("argument of mode --parallel is not a int, disabled parallel mode") - parallel_test_exec = 1 - return parallel_test_exec - - # This is how you magically control colours in this piece of art software - gt_logger.colorful(not opts.plain) - - # Prints version and exits - if opts.version: - print_version() - return (0) - - # Load test specification or print warnings / info messages and exit CLI mode - test_spec, ret = get_test_spec(opts) - if not test_spec: - return ret - - # Verbose flag - verbose = opts.verbose_test_result_only - - # We will load hooks from JSON file to support extra behaviour during test execution - greentea_hooks = GreenteaHooks(opts.hooks_json) if opts.hooks_json else None - - # Capture alternative test console inputs, used e.g. in 'yotta test command' - if opts.digest_source: - enum_host_tests_path = get_local_host_tests_dir(opts.enum_host_tests) - host_test_result = run_host_test(None, - None, - None, - None, - None, - digest_source=opts.digest_source, - enum_host_tests_path=enum_host_tests_path, - verbose=verbose) - - # Some error in htrun, abort test execution - if isinstance(host_test_result, int): - # int(host_test_result) > 0 - Call to mbedhtrun failed - # int(host_test_result) < 0 - Something went wrong while executing mbedhtrun - return host_test_result - - # If execution was successful 'run_host_test' return tuple with results - single_test_result, single_test_output, single_testduration, single_timeout, result_test_cases, test_cases_summary, memory_metrics = host_test_result - status = TEST_RESULTS.index(single_test_result) if single_test_result in TEST_RESULTS else -1 - return (status) - - ### Query with mbedls for available mbed-enabled devices - gt_logger.gt_log("detecting connected mbed-enabled devices...") - - ### check if argument of --parallel mode is a integer and greater or equal 1 - parallel_test_exec = get_parallel_value(opts.parallel_test_exec) - - # Detect devices connected to system - mbeds = mbed_os_tools.detect.create() - mbeds_list = mbeds.list_mbeds(unique_names=True, read_details_txt=True) - - if opts.global_resource_mgr: - # Mocking available platform requested by --grm switch - grm_values = parse_global_resource_mgr(opts.global_resource_mgr) - if grm_values: - gt_logger.gt_log_warn("entering global resource manager mbed-ls dummy mode!") - grm_platform_name, grm_module_name, grm_ip_name, grm_port_name = grm_values - mbeds_list = [] - if grm_platform_name == '*': - required_devices = [tb.get_platform() for tb in test_spec.get_test_builds()] - for _ in range(parallel_test_exec): - for device in required_devices: - mbeds_list.append(mbeds.get_dummy_platform(device)) - else: - for _ in range(parallel_test_exec): - mbeds_list.append(mbeds.get_dummy_platform(grm_platform_name)) - opts.global_resource_mgr = ':'.join([v for v in grm_values[1:] if v]) - gt_logger.gt_log_tab("adding dummy platform '%s'"% grm_platform_name) - else: - gt_logger.gt_log("global resource manager switch '--grm %s' in wrong format!"% opts.global_resource_mgr) - return (-1) - - if opts.fast_model_connection: - # Mocking available platform requested by --fm switch - fm_values = parse_fast_model_connection(opts.fast_model_connection) - if fm_values: - gt_logger.gt_log_warn("entering fastmodel connection, mbed-ls dummy simulator mode!") - fm_platform_name, fm_config_name = fm_values - mbeds_list = [] - for _ in range(parallel_test_exec): - mbeds_list.append(mbeds.get_dummy_platform(fm_platform_name)) - opts.fast_model_connection = fm_config_name - gt_logger.gt_log_tab("adding dummy fastmodel platform '%s'"% fm_platform_name) - else: - gt_logger.gt_log("fast model connection switch '--fm %s' in wrong format!"% opts.fast_model_connection) - return (-1) - - ready_mbed_devices = [] # Devices which can be used (are fully detected) - not_ready_mbed_devices = [] # Devices which can't be used (are not fully detected) - - if mbeds_list: - ready_mbed_devices, not_ready_mbed_devices = filter_ready_devices(mbeds_list) - if ready_mbed_devices: - # devices in form of a pretty formatted table - for line in log_mbed_devices_in_table(ready_mbed_devices).splitlines(): - gt_logger.gt_log_tab(line.strip(), print_text=verbose) - else: - gt_logger.gt_log_err("no compatible devices detected") - return (RET_NO_DEVICES) - - ### We can filter in only specific target ids - accepted_target_ids = None - if opts.use_target_ids: - gt_logger.gt_log("filtering out target ids not on below list (specified with --use-tids switch)") - accepted_target_ids = opts.use_target_ids.split(',') - for tid in accepted_target_ids: - gt_logger.gt_log_tab("accepting target id '%s'"% gt_logger.gt_bright(tid)) - - test_exec_retcode = 0 # Decrement this value each time test case result is not 'OK' - test_platforms_match = 0 # Count how many tests were actually ran with current settings - target_platforms_match = 0 # Count how many platforms were actually tested with current settings - - test_report = {} # Test report used to export to Junit, HTML etc... - test_queue = Queue() # contains information about test_bin and image_path for each test case - test_result_queue = Queue() # used to store results of each thread - execute_threads = [] # list of threads to run test cases - - # Values used to generate random seed for test execution order shuffle - SHUFFLE_SEED_ROUND = 10 # Value used to round float random seed - shuffle_random_seed = round(random.random(), SHUFFLE_SEED_ROUND) - - # Set shuffle seed if it is provided with command line option - if opts.shuffle_test_seed: - shuffle_random_seed = round(float(opts.shuffle_test_seed), SHUFFLE_SEED_ROUND) - - ### Testing procedures, for each target, for each target's compatible platform - # In case we are using test spec (switch --test-spec) command line option -t - # is used to enumerate builds from test spec we are supplying - filter_test_builds = opts.list_of_targets.split(',') if opts.list_of_targets else None - for test_build in test_spec.get_test_builds(filter_test_builds): - platform_name = test_build.get_platform() - gt_logger.gt_log("processing target '%s' toolchain '%s' compatible platforms... (note: switch set to --parallel %d)" % - (gt_logger.gt_bright(platform_name), - gt_logger.gt_bright(test_build.get_toolchain()), - int(opts.parallel_test_exec))) - - baudrate = test_build.get_baudrate() - - ### Select MUTS to test from list of available MUTS to start testing - mut = None - number_of_parallel_instances = 1 - muts_to_test = [] # MUTs to actually be tested - for mbed_dev in ready_mbed_devices: - if accepted_target_ids and mbed_dev['target_id'] not in accepted_target_ids: - continue - - # Check that we have a valid serial port detected. - sp = mbed_dev['serial_port'] - if not sp: - gt_logger.gt_log_err("Serial port for target %s not detected correctly\n" % mbed_dev['target_id']) - continue - - if mbed_dev['platform_name'] == platform_name: - mbed_dev['baud_rate'] = baudrate - - mut = mbed_dev - if mbed_dev not in muts_to_test: - # We will only add unique devices to list of devices "for testing" in this test run - muts_to_test.append(mbed_dev) - if number_of_parallel_instances < parallel_test_exec: - number_of_parallel_instances += 1 - else: - break - - # devices in form of a pretty formatted table - for line in log_mbed_devices_in_table(muts_to_test).splitlines(): - gt_logger.gt_log_tab(line.strip(), print_text=verbose) - - # Configuration print mode: - if opts.verbose_test_configuration_only: - continue - - ### If we have at least one available device we can proceed - if mut: - target_platforms_match += 1 - - build = test_build.get_name() - build_path = test_build.get_path() - - # Demo mode: --run implementation (already added --run to mbedhtrun) - # We want to pass file name to mbedhtrun (--run NAME => -f NAME_ and run only one binary - if opts.run_app: - gt_logger.gt_log("running '%s' for '%s'-'%s'" % (gt_logger.gt_bright(opts.run_app), - gt_logger.gt_bright(platform_name), - gt_logger.gt_bright(test_build.get_toolchain()))) - disk = mut['mount_point'] - # Set serial portl format used by mbedhtrun: 'serial_port' = ':' - port = "{}:{}".format(mut['serial_port'], mut['baud_rate']) - micro = mut['platform_name'] - program_cycle_s = get_platform_property(micro, "program_cycle_s") - copy_method = opts.copy_method if opts.copy_method else 'shell' - enum_host_tests_path = get_local_host_tests_dir(opts.enum_host_tests) - - test_platforms_match += 1 - host_test_result = run_host_test(opts.run_app, - disk, - port, - build_path, - mut['target_id'], - micro=micro, - copy_method=copy_method, - program_cycle_s=program_cycle_s, - digest_source=opts.digest_source, - json_test_cfg=opts.json_test_configuration, - run_app=opts.run_app, - enum_host_tests_path=enum_host_tests_path, - verbose=True) - - # Some error in htrun, abort test execution - if isinstance(host_test_result, int): - # int(host_test_result) > 0 - Call to mbedhtrun failed - # int(host_test_result) < 0 - Something went wrong while executing mbedhtrun - return host_test_result - - # If execution was successful 'run_host_test' return tuple with results - single_test_result, single_test_output, single_testduration, single_timeout, result_test_cases, test_cases_summary, memory_metrics = host_test_result - status = TEST_RESULTS.index(single_test_result) if single_test_result in TEST_RESULTS else -1 - if single_test_result != TEST_RESULT_OK: - test_exec_retcode += 1 - - test_list = test_build.get_tests() - - filtered_ctest_test_list = create_filtered_test_list(test_list, opts.test_by_names, opts.skip_test, test_spec=test_spec) - - gt_logger.gt_log("running %d test%s for platform '%s' and toolchain '%s'"% ( - len(filtered_ctest_test_list), - "s" if len(filtered_ctest_test_list) != 1 else "", - gt_logger.gt_bright(platform_name), - gt_logger.gt_bright(test_build.get_toolchain()) - )) - - # Test execution order can be shuffled (also with provided random seed) - # for test execution reproduction. - filtered_ctest_test_list_keys = filtered_ctest_test_list.keys() - if opts.shuffle_test_order: - # We want to shuffle test names randomly - random.shuffle(filtered_ctest_test_list_keys, lambda: shuffle_random_seed) - - for test_name in filtered_ctest_test_list_keys: - image_path = filtered_ctest_test_list[test_name].get_binary(binary_type=TestBinary.BIN_TYPE_BOOTABLE).get_path() - compare_log = filtered_ctest_test_list[test_name].get_binary(binary_type=TestBinary.BIN_TYPE_BOOTABLE).get_compare_log() - if image_path is None: - gt_logger.gt_log_err("Failed to find test binary for test %s flash method %s" % (test_name, 'usb')) - else: - test = {"test_bin": test_name, "image_path": image_path, "compare_log": compare_log} - test_queue.put(test) - - number_of_threads = 0 - for mut in muts_to_test: - # Experimental, parallel test execution - if number_of_threads < parallel_test_exec: - args = (test_result_queue, test_queue, opts, mut, build, build_path, greentea_hooks) - t = Thread(target=run_test_thread, args=args) - execute_threads.append(t) - number_of_threads += 1 - - gt_logger.gt_log_tab("use %s instance%s of execution threads for testing"% (len(execute_threads), - 's' if len(execute_threads) != 1 else str()), print_text=verbose) - for t in execute_threads: - t.daemon = True - t.start() - - # merge partial test reports from different threads to final test report - for t in execute_threads: - try: - # We can't block forever here since that prevents KeyboardInterrupts - # from being propagated correctly. Therefore, we just join with a - # timeout of 0.1 seconds until the thread isn't alive anymore. - # A time of 0.1 seconds is a fairly arbitrary choice. It needs - # to balance CPU utilization and responsiveness to keyboard interrupts. - # Checking 10 times a second seems to be stable and responsive. - while t.is_alive(): - t.join(0.1) - - test_return_data = test_result_queue.get(False) - except Exception as e: - # No test report generated - gt_logger.gt_log_err("could not generate test report" + str(e)) - test_exec_retcode += -1000 - return test_exec_retcode - - test_platforms_match += test_return_data['test_platforms_match'] - test_exec_retcode += test_return_data['test_exec_retcode'] - partial_test_report = test_return_data['test_report'] - # todo: find better solution, maybe use extend - for report_key in partial_test_report.keys(): - if report_key not in test_report: - test_report[report_key] = {} - test_report.update(partial_test_report) - else: - test_report[report_key].update(partial_test_report[report_key]) - - execute_threads = [] - - if opts.verbose_test_configuration_only: - print("Example: execute 'mbedgt --target=TARGET_NAME' to start testing for TARGET_NAME target") - return (0) - - gt_logger.gt_log("all tests finished!") - - # We will execute post test hooks on tests - for build_name in test_report: - test_name_list = [] # All test case names for particular yotta target - for test_name in test_report[build_name]: - test = test_report[build_name][test_name] - # Test was successful - if test['single_test_result'] in [TEST_RESULT_OK, TEST_RESULT_FAIL]: - test_name_list.append(test_name) - # Call hook executed for each test, just after all tests are finished - if greentea_hooks: - # We can execute this test hook just after all tests are finished ('hook_post_test_end') - format = { - "test_name": test_name, - "test_bin_name": test['test_bin_name'], - "image_path": test['image_path'], - "build_path": test['build_path'], - "build_path_abs": test['build_path_abs'], - } - greentea_hooks.run_hook_ext('hook_post_test_end', format) - if greentea_hooks: - build = test_spec.get_test_build(build_name) - assert build is not None, "Failed to find build info for build %s" % build_name - - # Call hook executed for each yotta target, just after all tests are finished - build_path = build.get_path() - build_path_abs = os.path.abspath(build_path) - # We can execute this test hook just after all tests are finished ('hook_post_test_end') - format = { - "build_path": build_path, - "build_path_abs": build_path_abs, - "test_name_list": test_name_list, - } - greentea_hooks.run_hook_ext('hook_post_all_test_end', format) - - # This tool is designed to work in CI - # We want to return success codes based on tool actions, - # only if testes were executed and all passed we want to - # return 0 (success) - if not opts.only_build_tests: - # Prints shuffle seed - gt_logger.gt_log("shuffle seed: %.*f"% (SHUFFLE_SEED_ROUND, shuffle_random_seed)) - - def dump_report_to_text_file(filename, content): - """! Closure for report dumps to text files - @param filename Name of destination file - @parm content Text content of the file to write - @return True if write was successful, else return False - """ - try: - with io.open(filename, encoding="utf-8", errors="backslashreplace", mode="w") as f: - f.write(content) - except IOError as e: - gt_logger.gt_log_err("can't export to '%s', reason:"% filename) - gt_logger.gt_log_err(str(e)) - return False - return True - - # Reports to JUNIT file - if opts.report_junit_file_name: - gt_logger.gt_log("exporting to JUNIT file '%s'..."% gt_logger.gt_bright(opts.report_junit_file_name)) - # This test specification will be used by JUnit exporter to populate TestSuite.properties (useful meta-data for Viewer) - test_suite_properties = {} - for target_name in test_report: - test_build_properties = get_test_build_properties(test_spec, target_name) - if test_build_properties: - test_suite_properties[target_name] = test_build_properties - junit_report = exporter_testcase_junit(test_report, test_suite_properties = test_suite_properties) - dump_report_to_text_file(opts.report_junit_file_name, junit_report) - - # Reports to text file - if opts.report_text_file_name: - gt_logger.gt_log("exporting to TEXT '%s'..."% gt_logger.gt_bright(opts.report_text_file_name)) - # Useful text reporter for those who do not like to copy paste to files tabale with results - text_report, text_results = exporter_text(test_report) - text_testcase_report, text_testcase_results = exporter_testcase_text(test_report) - text_final_report = '\n'.join([text_report, text_results, text_testcase_report, text_testcase_results]) - dump_report_to_text_file(opts.report_text_file_name, text_final_report) - - # Reports to JSON file - if opts.report_json_file_name: - # We will not print summary and json report together - gt_logger.gt_log("exporting to JSON '%s'..."% gt_logger.gt_bright(opts.report_json_file_name)) - json_report = exporter_json(test_report) - dump_report_to_text_file(opts.report_json_file_name, json_report) - - # Reports to HTML file - if opts.report_html_file_name: - gt_logger.gt_log("exporting to HTML file '%s'..."% gt_logger.gt_bright(opts.report_html_file_name)) - # Generate a HTML page displaying all of the results - html_report = exporter_html(test_report) - dump_report_to_text_file(opts.report_html_file_name, html_report) - - # Memory metrics to CSV file - if opts.report_memory_metrics_csv_file_name: - gt_logger.gt_log("exporting memory metrics to CSV file '%s'..."% gt_logger.gt_bright(opts.report_memory_metrics_csv_file_name)) - # Generate a CSV file page displaying all memory metrics - memory_metrics_csv_report = exporter_memory_metrics_csv(test_report) - dump_report_to_text_file(opts.report_memory_metrics_csv_file_name, memory_metrics_csv_report) - - # Final summary - if test_report: - # Test suite report - gt_logger.gt_log("test suite report:") - text_report, text_results = exporter_text(test_report) - print(text_report) - gt_logger.gt_log("test suite results: " + text_results) - # test case detailed report - gt_logger.gt_log("test case report:") - text_testcase_report, text_testcase_results = exporter_testcase_text(test_report) - print(text_testcase_report) - gt_logger.gt_log("test case results: " + text_testcase_results) - - # This flag guards 'build only' so we expect only yotta errors - if test_platforms_match == 0: - # No tests were executed - gt_logger.gt_log_warn("no platform/target matching tests were found!") - if target_platforms_match == 0: - # No platforms were tested - gt_logger.gt_log_warn("no matching platforms were found!") - - return (test_exec_retcode) diff --git a/tools/python/mbed_greentea/mbed_greentea_dlm.py b/tools/python/mbed_greentea/mbed_greentea_dlm.py deleted file mode 100644 index 653c4991b2d..00000000000 --- a/tools/python/mbed_greentea/mbed_greentea_dlm.py +++ /dev/null @@ -1,37 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_greentea_dlm import ( - HOME_DIR, - GREENTEA_HOME_DIR, - GREENTEA_GLOBAL_LOCK, - GREENTEA_KETTLE, - GREENTEA_KETTLE_PATH, - greentea_home_dir_init, - greentea_get_app_sem, - greentea_get_target_lock, - greentea_get_global_lock, - greentea_update_kettle, - greentea_clean_kettle, - greentea_acquire_target_id, - greentea_acquire_target_id_from_list, - greentea_release_target_id, - get_json_data_from_file, - greentea_kettle_info, -) diff --git a/tools/python/mbed_greentea/mbed_greentea_hooks.py b/tools/python/mbed_greentea/mbed_greentea_hooks.py deleted file mode 100644 index d608d5c7750..00000000000 --- a/tools/python/mbed_greentea/mbed_greentea_hooks.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_greentea_hooks import ( - GreenteaTestHook, - GreenteaCliTestHook, - LcovHook, - GreenteaHooks, -) diff --git a/tools/python/mbed_greentea/mbed_greentea_log.py b/tools/python/mbed_greentea/mbed_greentea_log.py deleted file mode 100644 index 8fa6f526053..00000000000 --- a/tools/python/mbed_greentea/mbed_greentea_log.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_greentea_log import ( - COLORAMA, - GreenTeaSimpleLockLogger, - gt_logger, -) diff --git a/tools/python/mbed_greentea/mbed_report_api.py b/tools/python/mbed_greentea/mbed_report_api.py deleted file mode 100644 index e10d72dbe37..00000000000 --- a/tools/python/mbed_greentea/mbed_report_api.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_report_api import ( - export_to_file, - exporter_json, - exporter_text, - exporter_testcase_text, - exporter_testcase_junit, - html_template, - TEST_RESULT_COLOURS, - TEST_RESULT_DEFAULT_COLOUR, - get_result_colour_class_css, - get_result_colour_class, - get_dropdown_html, - get_result_overlay_testcase_dropdown, - get_result_overlay_testcases_dropdown_menu, - get_result_overlay_dropdowns, - get_result_overlay, - exporter_html, - exporter_memory_metrics_csv, -) diff --git a/tools/python/mbed_greentea/mbed_target_info.py b/tools/python/mbed_greentea/mbed_target_info.py deleted file mode 100644 index 818df529732..00000000000 --- a/tools/python/mbed_greentea/mbed_target_info.py +++ /dev/null @@ -1,36 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_target_info import ( - TARGET_INFO_MAPPING, - TARGET_TOOLCAHINS, - get_mbed_target_call_yotta_target, - parse_yotta_json_for_build_name, - get_yotta_target_from_local_config, - get_mbed_target_from_current_dir, - parse_yotta_target_cmd_output, - get_mbed_targets_from_yotta_local_module, - parse_mbed_target_from_target_json, - get_mbed_targets_from_yotta, - parse_yotta_search_cmd_output, - add_target_info_mapping, - get_mbed_clasic_target_info, - get_binary_type_for_platform, - get_platform_property, -) diff --git a/tools/python/mbed_greentea/mbed_test_api.py b/tools/python/mbed_greentea/mbed_test_api.py deleted file mode 100644 index c11c5f3eb0c..00000000000 --- a/tools/python/mbed_greentea/mbed_test_api.py +++ /dev/null @@ -1,267 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" -import os -from time import time - -from mbed_os_tools.test.mbed_test_api import ( - TEST_RESULT_OK, - TEST_RESULT_FAIL, - TEST_RESULT_ERROR, - TEST_RESULT_SKIPPED, - TEST_RESULT_UNDEF, - TEST_RESULT_IOERR_COPY, - TEST_RESULT_IOERR_DISK, - TEST_RESULT_IOERR_SERIAL, - TEST_RESULT_TIMEOUT, - TEST_RESULT_NO_IMAGE, - TEST_RESULT_MBED_ASSERT, - TEST_RESULT_BUILD_FAILED, - TEST_RESULT_SYNC_FAILED, - TEST_RESULTS, - TEST_RESULT_MAPPING, - RUN_HOST_TEST_POPEN_ERROR, - get_test_result, - run_command, - run_htrun, - get_testcase_count_and_names, - get_testcase_utest, - get_coverage_data, - get_printable_string, - get_testcase_summary, - get_testcase_result, - get_memory_metrics, - get_thread_with_max_stack_size, - get_thread_stack_info_summary, - log_mbed_devices_in_table, - get_test_spec, - get_test_build_properties, - parse_global_resource_mgr, - parse_fast_model_connection, - gt_logger, -) - -def run_host_test(image_path, - disk, - port, - build_path, - target_id, - duration=10, - micro=None, - reset=None, - verbose=False, - copy_method=None, - program_cycle_s=None, - forced_reset_timeout=None, - digest_source=None, - json_test_cfg=None, - max_failed_properties=5, - enum_host_tests_path=None, - global_resource_mgr=None, - fast_model_connection=None, - compare_log=None, - num_sync_packtes=None, - polling_timeout=None, - retry_count=1, - tags=None, - run_app=None): - """! This function runs host test supervisor (executes mbedhtrun) and checks output from host test process. - @param image_path Path to binary file for flashing - @param disk Currently mounted mbed-enabled devices disk (mount point) - @param port Currently mounted mbed-enabled devices serial port (console) - @param duration Test case timeout - @param micro Mbed-enabled device name - @param reset Reset type - @param forced_reset_timeout Reset timeout (sec) - @param verbose Verbose mode flag - @param copy_method Copy method type (name) - @param program_cycle_s Wait after flashing delay (sec) - @param json_test_cfg Additional test configuration file path passed to host tests in JSON format - @param max_failed_properties After how many unknown properties we will assume test is not ported - @param enum_host_tests_path Directory where locally defined host tests may reside - @param num_sync_packtes sync packets to send for host <---> device communication - @param polling_timeout Timeout in sec for readiness of mount point and serial port of local or remote device - @param tags Filter list of available devices under test to only run on devices with the provided list - of tags [tag-filters tag1,tag] - @param run_app Run application mode flag (we run application and grab serial port data) - @param digest_source if None mbedhtrun will be executed. If 'stdin', - stdin will be used via StdInObserver or file (if - file name was given as switch option) - @return Tuple with test results, test output, test duration times, test case results, and memory metrics. - Return int > 0 if running mbedhtrun process failed. - Retrun int < 0 if something went wrong during mbedhtrun execution. - """ - - def get_binary_host_tests_dir(binary_path, level=2): - """! Checks if in binary test group has host_tests directory - @param binary_path Path to binary in test specification - @param level How many directories above test host_tests dir exists - @return Path to host_tests dir in group binary belongs too, None if not found - """ - try: - binary_path_norm = os.path.normpath(binary_path) - current_path_norm = os.path.normpath(os.getcwd()) - host_tests_path = binary_path_norm.split(os.sep)[:-level] + ['host_tests'] - build_dir_candidates = ['BUILD', '.build'] - idx = None - - for build_dir_candidate in build_dir_candidates: - if build_dir_candidate in host_tests_path: - idx = host_tests_path.index(build_dir_candidate) - break - - if idx is None: - msg = 'The following directories were not in the path: %s' % (', '.join(build_dir_candidates)) - raise Exception(msg) - - # Cut //tests/TOOLCHAIN/TARGET - host_tests_path = host_tests_path[:idx] + host_tests_path[idx+4:] - host_tests_path = os.sep.join(host_tests_path) - except Exception as e: - gt_logger.gt_log_warn("there was a problem while looking for host_tests directory") - gt_logger.gt_log_tab("level %d, path: %s"% (level, binary_path)) - gt_logger.gt_log_tab(str(e)) - return None - - if os.path.isdir(host_tests_path): - return host_tests_path - return None - - if not enum_host_tests_path: - # If there is -e specified we will try to find a host_tests path ourselves - # - # * Path to binary starts from "build" directory, and goes 4 levels - # deep: ./build/tests/compiler/toolchain - # * Binary is inside test group. - # For example: /tests/test_group_name/test_dir/*,cpp. - # * We will search for directory called host_tests on the level of test group (level=2) - # or on the level of tests directory (level=3). - # - # If host_tests directory is found above test code will will pass it to mbedhtrun using - # switch -e - gt_logger.gt_log("checking for 'host_tests' directory above image directory structure", print_text=verbose) - test_group_ht_path = get_binary_host_tests_dir(image_path, level=2) - TESTS_dir_ht_path = get_binary_host_tests_dir(image_path, level=3) - if test_group_ht_path: - enum_host_tests_path = test_group_ht_path - elif TESTS_dir_ht_path: - enum_host_tests_path = TESTS_dir_ht_path - - if enum_host_tests_path: - gt_logger.gt_log_tab("found 'host_tests' directory in: '%s'"% enum_host_tests_path, print_text=verbose) - else: - gt_logger.gt_log_tab("'host_tests' directory not found: two directory levels above image path checked", print_text=verbose) - - gt_logger.gt_log("selecting test case observer...", print_text=verbose) - if digest_source: - gt_logger.gt_log_tab("selected digest source: %s"% digest_source, print_text=verbose) - - # Select who will digest test case serial port data - if digest_source == 'stdin': - # When we want to scan stdin for test results - raise NotImplementedError - elif digest_source is not None: - # When we want to open file to scan for test results - raise NotImplementedError - - # Command executing CLI for host test supervisor (in detect-mode) - cmd = ["mbedhtrun", - '-m', micro, - '-p', port, - '-f', '"%s"'% image_path, - ] - - if enum_host_tests_path: - cmd += ["-e", '"%s"'% enum_host_tests_path] - - if global_resource_mgr: - # Use global resource manager to execute test - # Example: - # $ mbedhtrun -p :9600 -f "tests-mbed_drivers-generic_tests.bin" -m K64F --grm raas_client:10.2.203.31:8000 - cmd += ['--grm', global_resource_mgr] - else: - # Use local resources to execute tests - # Add extra parameters to host_test - if disk: - cmd += ["-d", disk] - if copy_method: - cmd += ["-c", copy_method] - if target_id: - cmd += ["-t", target_id] - if reset: - cmd += ["-r", reset] - if run_app: - cmd += ["--run"] # -f stores binary name! - - if fast_model_connection: - # Use simulator resource manager to execute test - # Example: - # $ mbedhtrun -f "tests-mbed_drivers-generic_tests.elf" -m FVP_MPS2_M3 --fm DEFAULT - cmd += ['--fm', fast_model_connection] - if compare_log: - cmd += ['--compare-log', compare_log] - if program_cycle_s: - cmd += ["-C", str(program_cycle_s)] - if forced_reset_timeout: - cmd += ["-R", str(forced_reset_timeout)] - if json_test_cfg: - cmd += ["--test-cfg", '"%s"' % str(json_test_cfg)] - if num_sync_packtes: - cmd += ["--sync",str(num_sync_packtes)] - if tags: - cmd += ["--tag-filters", tags] - if polling_timeout: - cmd += ["-P", str(polling_timeout)] - - gt_logger.gt_log_tab("calling mbedhtrun: %s" % " ".join(cmd), print_text=verbose) - gt_logger.gt_log("mbed-host-test-runner: started") - - for retry in range(1, 1 + retry_count): - start_time = time() - returncode, htrun_output = run_htrun(cmd, verbose) - end_time = time() - if returncode < 0: - return returncode - elif returncode == 0: - break - gt_logger.gt_log("retry mbedhtrun {}/{}".format(retry, retry_count)) - else: - gt_logger.gt_log("{} failed after {} count".format(cmd, retry_count)) - - testcase_duration = end_time - start_time # Test case duration from reset to {end} - htrun_output = get_printable_string(htrun_output) - result = get_test_result(htrun_output) - result_test_cases = get_testcase_result(htrun_output) - test_cases_summary = get_testcase_summary(htrun_output) - max_heap, reserved_heap, thread_stack_info = get_memory_metrics(htrun_output) - - thread_stack_summary = [] - - if thread_stack_info: - thread_stack_summary = get_thread_stack_info_summary(thread_stack_info) - - memory_metrics = { - "max_heap": max_heap, - "reserved_heap": reserved_heap, - "thread_stack_info": thread_stack_info, - "thread_stack_summary": thread_stack_summary - } - get_coverage_data(build_path, htrun_output) - - gt_logger.gt_log("mbed-host-test-runner: stopped and returned '%s'"% result, print_text=verbose) - return (result, htrun_output, testcase_duration, duration, result_test_cases, test_cases_summary, memory_metrics) diff --git a/tools/python/mbed_greentea/mbed_yotta_api.py b/tools/python/mbed_greentea/mbed_yotta_api.py deleted file mode 100644 index 67b3adbf975..00000000000 --- a/tools/python/mbed_greentea/mbed_yotta_api.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_yotta_api import ( - YottaError, - build_with_yotta, - get_platform_name_from_yotta_target, - get_test_spec_from_yt_module, -) diff --git a/tools/python/mbed_greentea/mbed_yotta_module_parse.py b/tools/python/mbed_greentea/mbed_yotta_module_parse.py deleted file mode 100644 index 2733c3a79d6..00000000000 --- a/tools/python/mbed_greentea/mbed_yotta_module_parse.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Przemyslaw Wirkus -""" - -from mbed_os_tools.test.mbed_yotta_module_parse import ( - YottaConfig, - YottaModule -) diff --git a/tools/python/mbed_greentea/tests_spec.py b/tools/python/mbed_greentea/tests_spec.py deleted file mode 100644 index 93e803e9196..00000000000 --- a/tools/python/mbed_greentea/tests_spec.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Author: Azim Khan -""" - -""" -This module contains classes to represent Test Specification interface that defines the data to be generated by/from -a build system to give enough information to Greentea. -""" - -from mbed_os_tools.test.tests_spec import ( - TestBinary, - Test, - TestBuild, - TestSpec, -) diff --git a/tools/python/mbed_os_tools/test/__init__.py b/tools/python/mbed_os_tools/test/__init__.py index eca1fec65d4..b693537585f 100644 --- a/tools/python/mbed_os_tools/test/__init__.py +++ b/tools/python/mbed_os_tools/test/__init__.py @@ -22,10 +22,9 @@ """ -import imp +import importlib import sys -from optparse import OptionParser -from optparse import SUPPRESS_HELP +from argparse import ArgumentParser, SUPPRESS from . import host_tests_plugins from .host_tests_registry import HostRegistry # noqa: F401 from .host_tests import BaseHostTest, event_callback # noqa: F401 @@ -52,9 +51,9 @@ def init_host_test_cli_params(): @return Function returns 'options' object returned from OptionParser class @details Options object later can be used to populate host test selector script. """ - parser = OptionParser() + parser = ArgumentParser() - parser.add_option( + parser.add_argument( "-m", "--micro", dest="micro", @@ -62,11 +61,11 @@ def init_host_test_cli_params(): metavar="MICRO", ) - parser.add_option( + parser.add_argument( "-p", "--port", dest="port", help="Serial port of the target", metavar="PORT" ) - parser.add_option( + parser.add_argument( "-d", "--disk", dest="disk", @@ -74,7 +73,7 @@ def init_host_test_cli_params(): metavar="DISK_PATH", ) - parser.add_option( + parser.add_argument( "-t", "--target-id", dest="target_id", @@ -82,8 +81,7 @@ def init_host_test_cli_params(): metavar="TARGET_ID", ) - parser.add_option( - "", + parser.add_argument( "--sync", dest="sync_behavior", default=2, @@ -95,8 +93,7 @@ def init_host_test_cli_params(): metavar="SYNC_BEHAVIOR", ) - parser.add_option( - "", + parser.add_argument( "--sync-timeout", dest="sync_timeout", default=5, @@ -105,7 +102,7 @@ def init_host_test_cli_params(): metavar="SYNC_TIMEOUT", ) - parser.add_option( + parser.add_argument( "-f", "--image-path", dest="image_path", @@ -117,7 +114,7 @@ def init_host_test_cli_params(): host_tests_plugins.get_plugin_caps("CopyMethod") ) - parser.add_option( + parser.add_argument( "-c", "--copy", dest="copy_method", @@ -125,8 +122,7 @@ def init_host_test_cli_params(): metavar="COPY_METHOD", ) - parser.add_option( - "", + parser.add_argument( "--retry-copy", dest="retry_copy", default=3, @@ -135,8 +131,7 @@ def init_host_test_cli_params(): metavar="RETRY_COPY", ) - parser.add_option( - "", + parser.add_argument( "--tag-filters", dest="tag_filters", default="", @@ -152,14 +147,14 @@ def init_host_test_cli_params(): host_tests_plugins.get_plugin_caps("ResetMethod") ) - parser.add_option( + parser.add_argument( "-r", "--reset", dest="forced_reset_type", help="Forces different type of reset. " + reset_methods_str, ) - parser.add_option( + parser.add_argument( "-C", "--program_cycle_s", dest="program_cycle_s", @@ -168,29 +163,29 @@ def init_host_test_cli_params(): "Program cycle sleep. Define how many seconds you want wait after " "copying binary onto target (Default is 4 second)" ), - type="float", + type=float, metavar="PROGRAM_CYCLE_S", ) - parser.add_option( + parser.add_argument( "-R", "--reset-timeout", dest="forced_reset_timeout", default=1, metavar="NUMBER", - type="float", + type=float, help=( "When forcing a reset using option -r you can set up after reset " "idle delay in seconds (Default is 1 second)" ), ) - parser.add_option( + parser.add_argument( "--process-start-timeout", dest="process_start_timeout", default=60, metavar="NUMBER", - type="float", + type=float, help=( "This sets the maximum time in seconds to wait for an internal " "process to start. This mostly only affects machines under heavy " @@ -198,7 +193,7 @@ def init_host_test_cli_params(): ), ) - parser.add_option( + parser.add_argument( "-e", "--enum-host-tests", dest="enum_host_tests", @@ -207,15 +202,13 @@ def init_host_test_cli_params(): help="Define directory with local host tests", ) - parser.add_option( - "", + parser.add_argument( "--test-cfg", dest="json_test_configuration", help="Pass to host test class data about host test configuration", ) - parser.add_option( - "", + parser.add_argument( "--list", dest="list_reg_hts", default=False, @@ -223,8 +216,7 @@ def init_host_test_cli_params(): help="Prints registered host test and exits", ) - parser.add_option( - "", + parser.add_argument( "--plugins", dest="list_plugins", default=False, @@ -232,7 +224,7 @@ def init_host_test_cli_params(): help="Prints registered plugins and exits", ) - parser.add_option( + parser.add_argument( "-g", "--grm", dest="global_resource_mgr", @@ -244,17 +236,14 @@ def init_host_test_cli_params(): ) # Show --fm option only if "fm_agent" module installed + fm_help=SUPPRESS try: - imp.find_module("fm_agent") - except ImportError: - fm_help = SUPPRESS_HELP - else: - fm_help = ( - 'Fast Model connection, This option requires mbed-fastmodel-agent ' - 'module installed, list CONFIGs via "mbedfm"' - ) - parser.add_option( - "", + if importlib.util.find_spec('fm_agent') is not None: + fm_help='Fast Model connection, This option requires mbed-fastmodel-agent module installed, list CONFIGs via "mbedfm"' + except ModuleNotFoundError: + pass + + parser.add_argument( "--fm", dest="fast_model_connection", metavar="CONFIG", @@ -262,8 +251,7 @@ def init_host_test_cli_params(): help=fm_help, ) - parser.add_option( - "", + parser.add_argument( "--run", dest="run_binary", default=False, @@ -271,8 +259,7 @@ def init_host_test_cli_params(): help="Runs binary image on target (workflow: flash, reset, output console)", ) - parser.add_option( - "", + parser.add_argument( "--skip-flashing", dest="skip_flashing", default=False, @@ -280,8 +267,7 @@ def init_host_test_cli_params(): help="Skips use of copy/flash plugin. Note: target will not be reflashed", ) - parser.add_option( - "", + parser.add_argument( "--skip-reset", dest="skip_reset", default=False, @@ -289,20 +275,20 @@ def init_host_test_cli_params(): help="Skips use of reset plugin. Note: target will not be reset", ) - parser.add_option( + parser.add_argument( "-P", "--polling-timeout", dest="polling_timeout", default=60, metavar="NUMBER", - type="int", + type=int, help=( "Timeout in sec for readiness of mount point and serial port of " "local or remote device. Default 60 sec" ), ) - parser.add_option( + parser.add_argument( "-b", "--send-break", dest="send_break_cmd", @@ -314,8 +300,7 @@ def init_host_test_cli_params(): ), ) - parser.add_option( - "", + parser.add_argument( "--baud-rate", dest="baud_rate", help=( @@ -325,7 +310,7 @@ def init_host_test_cli_params(): metavar="BAUD_RATE", ) - parser.add_option( + parser.add_argument( "-v", "--verbose", dest="verbose", @@ -334,24 +319,21 @@ def init_host_test_cli_params(): help="More verbose mode", ) - parser.add_option( - "", + parser.add_argument( "--serial-output-file", dest="serial_output_file", default=None, help="Save target serial output to this file.", ) - parser.add_option( - "", + parser.add_argument( "--compare-log", dest="compare_log", default=None, help="Log file to compare with the serial output from target.", ) - parser.add_option( - "", + parser.add_argument( "--version", dest="version", default=False, @@ -359,8 +341,7 @@ def init_host_test_cli_params(): help="Prints package version and exits", ) - parser.add_option( - "", + parser.add_argument( "--format", dest="format", help="Image file format passed to pyocd (elf, bin, hex, axf...).", @@ -373,10 +354,8 @@ def init_host_test_cli_params(): """Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F""" ) - (options, _) = parser.parse_args() - if len(sys.argv) == 1: parser.print_help() sys.exit() - return options + return parser.parse_args() diff --git a/tools/python/mbed_os_tools/test/host_tests/detect_auto.py b/tools/python/mbed_os_tools/test/host_tests/detect_auto.py index 4c998cb9355..c437912e216 100644 --- a/tools/python/mbed_os_tools/test/host_tests/detect_auto.py +++ b/tools/python/mbed_os_tools/test/host_tests/detect_auto.py @@ -17,7 +17,7 @@ from .. import BaseHostTest class DetectPlatformTest(BaseHostTest): - PATTERN_MICRO_NAME = "Target '(\w+)'" + PATTERN_MICRO_NAME = r"Target '(\w+)'" re_detect_micro_name = re.compile(PATTERN_MICRO_NAME) def result(self): diff --git a/tools/python/mbed_os_tools/test/host_tests/rtc_auto.py b/tools/python/mbed_os_tools/test/host_tests/rtc_auto.py index 8cf2848b58b..4a87b209ac3 100644 --- a/tools/python/mbed_os_tools/test/host_tests/rtc_auto.py +++ b/tools/python/mbed_os_tools/test/host_tests/rtc_auto.py @@ -18,7 +18,7 @@ from .. import BaseHostTest class RTCTest(BaseHostTest): - PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]" + PATTERN_RTC_VALUE = r"\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]" re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE) __result = None diff --git a/tools/python/mbed_os_tools/test/host_tests_conn_proxy/conn_primitive_fastmodel.py b/tools/python/mbed_os_tools/test/host_tests_conn_proxy/conn_primitive_fastmodel.py index a198de83f62..90e7e01b936 100644 --- a/tools/python/mbed_os_tools/test/host_tests_conn_proxy/conn_primitive_fastmodel.py +++ b/tools/python/mbed_os_tools/test/host_tests_conn_proxy/conn_primitive_fastmodel.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import telnetlib import socket from .conn_primitive import ConnectorPrimitive, ConnectorPrimitiveException diff --git a/tools/python/mbed_os_tools/test/host_tests_plugins/module_reset_mbed.py b/tools/python/mbed_os_tools/test/host_tests_plugins/module_reset_mbed.py index 1a6c5d85897..8ba6662e199 100644 --- a/tools/python/mbed_os_tools/test/host_tests_plugins/module_reset_mbed.py +++ b/tools/python/mbed_os_tools/test/host_tests_plugins/module_reset_mbed.py @@ -14,7 +14,6 @@ # limitations under the License. import re -import pkg_resources from .host_test_plugins import HostTestPluginBase @@ -35,51 +34,8 @@ def __init__(self): '2.7' """ HostTestPluginBase.__init__(self) - self.re_float = re.compile("^\d+\.\d+") - pyserial_version = pkg_resources.require("pyserial")[0].version - self.pyserial_version = self.get_pyserial_version(pyserial_version) - self.is_pyserial_v3 = float(self.pyserial_version) >= 3.0 - def get_pyserial_version(self, pyserial_version): - """! Retrieve pyserial module version - @return Returns float with pyserial module number - """ - version = 3.0 - m = self.re_float.search(pyserial_version) - if m: - try: - version = float(m.group(0)) - except ValueError: - version = 3.0 # We will assume you've got latest (3.0+) - return version - - def safe_sendBreak(self, serial): - """! Closure for pyserial version dependant API calls - """ - if self.is_pyserial_v3: - return self._safe_sendBreak_v3_0(serial) - return self._safe_sendBreak_v2_7(serial) - - def _safe_sendBreak_v2_7(self, serial): - """! pyserial 2.7 API implementation of sendBreak/setBreak - @details - Below API is deprecated for pyserial 3.x versions! - http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.sendBreak - http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.setBreak - """ - result = True - try: - serial.sendBreak() - except: - # In Linux a termios.error is raised in sendBreak and in setBreak. - # The following setBreak() is needed to release the reset signal on the target mcu. - try: - serial.setBreak(False) - except: - result = False - return result - - def _safe_sendBreak_v3_0(self, serial): + def _safe_send_break(self, serial): """! pyserial 3.x API implementation of send_brea / break_condition @details http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.send_break @@ -121,7 +77,7 @@ def execute(self, capability, *args, **kwargs): if kwargs['serial']: if capability == 'default': serial = kwargs['serial'] - result = self.safe_sendBreak(serial) + result = self._safe_send_break(serial) return result diff --git a/tools/python/mbed_os_tools/test/mbed_greentea_hooks.py b/tools/python/mbed_os_tools/test/mbed_greentea_hooks.py index 0d0fd695b8a..4d20362fa9b 100644 --- a/tools/python/mbed_os_tools/test/mbed_greentea_hooks.py +++ b/tools/python/mbed_os_tools/test/mbed_greentea_hooks.py @@ -117,7 +117,7 @@ def expand_parameters(expr, expandables, delimiter=' '): result = None if expandables: expansion_result = [] - m = re.search('\[.*?\]', expr) + m = re.search(r'\[.*?\]', expr) if m: expr_str_orig = m.group(0) expr_str_base = m.group(0)[1:-1] @@ -186,11 +186,11 @@ def check_if_file_exists_or_is_empty(expr): expr = "lcov --gcov-tool gcov [(-a <<./build/{yotta_target_name}/{test_name_list}.info>>)] --output-file result.info" """ result = expr - expr_strs_orig = re.findall('\(.*?\)', expr) + expr_strs_orig = re.findall(r'\(.*?\)', expr) for expr_str_orig in expr_strs_orig: expr_str_base = expr_str_orig[1:-1] result = result.replace(expr_str_orig, expr_str_base) - m = re.search('\<<.*?\>>', expr_str_base) + m = re.search(r'\<<.*?\>>', expr_str_base) if m: expr_str_path = m.group(0)[2:-2] # Remove option if file not exists OR if file exists but empty diff --git a/tools/python/mbed_os_tools/test/mbed_target_info.py b/tools/python/mbed_os_tools/test/mbed_target_info.py index 86bace33684..e6bd8faa199 100644 --- a/tools/python/mbed_os_tools/test/mbed_target_info.py +++ b/tools/python/mbed_os_tools/test/mbed_target_info.py @@ -293,7 +293,7 @@ def get_mbed_targets_from_yotta(mbed_classic_name): return result def parse_yotta_search_cmd_output(line): - m = re.search('([\w\d-]+) \d+\.\d+\.\d+[$:]?', line) + m = re.search(r'([\w\d-]+) \d+\.\d+\.\d+[$:]?', line) if m and len(m.groups()): yotta_target_name = m.groups()[0] return yotta_target_name diff --git a/tools/python/mbed_os_tools/test/mbed_test_api.py b/tools/python/mbed_os_tools/test/mbed_test_api.py index 5fa9e0ae222..a4204f2af76 100644 --- a/tools/python/mbed_os_tools/test/mbed_test_api.py +++ b/tools/python/mbed_os_tools/test/mbed_test_api.py @@ -121,7 +121,7 @@ def run_htrun(cmd, verbose): # int value > 0 notifies caller that starting of host test process failed return RUN_HOST_TEST_POPEN_ERROR - htrun_failure_line = re.compile('\[RXD\] (:\d+::FAIL: .*)') + htrun_failure_line = re.compile(r'\[RXD\] (:\d+::FAIL: .*)') for line in iter(p.stdout.readline, b''): decoded_line = line.decode("utf-8", "replace") diff --git a/tools/python/python_tests/mbed_greentea/__init__.py b/tools/python/python_tests/mbed_greentea/__init__.py deleted file mode 100644 index 196ab3986ea..00000000000 --- a/tools/python/python_tests/mbed_greentea/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -"""! @package mbed-greentea-test - -Unit tests for mbed-greentea test suite - -""" diff --git a/tools/python/python_tests/mbed_greentea/basic.py b/tools/python/python_tests/mbed_greentea/basic.py deleted file mode 100644 index 3b68a58fd1c..00000000000 --- a/tools/python/python_tests/mbed_greentea/basic.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest - -class BasicTestCase(unittest.TestCase): - """ Basic true asserts to see that testing is executed - """ - - def setUp(self): - pass - - def tearDown(self): - pass - - def test_example(self): - self.assertEqual(True, True) - self.assertNotEqual(True, False) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_cli.py b/tools/python/python_tests/mbed_greentea/mbed_gt_cli.py deleted file mode 100644 index b8fcd93beda..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_cli.py +++ /dev/null @@ -1,151 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import six -import sys -import unittest - -from mbed_greentea import mbed_greentea_cli -from mbed_greentea.tests_spec import TestSpec - -test_spec_def = { - "builds": { - "K64F-ARM": { - "platform": "K64F", - "toolchain": "ARM", - "base_path": "./.build/K64F/ARM", - "baud_rate": 115200, - "tests": { - "mbed-drivers-test-generic_tests":{ - "binaries":[ - { - "binary_type": "bootable", - "path": "./.build/K64F/ARM/mbed-drivers-test-generic_tests.bin" - } - ] - }, - "mbed-drivers-test-c_strings":{ - "binaries":[ - { - "binary_type": "bootable", - "path": "./.build/K64F/ARM/mbed-drivers-test-c_strings.bin" - } - ] - } - } - } - } -} - -class GreenteaCliFunctionality(unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def test_get_greentea_version(self): - version = mbed_greentea_cli.get_greentea_version() - - self.assertIs(type(version), str) - - version_list = version.split('.') - - self.assertEqual(version_list[0].isdigit(), True) - self.assertEqual(version_list[1].isdigit(), True) - self.assertEqual(version_list[2].isdigit(), True) - - def test_print_version(self): - version = mbed_greentea_cli.get_greentea_version() - - old_stdout = sys.stdout - sys.stdout = stdout_capture = six.StringIO() - mbed_greentea_cli.print_version() - sys.stdout = old_stdout - - printed_version = stdout_capture.getvalue().splitlines()[0] - self.assertEqual(printed_version, version) - - def test_get_hello_string(self): - version = mbed_greentea_cli.get_greentea_version() - hello_string = mbed_greentea_cli.get_hello_string() - - self.assertIs(type(version), str) - self.assertIs(type(hello_string), str) - self.assertIn(version, hello_string) - - def test_get_local_host_tests_dir_invalid_path(self): - test_path = mbed_greentea_cli.get_local_host_tests_dir("invalid-path") - self.assertEqual(test_path, None) - - def test_get_local_host_tests_dir_valid_path(self): - path = "." - test_path = mbed_greentea_cli.get_local_host_tests_dir(path) - self.assertEqual(test_path, path) - - def test_get_local_host_tests_dir_default_path(self): - import os - import shutil - import tempfile - - curr_dir = os.getcwd() - test1_dir = tempfile.mkdtemp() - test2_dir = os.mkdir(os.path.join(test1_dir, "test")) - test3_dir = os.mkdir(os.path.join(test1_dir, "test", "host_tests")) - - os.chdir(test1_dir) - - test_path = mbed_greentea_cli.get_local_host_tests_dir("") - self.assertEqual(test_path, "./test/host_tests") - - os.chdir(curr_dir) - shutil.rmtree(test1_dir) - - def test_create_filtered_test_list(self): - test_spec = TestSpec() - test_spec.parse(test_spec_def) - test_build = test_spec.get_test_builds()[0] - - test_list = mbed_greentea_cli.create_filtered_test_list(test_build.get_tests(), - 'mbed-drivers-test-generic_*', - None, - test_spec=test_spec) - self.assertEqual(set(test_list.keys()), set(['mbed-drivers-test-generic_tests'])) - - test_list = mbed_greentea_cli.create_filtered_test_list(test_build.get_tests(), - '*_strings', - None, - test_spec=test_spec) - self.assertEqual(set(test_list.keys()), set(['mbed-drivers-test-c_strings'])) - - test_list = mbed_greentea_cli.create_filtered_test_list(test_build.get_tests(), - 'mbed*s', - None, - test_spec=test_spec) - expected = set(['mbed-drivers-test-c_strings', 'mbed-drivers-test-generic_tests']) - self.assertEqual(set(test_list.keys()), expected) - - test_list = mbed_greentea_cli.create_filtered_test_list(test_build.get_tests(), - '*-drivers-*', - None, - test_spec=test_spec) - expected = set(['mbed-drivers-test-c_strings', 'mbed-drivers-test-generic_tests']) - self.assertEqual(set(test_list.keys()), expected) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_cmake_handlers.py b/tools/python/python_tests/mbed_greentea/mbed_gt_cmake_handlers.py deleted file mode 100644 index 7681c1905eb..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_cmake_handlers.py +++ /dev/null @@ -1,147 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import os -import mock -import six -import sys -import unittest - -from mbed_greentea import cmake_handlers, tests_spec - -class GreenteaCmakeHandlers(unittest.TestCase): - """ Basic true asserts to see that testing is executed - """ - - def setUp(self): - self.ctesttestfile = """# CMake generated Testfile for -# Source directory: c:/Work2/mbed-client/test -# Build directory: c:/Work2/mbed-client/build/frdm-k64f-gcc/test -# -# This file includes the relevant testing commands required for -# testing this directory and lists subdirectories to be tested as well. -add_test(mbed-client-test-mbedclient-smokeTest "mbed-client-test-mbedclient-smokeTest") -add_test(mbed-client-test-helloworld-mbedclient "mbed-client-test-helloworld-mbedclient") -""" - - def tearDown(self): - pass - - def test_example(self): - self.assertEqual(True, True) - self.assertNotEqual(True, False) - - def test_parse_ctesttestfile_line(self): - LINK_TARGET = '/dir/to/target' - BINARY_TYPE = '.bin' - - result = {} - no_skipped_lines = 0 - for line in self.ctesttestfile.splitlines(): - line_parse = cmake_handlers.parse_ctesttestfile_line(LINK_TARGET, BINARY_TYPE, line, verbose=True) - if line_parse: - test_case, test_case_path = line_parse - result[test_case] = test_case_path - else: - no_skipped_lines += 1 - - self.assertIn('mbed-client-test-mbedclient-smokeTest', result) - self.assertIn('mbed-client-test-helloworld-mbedclient', result) - - for test_case, test_case_path in result.items(): - self.assertEqual(test_case_path.startswith(LINK_TARGET), True) - self.assertEqual(test_case_path.endswith(BINARY_TYPE), True) - - self.assertEqual(len(result), 2) # We parse two entries - self.assertEqual(no_skipped_lines, 6) # We skip six lines in this file - - def test_load_ctest_testsuite_missing_link_target(self): - null_link_target = None - null_suite = cmake_handlers.load_ctest_testsuite(null_link_target) - self.assertEqual(null_suite, {}) - - - def test_load_ctest_testsuite(self): - root_path = os.path.dirname(os.path.realpath(__file__)) - emty_path = os.path.join(root_path, "resources", "empty") - full_path = os.path.join(root_path, "resources", "not-empty") - - # Empty LINK_TARGET - empty_link_target = emty_path - empty_suite = cmake_handlers.load_ctest_testsuite(empty_link_target) - self.assertEqual(empty_suite, {}) - - # Not empty LINK_TARGET - link_target = full_path - test_suite = cmake_handlers.load_ctest_testsuite(link_target) - self.assertIsNotNone(test_suite) - self.assertIn('mbed-client-test-mbedclient-smokeTest', test_suite) - self.assertIn('mbed-client-test-helloworld-mbedclient', test_suite) - - - def test_list_binaries_for_targets(self): - root_path = os.path.dirname(os.path.realpath(__file__)) - null_path = os.path.join(root_path, "resources", "empty", "test") - full_path = os.path.join(root_path, "resources") - - def run_and_capture(path, verbose=False): - old_stdout = sys.stdout - sys.stdout = stdout_capture = six.StringIO() - cmake_handlers.list_binaries_for_targets(build_dir=path, verbose_footer=verbose) - sys.stdout = old_stdout - - return stdout_capture.getvalue() - - # Test empty target directory - output = run_and_capture(null_path) - self.assertTrue("no tests found in current location" in output) - - # Test empty target directory (Verbose output) - output = run_and_capture(null_path, verbose=True) - self.assertTrue("no tests found in current location" in output) - self.assertTrue("Example: execute 'mbedgt -t TARGET_NAME -n TEST_NAME' to run test TEST_NAME for target TARGET_NAME" in output) - - # Test non-empty target directory - output = run_and_capture(full_path) - self.assertTrue("available tests for target" in output) - - - def test_list_binaries_for_builds(self): - root_path = os.path.dirname(os.path.realpath(__file__)) - spec_path = os.path.join(root_path, "resources", "test_spec.json") - - spec = tests_spec.TestSpec(spec_path) - - for verbose in [True, False]: - # Capture logging output - old_stdout = sys.stdout - sys.stdout = stdout_capture = six.StringIO() - cmake_handlers.list_binaries_for_builds(spec, verbose_footer=verbose) - sys.stdout = old_stdout - - output = stdout_capture.getvalue() - self.assertTrue("available tests for build 'K64F-ARM'" in output) - self.assertTrue("available tests for build 'K64F-GCC'" in output) - self.assertTrue("tests-example-1" in output) - self.assertTrue("tests-example-2" in output) - self.assertTrue("tests-example-7" in output) - - if verbose == True: - self.assertTrue("Example: execute" in output) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_coverage_api.py b/tools/python/python_tests/mbed_greentea/mbed_gt_coverage_api.py deleted file mode 100644 index 65ae0e81eb4..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_coverage_api.py +++ /dev/null @@ -1,63 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import os -import unittest -from mbed_greentea import mbed_coverage_api - - -class GreenteaCoverageAPI(unittest.TestCase): - - def setUp(self): - pass - - def test_x(self): - pass - - def test_coverage_pack_hex_payload(self): - # This function takesstring as input - r = mbed_coverage_api.coverage_pack_hex_payload('') - self.assertEqual(bytearray(b''), r) - - r = mbed_coverage_api.coverage_pack_hex_payload('6164636772') - self.assertEqual(bytearray(b'adcgr'), r) - - r = mbed_coverage_api.coverage_pack_hex_payload('.') # '.' -> 0x00 - self.assertEqual(bytearray(b'\x00'), r) - - r = mbed_coverage_api.coverage_pack_hex_payload('...') # '.' -> 0x00 - self.assertEqual(bytearray(b'\x00\x00\x00'), r) - - r = mbed_coverage_api.coverage_pack_hex_payload('.6164636772.') # '.' -> 0x00 - self.assertEqual(bytearray(b'\x00adcgr\x00'), r) - - def test_coverage_dump_file_valid(self): - import tempfile - - payload = bytearray(b'PAYLOAD') - handle, path = tempfile.mkstemp("test_file") - mbed_coverage_api.coverage_dump_file(".", path, payload) - - with open(path, 'r') as f: - read_data = f.read() - - self.assertEqual(read_data, payload.decode("utf-8", "ignore")) - os.close(handle) - os.remove(path) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_greentea_dlm.py b/tools/python/python_tests/mbed_greentea/mbed_gt_greentea_dlm.py deleted file mode 100644 index 287262ccd56..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_greentea_dlm.py +++ /dev/null @@ -1,142 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2017 ARM Limited -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import os -import six -import sys -import tempfile -import unittest - -from lockfile import LockFile -from mock import patch -from mbed_greentea import mbed_greentea_dlm - - -class GreenteaDlmFunctionality(unittest.TestCase): - def setUp(self): - temp_dir = tempfile.mkdtemp() - self.home_tools_patch = patch('mbed_os_tools.test.mbed_greentea_dlm.HOME_DIR', temp_dir) - self.home_local_patch = patch('mbed_greentea.mbed_greentea_dlm.HOME_DIR', temp_dir) - kettle_dir = os.path.join(temp_dir, mbed_greentea_dlm.GREENTEA_HOME_DIR, mbed_greentea_dlm.GREENTEA_KETTLE) - self.kettle_tools_patch = patch('mbed_os_tools.test.mbed_greentea_dlm.GREENTEA_KETTLE_PATH', kettle_dir) - self.kettle_local_patch = patch('mbed_greentea.mbed_greentea_dlm.GREENTEA_KETTLE_PATH', kettle_dir) - - self.home_tools_patch.start() - self.home_local_patch.start() - self.kettle_tools_patch.start() - self.kettle_local_patch.start() - - def tearDown(self): - self.home_tools_patch.stop() - self.home_local_patch.stop() - self.kettle_tools_patch.stop() - self.kettle_local_patch.stop() - - def test_greentea_home_dir_init(self): - mbed_greentea_dlm.greentea_home_dir_init() - - path = os.path.join(mbed_greentea_dlm.HOME_DIR, mbed_greentea_dlm.GREENTEA_HOME_DIR) - self.assertTrue(os.path.exists(path)) - - def test_greentea_get_app_sem(self): - sem, name, uuid = mbed_greentea_dlm.greentea_get_app_sem() - self.assertIsNotNone(sem) - self.assertIsNotNone(name) - self.assertIsNotNone(uuid) - - def test_greentea_get_target_lock(self): - lock = mbed_greentea_dlm.greentea_get_target_lock("target-id-2") - path = os.path.join(mbed_greentea_dlm.HOME_DIR, mbed_greentea_dlm.GREENTEA_HOME_DIR, "target-id-2") - self.assertIsNotNone(lock) - self.assertEqual(path, lock.path) - - def test_greentea_get_global_lock(self): - lock = mbed_greentea_dlm.greentea_get_global_lock() - path = os.path.join(mbed_greentea_dlm.HOME_DIR, mbed_greentea_dlm.GREENTEA_HOME_DIR, "glock.lock") - self.assertIsNotNone(lock) - self.assertEqual(path, lock.path) - - def test_get_json_data_from_file_invalid_file(self): - result = mbed_greentea_dlm.get_json_data_from_file("null_file") - self.assertIsNone(result) - - def test_get_json_data_from_file_invalid_json(self): - path = os.path.join(mbed_greentea_dlm.HOME_DIR, "test") - - with open(path, "w") as f: - f.write("invalid json") - - result = mbed_greentea_dlm.get_json_data_from_file(path) - self.assertEqual(result, None) - - os.remove(path) - - def test_get_json_data_from_file_valid_file(self): - path = os.path.join(mbed_greentea_dlm.HOME_DIR, "test") - - with open(path, "w") as f: - f.write("{}") - - result = mbed_greentea_dlm.get_json_data_from_file(path) - self.assertEqual(result, {}) - - os.remove(path) - - def test_greentea_update_kettle(self): - uuid = "001" - mbed_greentea_dlm.greentea_update_kettle(uuid) - - data = mbed_greentea_dlm.get_json_data_from_file(mbed_greentea_dlm.GREENTEA_KETTLE_PATH) - self.assertIsNotNone(data) - self.assertIn("start_time", data[uuid]) - self.assertIn("cwd", data[uuid]) - self.assertIn("locks", data[uuid]) - - self.assertEqual(data[uuid]["cwd"], os.getcwd()) - self.assertEqual(data[uuid]["locks"], []) - - # Check greentea_kettle_info() - output = mbed_greentea_dlm.greentea_kettle_info().splitlines() - line = output[3] - self.assertIn(os.getcwd(), line) - self.assertIn(uuid, line) - - # Test greentea_acquire_target_id - target_id = "999" - mbed_greentea_dlm.greentea_acquire_target_id(target_id, uuid) - data = mbed_greentea_dlm.get_json_data_from_file(mbed_greentea_dlm.GREENTEA_KETTLE_PATH) - self.assertIn(uuid, data) - self.assertIn("locks", data[uuid]) - self.assertIn(target_id, data[uuid]["locks"]) - - # Test greentea_release_target_id - mbed_greentea_dlm.greentea_release_target_id(target_id, uuid) - data = mbed_greentea_dlm.get_json_data_from_file(mbed_greentea_dlm.GREENTEA_KETTLE_PATH) - self.assertIn(uuid, data) - self.assertIn("locks", data[uuid]) - self.assertNotIn(target_id, data[uuid]["locks"]) - - # Test greentea_acquire_target_id_from_list - target_id = "999" - result = mbed_greentea_dlm.greentea_acquire_target_id_from_list([target_id], uuid) - data = mbed_greentea_dlm.get_json_data_from_file(mbed_greentea_dlm.GREENTEA_KETTLE_PATH) - self.assertEqual(result, target_id) - self.assertIn(uuid, data) - self.assertIn("locks", data[uuid]) - self.assertIn(target_id, data[uuid]["locks"]) - - # Check greentea_clean_kettle() - mbed_greentea_dlm.greentea_clean_kettle(uuid) - data = mbed_greentea_dlm.get_json_data_from_file(mbed_greentea_dlm.GREENTEA_KETTLE_PATH) - self.assertEqual(data, {}) diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_hooks.py b/tools/python/python_tests/mbed_greentea/mbed_gt_hooks.py deleted file mode 100644 index 78fdca01fff..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_hooks.py +++ /dev/null @@ -1,141 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import six -import sys -import unittest - -from mock import patch -from mbed_greentea.mbed_greentea_hooks import GreenteaCliTestHook -from mbed_greentea.mbed_greentea_hooks import LcovHook - -class GreenteaCliTestHookTest(unittest.TestCase): - - def setUp(self): - self.cli_hooks = GreenteaCliTestHook('test_hook', 'some command') - self.lcov_hooks = LcovHook('test_hook', 'some command') - - def tearDown(self): - pass - - def test_format_before_run(self): - command = LcovHook.format_before_run("command {expansion}", None, verbose=True) - self.assertEqual(command, "command {expansion}") - - expansions = ["test", "test2"] - command = LcovHook.format_before_run("command {expansion}", {"expansion": expansions}, verbose=True) - self.assertEqual(command, "command ['test', 'test2']") - - def test_expand_parameters_with_1_list(self): - # Simple list - self.assertEqual('new_value_1 new_value_2', - self.cli_hooks.expand_parameters('[{token_list}]', { - "token_list" : ['new_value_1', 'new_value_2'] - })) - - # List with prefix - self.assertEqual('-a new_value_1 -a new_value_2', - self.cli_hooks.expand_parameters('[-a {token_list}]', { - "token_list" : ['new_value_1', 'new_value_2'] - })) - - # List with prefix and extra text - self.assertEqual('-a /path/to/new_value_1 -a /path/to/new_value_2', - self.cli_hooks.expand_parameters('[-a /path/to/{token_list}]', { - "token_list" : ['new_value_1', 'new_value_2'] - })) - - def test_expand_parameters_with_2_lists(self): - self.assertEqual('ytA T1', - self.cli_hooks.expand_parameters('[{yt_target_list} {test_list}]', { - "test_list" : ['T1'], - "yt_target_list" : ['ytA'], - })) - - self.assertEqual('ytA T1 ytA T2 ytA T3 ytB T1 ytB T2 ytB T3 ytC T1 ytC T2 ytC T3', - self.cli_hooks.expand_parameters('[{yt_target_list} {test_list}]', { - "test_list" : ['T1', 'T2', 'T3'], - "yt_target_list" : ['ytA', 'ytB', 'ytC'], - })) - - # In this test we expect {yotta_target_name} token to stay untouched because it is not declared as a list - self.assertEqual('lcov -a /build/{yotta_target_name}/mbed-drivers-test-basic.info -a /build/{yotta_target_name}/mbed-drivers-test-hello.info', - self.cli_hooks.expand_parameters('lcov [-a /build/{yotta_target_name}/{test_list}.info]', { - "test_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc' - })) - - def test_expand_parameters_exceptions(self): - # Here [] is reduced to empty string - self.assertEqual('', - self.cli_hooks.expand_parameters('[]', { - "test_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc' - })) - - # Here [some string] is reduced to empty string - self.assertEqual('', - self.cli_hooks.expand_parameters('[some string]', { - "test_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc' - })) - - # Here [some string] is reduced to empty string - self.assertEqual('-+=abc', - self.cli_hooks.expand_parameters('-+=[some string]abc', { - "test_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc' - })) - - self.assertEqual(None, - self.cli_hooks.expand_parameters('some text without square brackets but with tokes: {test_list} and {yotta_target_name}', { - "test_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc' - })) - - def test_format_before_run_with_1_list_1_string(self): - # {test_name_list} should expand [] list twice - # {yotta_target_name} should not be used to expand, only to replace - self.assertEqual('build path = -a /build/frdm-k64f-gcc/mbed-drivers-test-basic -a /build/frdm-k64f-gcc/mbed-drivers-test-hello', - self.cli_hooks.format_before_run('build path = [-a /build/{yotta_target_name}/{test_name_list}]', { - "test_name_list" : ['mbed-drivers-test-basic', 'mbed-drivers-test-hello'], - "yotta_target_name" : 'frdm-k64f-gcc', - })) - - @patch('os.path.exists') - @patch('os.path.getsize') - def test_check_if_file_exists(self, pathGetsize_mock, pathExists_mock): - pathExists_mock.return_value = True - self.assertEqual('-a ./build/frdm-k64f-gcc.info', - self.lcov_hooks.check_if_file_exists_or_is_empty('(-a <<./build/frdm-k64f-gcc.info>>)')) - - pathExists_mock.return_value = False - self.assertEqual('', - self.lcov_hooks.check_if_file_exists_or_is_empty('(-a <<./build/frdm-k64f-gcc.info>>)')) - - @patch('os.path.exists') - @patch('os.path.getsize') - def test_check_if_file_is_empty(self, pathGetsize_mock, pathExists_mock): - pathExists_mock.return_value = True - pathGetsize_mock.return_value = 1 - self.assertEqual('-a ./build/frdm-k64f-gcc.info', - self.lcov_hooks.check_if_file_exists_or_is_empty('(-a <<./build/frdm-k64f-gcc.info>>)')) - - pathExists_mock.return_value = True - pathGetsize_mock.return_value = 0 - self.assertEqual('', - self.lcov_hooks.check_if_file_exists_or_is_empty('(-a <<./build/frdm-k64f-gcc.info>>)')) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_report_api.py b/tools/python/python_tests/mbed_greentea/mbed_gt_report_api.py deleted file mode 100644 index 2c973a14bfb..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_report_api.py +++ /dev/null @@ -1,175 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import json -import os -import six -import sys -import tempfile -import unittest - -from mock import patch -from mbed_greentea import mbed_report_api - -class GreenteaReportApiFunctionality(unittest.TestCase): - def setUp(self): - self.test_case_data = { - "K64F-ARM": { - "suite": { - "testcase_result": { - "case-1": { - "duration": 1.00, - "time_start": 2.00, - "time_end": 3.00, - "result_text": "FAIL", - "passed": 10, - "failed": 10 - }, - "case-2": { - "duration": 1.00, - "time_start": 2.00, - "time_end": 3.00, - "result_text": "SKIPPED", - "passed": 10, - "failed": 10 - }, - "case-3": { - "duration": 1.00, - "time_start": 2.00, - "time_end": 3.00, - "result_text": "?", - "passed": 10, - "failed": 10 - }, - }, - "single_test_output": "OK", - "platform_name": "K64F" - } - } - } - - self.test_suite_data = { - "K64F-ARM": { - "test-1": { - "testcase_result": { - "build_path": ".." - }, - "single_test_output": "OK", - "single_test_result": "OK", - "platform_name": "K64F", - "elapsed_time": 1.2, - "copy_method": "shell" - }, - "test-2": { - "testcase_result": { - "build_path": ".." - }, - "single_test_output": "OK", - "single_test_result": "OK", - "platform_name": "K64F", - "elapsed_time": 1.2, - "copy_method": "shell" - } - }, - "N32F-ARM": { - "test-3": { - "testcase_result": { - "build_path": ".." - }, - "single_test_output": "OK", - "single_test_result": "OK", - "platform_name": "N32F", - "elapsed_time": 1.2, - "copy_method": "shell" - } - } - } - - def tearDown(self): - pass - - def test_export_to_file(self): - # Invalid filepath - payload = "PAYLOAD" - filepath = "." - - old_stdout = sys.stdout - sys.stdout = stdout_capture = six.StringIO() - result = mbed_report_api.export_to_file(filepath, payload) - sys.stdout = old_stdout - - command_output = stdout_capture.getvalue().splitlines()[0] - self.assertIn("file failed:", command_output) - self.assertEqual(result, False) - - # Valid filepath - temp_file = tempfile.mkstemp("test_file") - result = mbed_report_api.export_to_file(temp_file[1], payload) - self.assertTrue(result) - - with open(temp_file[1], 'r') as f: - read_data = f.read() - - self.assertEqual(read_data, payload) - os.close(temp_file[0]) - os.remove(temp_file[1]) - - - def test_exporter_text(self): - result, result_ = mbed_report_api.exporter_text(self.test_suite_data) - - lines = result.splitlines() - self.assertIn("target", lines[0]) - self.assertIn("platform_name", lines[0]) - self.assertIn("test suite", lines[0]) - self.assertIn("result", lines[0]) - self.assertIn("K64F", lines[2]) - self.assertIn("test-1", lines[2]) - self.assertIn("test-2", lines[3]) - self.assertIn("test-3", lines[4]) - self.assertIn("OK", lines[2]) - - def test_exporter_testcase_test(self): - result, result_ = mbed_report_api.exporter_testcase_text(self.test_case_data) - - lines = result.splitlines() - self.assertIn("target", lines[0]) - self.assertIn("platform_name", lines[0]) - self.assertIn("test suite", lines[0]) - self.assertIn("result", lines[0]) - - line = lines[2] - self.assertIn("K64F-ARM", line) - self.assertIn("suite", line) - self.assertIn("case-1", line) - - def test_exporter_testcase_junit(self): - result = mbed_report_api.exporter_testcase_junit(self.test_case_data) - self.assertIsNotNone(result) - - from xml.etree import ElementTree as ET - xml = ET.fromstring(result) - - self.assertEqual(xml.tag, "testsuites") - self.assertEqual(xml.attrib["failures"], "1") - self.assertEqual(xml.attrib["tests"], "3") - self.assertEqual(xml.attrib["errors"], "1") - self.assertEqual(xml.attrib["time"], "3.0") - - child = xml[0] - self.assertEqual(child.tag, "testsuite") - self.assertEqual(child.attrib["failures"], "1") - self.assertEqual(child.attrib["tests"], "3") - self.assertEqual(child.attrib["errors"], "1") - self.assertEqual(child.attrib["time"], "3.0") diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_target_info.py b/tools/python/python_tests/mbed_greentea/mbed_gt_target_info.py deleted file mode 100644 index 5369e691d8f..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_target_info.py +++ /dev/null @@ -1,434 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import os -import shutil -import tempfile -import unittest - -from six import StringIO - -from mock import patch -from mbed_greentea import mbed_target_info - - -class GreenteaTargetInfo(unittest.TestCase): - - def setUp(self): - self.YOTTA_SEARCH_SSL_ISSUE = """/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. - InsecurePlatformWarning -frdm-k64f-gcc 0.0.24: Official mbed build target for the mbed frdm-k64f development board. -frdm-k64f-armcc 0.0.16: Official mbed build target for the mbed frdm-k64f development board, using the armcc toolchain. -/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. - InsecurePlatformWarning -""" - - def tearDown(self): - pass - - def test_parse_yotta_target_cmd_output_mixed_chars(self): - self.assertIn("m", mbed_target_info.parse_yotta_target_cmd_output("m 0.0.0")) - self.assertIn("m", mbed_target_info.parse_yotta_target_cmd_output(" m 0.0.0")) - self.assertIn("aaaaaaaaaaaaa", mbed_target_info.parse_yotta_target_cmd_output("aaaaaaaaaaaaa 0.0.0")) - self.assertIn("aaaa-bbbb-cccc", mbed_target_info.parse_yotta_target_cmd_output("aaaa-bbbb-cccc 0.0.0")) - self.assertIn("aBc-DEF_hijkkk", mbed_target_info.parse_yotta_target_cmd_output("aBc-DEF_hijkkk 0.0.0")) - - def test_parse_yotta_target_cmd_output_mixed_version(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.0")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 1.1.1")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 1.1.12")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 1.1.123")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 11.22.33")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.1")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.10.12")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.20.123")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.2.123")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 10.20.123")) - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 110.200.123")) - - def test_parse_yotta_target_cmd_output(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 0.0.14")) - - def test_parse_yotta_target_cmd_output_mixed_whitechars(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24 ")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3 ")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14 ")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 0.0.14 ")) - - def test_parse_yotta_target_cmd_output_mixed_nl(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24\n")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3\n")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14\n")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 0.0.14\n")) - - def test_parse_yotta_target_cmd_output_mixed_rcnl(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24\r\n")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3\r\n")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14\r\n")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 11.222.333\r\n")) - - def test_parse_yotta_target_cmd_output_mixed_nl_whitechars(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24 \n")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3 \n")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14 \n")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 0.0.14 \n")) - - def test_parse_yotta_target_cmd_output_mixed_rcnl_whitechars(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-gcc 0.0.24 \r\n")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_target_cmd_output("frdm-k64f-armcc 1.12.3 \r\n")) - self.assertIn("mbed-gcc", mbed_target_info.parse_yotta_target_cmd_output("mbed-gcc 0.0.14 \r\n")) - self.assertIn("stm32f429i-disco-gcc", mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 0.0.14 \r\n")) - - def test_parse_yotta_target_cmd_output_fail(self): - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("")) - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 1")) - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 1.")) - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 1.0")) - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 1.0.")) - self.assertEqual(None, mbed_target_info.parse_yotta_target_cmd_output("stm32f429i-disco-gcc 1.0.x")) - - def test_parse_yotta_search_cmd_output(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_search_cmd_output("frdm-k64f-gcc 0.0.24: Official mbed build target for the mbed frdm-k64f development board.")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_search_cmd_output("frdm-k64f-armcc 0.0.16: Official mbed build target for the mbed frdm-k64f development board, using the armcc toolchain.")) - self.assertEqual(None, mbed_target_info.parse_yotta_search_cmd_output("")) - self.assertEqual(None, mbed_target_info.parse_yotta_search_cmd_output("additional results from https://yotta-private.herokuapp.com:")) - - def test_parse_yotta_search_cmd_output_text(self): - # Old style with new switch --short : 'yotta search ... --short' - text = """frdm-k64f-gcc 0.1.4: Official mbed build target for the mbed frdm-k64f development board. -frdm-k64f-armcc 0.1.3: Official mbed build target for the mbed frdm-k64f development board, using the armcc toolchain. - -additional results from https://yotta-private.herokuapp.com: -""" - targets = [] - for line in text.splitlines(): - yotta_target_name = mbed_target_info.parse_yotta_search_cmd_output(line) - if yotta_target_name: - targets.append(yotta_target_name) - self.assertIn("frdm-k64f-gcc", targets) - self.assertIn("frdm-k64f-armcc", targets) - self.assertEqual(2, len(targets)) - - def test_parse_yotta_search_cmd_output_new_style(self): - self.assertIn("frdm-k64f-gcc", mbed_target_info.parse_yotta_search_cmd_output("frdm-k64f-gcc 0.1.4")) - self.assertIn("frdm-k64f-armcc", mbed_target_info.parse_yotta_search_cmd_output("frdm-k64f-armcc 0.1.4")) - pass - - def test_parse_yotta_search_cmd_output_new_style_text(self): - # New style of 'yotta search ...' - text = """frdm-k64f-gcc 0.1.4 - Official mbed build target for the mbed frdm-k64f development board. - mbed-target:k64f, mbed-official, k64f, frdm-k64f, gcc -frdm-k64f-armcc 0.1.4 - Official mbed build target for the mbed frdm-k64f development board, using the armcc toolchain. - mbed-target:k64f, mbed-official, k64f, frdm-k64f, armcc - -additional results from https://yotta-private.herokuapp.com:""" - targets = [] - for line in text.splitlines(): - yotta_target_name = mbed_target_info.parse_yotta_search_cmd_output(line) - if yotta_target_name: - targets.append(yotta_target_name) - self.assertIn("frdm-k64f-gcc", targets) - self.assertIn("frdm-k64f-armcc", targets) - self.assertEqual(2, len(targets)) - - def test_parse_yotta_search_cmd_output_new_style_text_2(self): - # New style of 'yotta search ...' - text = """nrf51dk-gcc 0.0.3: - Official mbed build target for the nRF51-DK 32KB platform. - mbed-official, mbed-target:nrf51_dk, gcc - -additional results from https://yotta-private.herokuapp.com: - nrf51dk-gcc 0.0.3: - Official mbed build target for the nRF51-DK 32KB platform. - mbed-official, mbed-target:nrf51_dk, gcc - nrf51dk-armcc 0.0.3: - Official mbed build target for the nRF51-DK 32KB platform. - mbed-official, mbed-target:nrf51_dk, armcc -""" - targets = [] - for line in text.splitlines(): - yotta_target_name = mbed_target_info.parse_yotta_search_cmd_output(line) - if yotta_target_name and yotta_target_name not in targets: - targets.append(yotta_target_name) - - self.assertIn("nrf51dk-gcc", targets) - self.assertIn("nrf51dk-armcc", targets) - self.assertEqual(2, len(targets)) - - def test_parse_yotta_search_cmd_output_with_ssl_errors(self): - result = [] - for line in self.YOTTA_SEARCH_SSL_ISSUE.splitlines(): - yotta_target_name = mbed_target_info.parse_yotta_search_cmd_output(line) - if yotta_target_name: - result.append(yotta_target_name) - self.assertIn("frdm-k64f-gcc", result) - self.assertIn("frdm-k64f-armcc", result) - self.assertEqual(2, len(result)) - - def test_parse_mbed_target_from_target_json_no_keywords(self): - target_json_data = { - "name": "frdm-k64f-armcc", - "version": "0.1.4", - } - - self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - - def test_parse_mbed_target_from_target_json_no_name(self): - target_json_data = { - "version": "0.1.4", - "keywords": [ - "mbed-target:k64f", - "mbed-target::garbage", - "mbed-official", - "k64f", - "frdm-k64f", - "armcc" - ], - } - - self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - - def test_parse_mbed_target_from_target_json(self): - target_json_data = { - "name": "frdm-k64f-armcc", - "version": "0.1.4", - "keywords": [ - "mbed-target:k64f", - "mbed-target::garbage", - "mbed-official", - "k64f", - "frdm-k64f", - "armcc" - ], - } - - # Positive tests - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - - # Except cases - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - self.assertEqual(None, mbed_target_info.parse_mbed_target_from_target_json('_k64f_', target_json_data)) - self.assertEqual(None, mbed_target_info.parse_mbed_target_from_target_json('', target_json_data)) - self.assertEqual(None, mbed_target_info.parse_mbed_target_from_target_json('Some board name', target_json_data)) - - def test_parse_mbed_target_from_target_json_multiple(self): - target_json_data = { - "name": "frdm-k64f-armcc", - "version": "0.1.4", - "keywords": [ - "mbed-target:k64f", - "mbed-target:frdm-k64f", - "mbed-official", - "k64f", - "frdm-k64f", - "armcc" - ], - } - - # Positive tests - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('frdm-k64f', target_json_data)) - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - self.assertEqual('frdm-k64f-armcc', mbed_target_info.parse_mbed_target_from_target_json('FRDM-K64F', target_json_data)) - - # Except cases - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data)) - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('frdm-k64f', target_json_data)) - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data)) - self.assertNotEqual('frdm-k64f-gcc', mbed_target_info.parse_mbed_target_from_target_json('FRDM-K64F', target_json_data)) - - @patch('mbed_os_tools.test.mbed_target_info.get_mbed_target_call_yotta_target') - def test_get_mbed_target_from_current_dir_ok(self, callYtTarget_mock): - - yotta_target_cmd = """frdm-k64f-gcc 2.0.0 -kinetis-k64-gcc 2.0.2 -mbed-gcc 1.1.0 -""" - - callYtTarget_mock.return_value = ('', '', 0) - r = mbed_target_info.get_mbed_target_from_current_dir() - self.assertEqual(None, r) - - callYtTarget_mock.return_value = ('', '', 1) - r = mbed_target_info.get_mbed_target_from_current_dir() - self.assertEqual(None, r) - - callYtTarget_mock.return_value = (yotta_target_cmd, '', 1) - r = mbed_target_info.get_mbed_target_from_current_dir() - self.assertEqual(None, r) - - callYtTarget_mock.return_value = (yotta_target_cmd, '', 0) - r = mbed_target_info.get_mbed_target_from_current_dir() - self.assertEqual('frdm-k64f-gcc', r) - - def test_get_yotta_target_from_local_config_invalid_path(self): - result = mbed_target_info.get_yotta_target_from_local_config("invalid_path.json") - - self.assertIsNone(result) - - def test_get_yotta_target_from_local_config_valid_path(self): - payload = '{"build": { "target": "test_target"}}' - handle, path = tempfile.mkstemp("test_file") - - with open(path, 'w+') as f: - f.write(payload) - - result = mbed_target_info.get_yotta_target_from_local_config(path) - - self.assertIsNotNone(result) - self.assertEqual(result, "test_target") - - def test_get_yotta_target_from_local_config_failed_open(self): - handle, path = tempfile.mkstemp() - - with open(path, 'w+') as f: - result = mbed_target_info.get_yotta_target_from_local_config(path) - - self.assertIsNone(result) - - def test_get_mbed_targets_from_yotta_local_module_invalid_path(self): - result = mbed_target_info.get_mbed_targets_from_yotta_local_module("null", "invalid_path") - self.assertEqual(result, []) - - def test_get_mbed_targets_from_yotta_local_module_invalid_target(self): - base_path = tempfile.mkdtemp() - targ_path = tempfile.mkdtemp("target-1", dir=base_path) - handle, targ_file = tempfile.mkstemp("target.json", dir=targ_path) - - result = mbed_target_info.get_mbed_targets_from_yotta_local_module("null", base_path) - - self.assertEqual(result, []) - - def test_get_mbed_targets_from_yotta_local_module_valid(self): - payload = '{"name": "test_name", "keywords": [ "mbed-target:k64f" ]}' - base_path = tempfile.mkdtemp() - tar1_path = tempfile.mkdtemp("target-1", dir=base_path) - tar1_file = os.path.join(tar1_path, "target.json") - - with open(tar1_file, 'w+') as f: - f.write(payload) - - result = mbed_target_info.get_mbed_targets_from_yotta_local_module("k64f", base_path) - self.assertIsNot(result, None) - self.assertEqual(result[0], "test_name") - - shutil.rmtree(base_path) - - def test_parse_mbed_target_from_target_json_missing_json_data(self): - result = mbed_target_info.parse_mbed_target_from_target_json("null", "null") - self.assertIsNone(result) - - def test_parse_mbed_target_from_target_json_missing_keywords(self): - data = {} - result = mbed_target_info.parse_mbed_target_from_target_json("null", data) - self.assertIsNone(result) - - def test_parse_mbed_target_from_target_json_missing_target(self): - data = {} - data["keywords"] = {} - result = mbed_target_info.parse_mbed_target_from_target_json("null", data) - self.assertIsNone(result) - - def test_parse_mbed_target_from_target_json_missing_name(self): - data = {} - data["keywords"] = ["mbed-target:null"] - result = mbed_target_info.parse_mbed_target_from_target_json("null", data) - self.assertIsNone(result) - - # def test_get_mbed_targets_from_yotta(self): - # result = mbed_target_info.get_mbed_targets_from_yotta("k64f") - - def test_parse_add_target_info_mapping(self): - result = mbed_target_info.add_target_info_mapping("null") - - def test_parse_yotta_json_for_build_name(self): - self.assertEqual("", mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - "target": "" - } - } - )) - - self.assertEqual(None, mbed_target_info.parse_yotta_json_for_build_name( - { - "build": {} - } - )) - - self.assertEqual('frdm-k64f-gcc', mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - "target": "frdm-k64f-gcc,*", - "targetSetExplicitly": True - } - } - )) - - self.assertEqual('x86-linux-native', mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - "target": "x86-linux-native,*", - "targetSetExplicitly": True - } - } - )) - - self.assertEqual('frdm-k64f-gcc', mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - "target": "frdm-k64f-gcc,*" - } - } - )) - - self.assertEqual('frdm-k64f-gcc', mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - "target": "frdm-k64f-gcc" - } - } - )) - - self.assertEqual(None, mbed_target_info.parse_yotta_json_for_build_name( - { - "build": { - } - } - )) - - self.assertEqual(None, mbed_target_info.parse_yotta_json_for_build_name( - { - "BUILD": { - "target": "frdm-k64f-gcc,*", - "targetSetExplicitly": True - } - } - )) - - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_test_api.py b/tools/python/python_tests/mbed_greentea/mbed_gt_test_api.py deleted file mode 100644 index df0d5332f62..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_test_api.py +++ /dev/null @@ -1,595 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest -from mbed_greentea import mbed_test_api - - - -class GreenteaTestAPI(unittest.TestCase): - - def setUp(self): - self.OUTPUT_FAILURE = """mbedgt: mbed-host-test-runner: started -[1459245784.59][CONN][RXD] >>> Test cases: 7 passed, 1 failed with reason 'Test Cases Failed' -[1459245784.61][CONN][RXD] >>> TESTS FAILED! -[1459245784.64][CONN][INF] found KV pair in stream: {{__testcase_summary;7;1}}, queued... -[1459245784.64][CONN][RXD] {{__testcase_summary;7;1}} -[1459245784.66][CONN][INF] found KV pair in stream: {{end;failure}}, queued... -[1459245784.66][HTST][INF] __notify_complete(False) -[1459245784.66][HTST][INF] test suite run finished after 2.37 sec... -[1459245784.66][CONN][RXD] {{end;failure}} -[1459245784.67][HTST][INF] CONN exited with code: 0 -[1459245784.67][HTST][INF] Some events in queue -[1459245784.67][HTST][INF] stopped consuming events -[1459245784.67][HTST][INF] host test result() call skipped, received: False -[1459245784.67][HTST][WRN] missing __exit event from DUT -[1459245784.67][HTST][INF] calling blocking teardown() -[1459245784.67][HTST][INF] teardown() finished -[1459245784.67][HTST][INF] {{result;failure}} -""" - - self.OUTPUT_SUCCESS = """mbedgt: mbed-host-test-runner: started -[1459245860.90][CONN][RXD] {{__testcase_summary;4;0}} -[1459245860.92][CONN][INF] found KV pair in stream: {{end;success}}, queued... -[1459245860.92][CONN][RXD] {{end;success}} -[1459245860.92][HTST][INF] __notify_complete(True) -[1459245860.92][HTST][INF] test suite run finished after 0.90 sec... -[1459245860.94][HTST][INF] CONN exited with code: 0 -[1459245860.94][HTST][INF] No events in queue -[1459245860.94][HTST][INF] stopped consuming events -[1459245860.94][HTST][INF] host test result() call skipped, received: True -[1459245860.94][HTST][WRN] missing __exit event from DUT -[1459245860.94][HTST][INF] calling blocking teardown() -[1459245860.94][HTST][INF] teardown() finished -[1459245860.94][HTST][INF] {{result;success}} -""" - - self.OUTPUT_TIMEOUT = """mbedgt: mbed-host-test-runner: started -[1459246047.80][HTST][INF] copy image onto target... - 1 file(s) copied. -[1459246055.05][HTST][INF] starting host test process... -[1459246055.47][CONN][INF] starting connection process... -[1459246055.47][CONN][INF] initializing serial port listener... -[1459246055.47][SERI][INF] serial(port=COM205, baudrate=9600) -[1459246055.47][SERI][INF] reset device using 'default' plugin... -[1459246055.73][SERI][INF] wait for it... -[1459246056.74][CONN][INF] sending preamble '56bdcd85-b88a-460b-915e-1b9b41713b5a'... -[1459246056.74][SERI][TXD] mbedmbedmbedmbedmbedmbedmbedmbedmbedmbed -[1459246056.74][SERI][TXD] {{__sync;56bdcd85-b88a-460b-915e-1b9b41713b5a}} -[1459246065.06][HTST][INF] test suite run finished after 10.00 sec... -[1459246065.07][HTST][INF] CONN exited with code: 0 -[1459246065.07][HTST][INF] No events in queue -[1459246065.07][HTST][INF] stopped consuming events -[1459246065.07][HTST][INF] host test result(): None -[1459246065.07][HTST][WRN] missing __exit event from DUT -[1459246065.07][HTST][ERR] missing __exit event from DUT and no result from host test, timeout... -[1459246065.07][HTST][INF] calling blocking teardown() -[1459246065.07][HTST][INF] teardown() finished -[1459246065.07][HTST][INF] {{result;timeout}} -""" - - self.OUTPUT_STARTTAG_MISSING = """ -mbedgt: mbed-host-test-runner: started -[1507470727.39][HTST][INF] host test executor ver. 1.2.0 -[1507470727.39][HTST][INF] copy image onto target... SKIPPED! -[1507470727.39][HTST][INF] starting host test process... -[1507470727.40][CONN][INF] starting connection process... -[1507470727.40][HTST][INF] setting timeout to: 120 sec -[1507470756.96][CONN][RXD] >>> Running 4 test cases... -[1507470756.96][CONN][RXD] -[1507470756.96][CONN][RXD] >>> Running case #1: 'DNS query'... -[1507470756.96][CONN][INF] found KV pair in stream: {{__testcase_name;DNS query}}, queued... -[1507470756.96][CONN][INF] found KV pair in stream: {{__testcase_name;DNS preference query}}, queued... -[1507470756.96][CONN][INF] found KV pair in stream: {{__testcase_name;DNS literal}}, queued... -[1507470756.96][CONN][INF] found KV pair in stream: {{__testcase_name;DNS preference literal}}, queued... -[1507470757.04][CONN][RXD] DNS: query "connector.mbed.com" => "169.45.82.19" -[1507470757.04][CONN][INF] found KV pair in stream: {{__testcse_start;DNS query}}, queued... -[1507470757.13][CONN][RXD] >>> 'DNS query': 1 passed, 0 failed -[1507470757.13][CONN][RXD] -[1507470757.13][CONN][INF] found KV pair in stream: {{__testcase_finish;DNS query;1;0}}, queued... -[1507470757.32][CONN][RXD] >>> Running case #2: 'DNS preference query'... -[1507470757.41][CONN][RXD] DNS: query ipv4 "connector.mbed.com" => "169.45.82.19" -[1507470757.41][CONN][RXD] >>> 'DNS preference query': 1 passed, 0 failed -[1507470757.41][CONN][RXD] -[1507470757.41][CONN][INF] found KV pair in stream: {{__testcase_start;DNS preference query}}, queued... -[1507470757.41][CONN][INF] found KV pair in stream: {{__testcase_finish;DNS preference query;1;0}}, queued... -[1507470757.57][CONN][RXD] >>> Running case #3: 'DNS literal'... -[1507470757.66][CONN][RXD] DNS: literal "10.118.13.253" => "10.118.13.253" -[1507470757.66][CONN][RXD] {{__testcase_finish;DNS l -[1507470757.66][CONN][RXD] sed, 0 fai -[1507470757.66][CONN][INF] found KV pair in stream: {{__testcase_start;DNS literal}}, queued... -[1507470757.80][CONN][RXD] case #4: 'DNS preference literal'... -[1507470757.80][CONN][RXD] {{__test -[1507470757.80][CONN][RXD] reference literal}} -[1507470757.83][CONN][RXD] DNS: literal ipv4 "10.118.13.253" => "10.118.13.253" -[1507470757.83][CONN][INF] found KV pair in stream: {{__testcase_finish;DNS preference literal;1;0}}, queued... -[1507470757.92][CONN][RXD] >>> 'DNS preference literal': 1 passed, 0 failed -[1507470757.92][CONN][RXD] -[1507470757.92][CONN][RXD] >>> Test cases: 4 passed, 0 failed -[1507470758.00][CONN][INF] found KV pair in stream: {{__testcase_summary;4;0}}, queued... -[1507470758.00][CONN][INF] found KV pair in stream: {{max_heap_usage;2800}}, queued... -[1507470758.00][CONN][INF] found KV pair in stream: {{reserved_heap;19336}}, queued... -[1507470758.00][HTST][ERR] orphan event in main phase: {{max_heap_usage;2800}}, timestamp=1507470757.999258 -[1507470758.00][HTST][ERR] orphan event in main phase: {{reserved_heap;19336}}, timestamp=1507470757.999260 -[1507470758.00][CONN][INF] found KV pair in stream: {{__thread_info;"0x010002ca8",600,4096}}, queued... -[1507470758.00][HTST][ERR] orphan event in main phase: {{__thread_info;"0x010002ca8",600,4096}}, timestamp=1507470757.999261 -[1507470758.09][CONN][INF] found KV pair in stream: {{__thread_info;"0x01000045c",72,512}}, queued... -[1507470758.09][CONN][INF] found KV pair in stream: {{__thread_info;"0x010001168",128,512}}, queued... -[1507470758.09][HTST][ERR] orphan event in main phase: {{__thread_info;"0x01000045c",72,512}}, timestamp=1507470758.085627 -[1507470758.09][HTST][ERR] orphan event in main phase: {{__thread_info;"0x010001168",128,512}}, timestamp=1507470758.085635 -[1507470758.16][CONN][INF] found KV pair in stream: {{__thread_info;"0x010001018",560,1200}}, queued... -[1507470758.16][HTST][ERR] orphan event in main phase: {{__thread_info;"0x010001018",560,1200}}, timestamp=1507470758.162780 -[1507470758.25][CONN][INF] found KV pair in stream: {{__thread_info;"0x0100004a4",112,768}}, queued... -[1507470758.25][CONN][INF] found KV pair in stream: {{__thread_info;"0x0100010f8",96,512}}, queued... -[1507470758.25][CONN][INF] found KV pair in stream: {{__thread_info;"0x010001088",152,512}}, queued... -[1507470758.25][CONN][INF] found KV pair in stream: {{end;success}}, queued... -[1507470758.25][HTST][ERR] orphan event in main phase: {{__thread_info;"0x0100004a4",112,768}}, timestamp=1507470758.248291 -[1507470758.25][HTST][ERR] orphan event in main phase: {{__thread_info;"0x0100010f8",96,512}}, timestamp=1507470758.248296 -[1507470758.25][HTST][ERR] orphan event in main phase: {{__thread_info;"0x010001088",152,512}}, timestamp=1507470758.248299 -[1507470758.25][HTST][INF] __notify_complete(True) -[1507470758.25][HTST][INF] __exit_event_queue received -[1507470760.47][HTST][INF] CONN exited with code: 0 -[1507470760.47][HTST][INF] No events in queue -[1507470760.47][HTST][INF] stopped consuming events -[1507470760.47][HTST][INF] host test result() call skipped, received: True -[1507470760.47][HTST][WRN] missing __exit event from DUT -[1507470760.47][HTST][INF] calling blocking teardown() -[1507470760.47][HTST][INF] teardown() finished -[1507470760.47][HTST][INF] {{result;success}} - """ - - self.OUTPUT_UNDEF = """mbedgt: mbed-host-test-runner: started -{{result;some_random_value}} -""" - - self.OUTOUT_CSTRING_TEST = """ -[1459246264.88][HTST][INF] copy image onto target... - 1 file(s) copied. -[1459246272.76][HTST][INF] starting host test process... -[1459246273.18][CONN][INF] starting connection process... -[1459246273.18][CONN][INF] initializing serial port listener... -[1459246273.18][SERI][INF] serial(port=COM205, baudrate=9600) -[1459246273.18][SERI][INF] reset device using 'default' plugin... -[1459246273.43][SERI][INF] wait for it... -[1459246274.43][CONN][INF] sending preamble '5daa5ff9-a9c1-4b47-88a2-9295f1de7c64'... -[1459246274.43][SERI][TXD] mbedmbedmbedmbedmbedmbedmbedmbedmbedmbed -[1459246274.43][SERI][TXD] {{__sync;5daa5ff9-a9c1-4b47-88a2-9295f1de7c64}} -[1459246274.58][CONN][INF] found SYNC in stream: {{__sync;5daa5ff9-a9c1-4b47-88a2-9295f1de7c64}}, queued... -[1459246274.58][CONN][RXD] {{__sync;5daa5ff9-a9c1-4b47-88a2-9295f1de7c64}} -[1459246274.58][HTST][INF] sync KV found, uuid=5daa5ff9-a9c1-4b47-88a2-9295f1de7c64, timestamp=1459246274.575000 -[1459246274.60][CONN][INF] found KV pair in stream: {{__version;1.1.0}}, queued... -[1459246274.60][CONN][RXD] {{__version;1.1.0}} -[1459246274.60][HTST][INF] DUT greentea-client version: 1.1.0 -[1459246274.61][CONN][INF] found KV pair in stream: {{__timeout;5}}, queued... -[1459246274.61][HTST][INF] setting timeout to: 5 sec -[1459246274.62][CONN][RXD] {{__timeout;5}} -[1459246274.64][CONN][INF] found KV pair in stream: {{__host_test_name;default_auto}}, queued... -[1459246274.64][HTST][INF] host test setup() call... -[1459246274.64][HTST][INF] CALLBACKs updated -[1459246274.64][HTST][INF] host test detected: default_auto -[1459246274.64][CONN][RXD] {{__host_test_name;default_auto}} -[1459246274.66][CONN][INF] found KV pair in stream: {{__testcase_count;8}}, queued... -[1459246274.66][CONN][RXD] {{__testcase_count;8}} -[1459246274.69][CONN][RXD] >>> Running 8 test cases... -[1459246274.74][CONN][RXD] >>> Running case #1: 'C strings: strtok'... -[1459246274.79][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: strtok}}, queued... -[1459246274.79][CONN][RXD] {{__testcase_start;C strings: strtok}} -[1459246274.84][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: strtok;1;0}}, queued... -[1459246274.84][CONN][RXD] {{__testcase_finish;C strings: strtok;1;0}} -[1459246274.88][CONN][RXD] >>> 'C strings: strtok': 1 passed, 0 failed -[1459246274.93][CONN][RXD] >>> Running case #2: 'C strings: strpbrk'... -[1459246274.97][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: strpbrk}}, queued... -[1459246274.97][CONN][RXD] {{__testcase_start;C strings: strpbrk}} -[1459246275.01][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: strpbrk;1;0}}, queued... -[1459246275.01][CONN][RXD] {{__testcase_finish;C strings: strpbrk;1;0}} -[1459246275.06][CONN][RXD] >>> 'C strings: strpbrk': 1 passed, 0 failed -[1459246275.13][CONN][RXD] >>> Running case #3: 'C strings: %i %d integer formatting'... -[1459246275.18][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %i %d integer formatting}}, queued... -[1459246275.18][CONN][RXD] {{__testcase_start;C strings: %i %d integer formatting}} -[1459246275.24][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %i %d integer formatting;1;0}}, queued... -[1459246275.24][CONN][RXD] {{__testcase_finish;C strings: %i %d integer formatting;1;0}} -[1459246275.32][CONN][RXD] >>> 'C strings: %i %d integer formatting': 1 passed, 0 failed -[1459246275.38][CONN][RXD] >>> Running case #4: 'C strings: %u %d integer formatting'... -[1459246275.44][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %u %d integer formatting}}, queued... -[1459246275.44][CONN][RXD] {{__testcase_start;C strings: %u %d integer formatting}} -[1459246275.50][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %u %d integer formatting;1;0}}, queued... -[1459246275.50][CONN][RXD] {{__testcase_finish;C strings: %u %d integer formatting;1;0}} -[1459246275.57][CONN][RXD] >>> 'C strings: %u %d integer formatting': 1 passed, 0 failed -[1459246275.64][CONN][RXD] >>> Running case #5: 'C strings: %x %E integer formatting'... -[1459246275.68][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %x %E integer formatting}}, queued... -[1459246275.68][CONN][RXD] {{__testcase_start;C strings: %x %E integer formatting}} -[1459246275.74][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %x %E integer formatting;1;0}}, queued... -[1459246275.74][CONN][RXD] {{__testcase_finish;C strings: %x %E integer formatting;1;0}} -[1459246275.82][CONN][RXD] >>> 'C strings: %x %E integer formatting': 1 passed, 0 failed -[1459246275.88][CONN][RXD] >>> Running case #6: 'C strings: %f %f float formatting'... -[1459246275.94][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %f %f float formatting}}, queued... -[1459246275.94][CONN][RXD] {{__testcase_start;C strings: %f %f float formatting}} -[1459246276.10][CONN][RXD] :57::FAIL: Expected '0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000' Was ' -' -[1459246276.18][CONN][RXD] >>> failure with reason 'Assertion Failed' during 'Case Handler' -[1459246276.25][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %f %f float formatting;0;1}}, queued... -[1459246276.25][CONN][RXD] {{__testcase_finish;C strings: %f %f float formatting;0;1}} -[1459246276.34][CONN][RXD] >>> 'C strings: %f %f float formatting': 0 passed, 1 failed with reason 'Test Cases Failed' -[1459246276.41][CONN][RXD] >>> Running case #7: 'C strings: %e %E float formatting'... -[1459246276.46][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %e %E float formatting}}, queued... -[1459246276.46][CONN][RXD] {{__testcase_start;C strings: %e %E float formatting}} -[1459246276.52][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %e %E float formatting;1;0}}, queued... -[1459246276.53][CONN][RXD] {{__testcase_finish;C strings: %e %E float formatting;1;0}} -[1459246276.59][CONN][RXD] >>> 'C strings: %e %E float formatting': 1 passed, 0 failed -[1459246276.65][CONN][RXD] >>> Running case #8: 'C strings: %g %g float formatting'... -[1459246276.71][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %g %g float formatting}}, queued... -[1459246276.71][CONN][RXD] {{__testcase_start;C strings: %g %g float formatting}} -[1459246276.77][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %g %g float formatting;1;0}}, queued... -[1459246276.77][CONN][RXD] {{__testcase_finish;C strings: %g %g float formatting;1;0}} -[1459246276.83][CONN][RXD] >>> 'C strings: %g %g float formatting': 1 passed, 0 failed -[1459246276.90][CONN][RXD] >>> Test cases: 7 passed, 1 failed with reason 'Test Cases Failed' -[1459246276.92][CONN][RXD] >>> TESTS FAILED! -[1459246276.95][CONN][INF] found KV pair in stream: {{__testcase_summary;7;1}}, queued... -[1459246276.95][CONN][RXD] {{__testcase_summary;7;1}} -[1459246276.97][CONN][INF] found KV pair in stream: {{end;failure}}, queued... -[1459246276.97][CONN][RXD] {{end;failure}} -[1459246276.97][HTST][INF] __notify_complete(False) -[1459246276.97][HTST][INF] test suite run finished after 2.37 sec... -[1459246276.98][HTST][INF] CONN exited with code: 0 -[1459246276.98][HTST][INF] Some events in queue -[1459246276.98][HTST][INF] stopped consuming events -[1459246276.98][HTST][INF] host test result() call skipped, received: False -[1459246276.98][HTST][WRN] missing __exit event from DUT -[1459246276.98][HTST][INF] calling blocking teardown() -[1459246276.98][HTST][INF] teardown() finished -[1459246276.98][HTST][INF] {{result;failure}} -""" - - self.OUTOUT_CSTRING_TEST_CASE_COUNT_AND_NAME = """ -[1467197417.13][SERI][TXD] {{__sync;3018cb93-f11c-417e-bf61-240c338dfec9}} -[1467197417.27][CONN][RXD] {{__sync;3018cb93-f11c-417e-bf61-240c338dfec9}} -[1467197417.27][CONN][INF] found SYNC in stream: {{__sync;3018cb93-f11c-417e-bf61-240c338dfec9}} it is #0 sent, queued... -[1467197417.27][HTST][INF] sync KV found, uuid=3018cb93-f11c-417e-bf61-240c338dfec9, timestamp=1467197417.272000 -[1467197417.29][CONN][RXD] {{__version;1.1.0}} -[1467197417.29][CONN][INF] found KV pair in stream: {{__version;1.1.0}}, queued... -[1467197417.29][HTST][INF] DUT greentea-client version: 1.1.0 -[1467197417.31][CONN][RXD] {{__timeout;5}} -[1467197417.31][CONN][INF] found KV pair in stream: {{__timeout;5}}, queued... -[1467197417.31][HTST][INF] setting timeout to: 5 sec -[1467197417.34][CONN][RXD] {{__host_test_name;default_auto}} -[1467197417.34][CONN][INF] found KV pair in stream: {{__host_test_name;default_auto}}, queued... -[1467197417.34][HTST][INF] host test class: '' -[1467197417.34][HTST][INF] host test setup() call... -[1467197417.34][HTST][INF] CALLBACKs updated -[1467197417.34][HTST][INF] host test detected: default_auto -[1467197417.36][CONN][RXD] {{__testcase_count;2}} -[1467197417.36][CONN][INF] found KV pair in stream: {{__testcase_count;2}}, queued... -[1467197417.39][CONN][RXD] >>> Running 2 test cases... -[1467197417.43][CONN][RXD] {{__testcase_name;C strings: strtok}} -[1467197417.43][CONN][INF] found KV pair in stream: {{__testcase_name;C strings: strtok}}, queued... -[1467197417.47][CONN][RXD] {{__testcase_name;C strings: strpbrk}} -[1467197417.47][CONN][INF] found KV pair in stream: {{__testcase_name;C strings: strpbrk}}, queued... -[1467197417.52][CONN][RXD] >>> Running case #1: 'C strings: strtok'... -[1467197417.56][CONN][RXD] {{__testcase_start;C strings: strtok}} -[1467197417.56][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: strtok}}, queued... -[1467197422.31][HTST][INF] test suite run finished after 5.00 sec... -[1467197422.31][CONN][INF] received special even '__host_test_finished' value='True', finishing -[1467197422.33][HTST][INF] CONN exited with code: 0 -[1467197422.33][HTST][INF] No events in queue -[1467197422.33][HTST][INF] stopped consuming events -[1467197422.33][HTST][INF] host test result(): None -[1467197422.33][HTST][WRN] missing __exit event from DUT -[1467197422.33][HTST][ERR] missing __exit event from DUT and no result from host test, timeout... -[1467197422.33][HTST][INF] calling blocking teardown() -[1467197422.33][HTST][INF] teardown() finished -[1467197422.33][HTST][INF] {{result;timeout}} -""" - - self.OUTOUT_GENERIC_TESTS_TESCASE_NAME_AND_COUNT = """ -[1467205002.74][HTST][INF] host test executor ver. 0.2.19 -[1467205002.74][HTST][INF] copy image onto target... - 1 file(s) copied. -Plugin info: HostTestPluginCopyMethod_Shell::CopyMethod: Waiting up to 60 sec for '0240000033514e450019500585d40008e981000097969900' mount point (current is 'F:')... -[1467205011.16][HTST][INF] starting host test process... -[1467205011.74][CONN][INF] starting serial connection process... -[1467205011.74][CONN][INF] notify event queue about extra 60 sec timeout for serial port pooling -[1467205011.74][CONN][INF] initializing serial port listener... -[1467205011.74][HTST][INF] setting timeout to: 60 sec -[1467205011.74][SERI][INF] serial(port=COM219, baudrate=9600, timeout=0) -Plugin info: HostTestPluginBase::BasePlugin: Waiting up to 60 sec for '0240000033514e450019500585d40008e981000097969900' serial port (current is 'COM219')... -[1467205011.83][SERI][INF] reset device using 'default' plugin... -[1467205012.08][SERI][INF] waiting 1.00 sec after reset -[1467205013.08][SERI][INF] wait for it... -[1467205013.08][SERI][TXD] mbedmbedmbedmbedmbedmbedmbedmbedmbedmbed -[1467205013.08][CONN][INF] sending up to 2 __sync packets (specified with --sync=2) -[1467205013.08][CONN][INF] sending preamble 'f82e0251-bb3e-4434-bc93-b780b5d0e82a' -[1467205013.08][SERI][TXD] {{__sync;f82e0251-bb3e-4434-bc93-b780b5d0e82a}} -[1467205013.22][CONN][RXD] {{__sync;f82e0251-bb3e-4434-bc93-b780b5d0e82a}} -[1467205013.22][CONN][INF] found SYNC in stream: {{__sync;f82e0251-bb3e-4434-bc93-b780b5d0e82a}} it is #0 sent, queued... -[1467205013.22][HTST][INF] sync KV found, uuid=f82e0251-bb3e-4434-bc93-b780b5d0e82a, timestamp=1467205013.219000 -[1467205013.24][CONN][RXD] {{__version;1.1.0}} -[1467205013.24][CONN][INF] found KV pair in stream: {{__version;1.1.0}}, queued... -[1467205013.24][HTST][INF] DUT greentea-client version: 1.1.0 -[1467205013.25][CONN][RXD] {{__timeout;20}} -[1467205013.26][CONN][INF] found KV pair in stream: {{__timeout;20}}, queued... -[1467205013.26][HTST][INF] setting timeout to: 20 sec -[1467205013.29][CONN][RXD] {{__host_test_name;default_auto}} -[1467205013.29][CONN][INF] found KV pair in stream: {{__host_test_name;default_auto}}, queued... -[1467205013.29][HTST][INF] host test class: '' -[1467205013.29][HTST][INF] host test setup() call... -[1467205013.29][HTST][INF] CALLBACKs updated -[1467205013.29][HTST][INF] host test detected: default_auto -[1467205013.31][CONN][RXD] {{__testcase_count;4}} -[1467205013.31][CONN][INF] found KV pair in stream: {{__testcase_count;4}}, queued... -[1467205013.34][CONN][RXD] >>> Running 4 test cases... -[1467205013.37][CONN][RXD] {{__testcase_name;Basic}} -[1467205013.37][CONN][INF] found KV pair in stream: {{__testcase_name;Basic}}, queued... -[1467205013.40][CONN][RXD] {{__testcase_name;Blinky}} -[1467205013.40][CONN][INF] found KV pair in stream: {{__testcase_name;Blinky}}, queued... -[1467205013.43][CONN][RXD] {{__testcase_name;C++ stack}} -[1467205013.43][CONN][INF] found KV pair in stream: {{__testcase_name;C++ stack}}, queued... -[1467205013.46][CONN][RXD] {{__testcase_name;C++ heap}} -[1467205013.46][CONN][INF] found KV pair in stream: {{__testcase_name;C++ heap}}, queued... -[1467205013.49][CONN][RXD] >>> Running case #1: 'Basic'... -[1467205013.52][CONN][RXD] {{__testcase_start;Basic}} -[1467205013.52][CONN][INF] found KV pair in stream: {{__testcase_start;Basic}}, queued... -[1467205013.56][CONN][RXD] {{__testcase_finish;Basic;1;0}} -[1467205013.56][CONN][INF] found KV pair in stream: {{__testcase_finish;Basic;1;0}}, queued... -[1467205013.59][CONN][RXD] >>> 'Basic': 1 passed, 0 failed -[1467205013.62][CONN][RXD] >>> Running case #2: 'Blinky'... -[1467205013.65][CONN][RXD] {{__testcase_start;Blinky}} -[1467205013.65][CONN][INF] found KV pair in stream: {{__testcase_start;Blinky}}, queued... -[1467205013.69][CONN][RXD] {{__testcase_finish;Blinky;1;0}} -[1467205013.69][CONN][INF] found KV pair in stream: {{__testcase_finish;Blinky;1;0}}, queued... -[1467205013.72][CONN][RXD] >>> 'Blinky': 1 passed, 0 failed -[1467205013.75][CONN][RXD] >>> Running case #3: 'C++ stack'... -[1467205013.78][CONN][RXD] {{__testcase_start;C++ stack}} -[1467205013.78][CONN][INF] found KV pair in stream: {{__testcase_start;C++ stack}}, queued... -[1467205013.79][CONN][RXD] Static::init -[1467205013.81][CONN][RXD] Static::stack_test -[1467205013.82][CONN][RXD] Stack::init -[1467205013.85][CONN][RXD] Stack::hello -[1467205013.87][CONN][RXD] Stack::destroy -[1467205013.89][CONN][RXD] Static::check_init: OK -[1467205013.91][CONN][RXD] Static::destroy -[1467205013.94][CONN][RXD] {{__testcase_finish;C++ stack;1;0}} -[1467205013.95][CONN][INF] found KV pair in stream: {{__testcase_finish;C++ stack;1;0}}, queued... -[1467205013.98][CONN][RXD] >>> 'C++ stack': 1 passed, 0 failed -[1467205014.02][CONN][RXD] >>> Running case #4: 'C++ heap'... -[1467205014.05][CONN][RXD] {{__testcase_start;C++ heap}} -[1467205014.05][CONN][INF] found KV pair in stream: {{__testcase_start;C++ heap}}, queued... -[1467205014.06][CONN][RXD] Heap::init -[1467205014.07][CONN][RXD] Heap::hello -[1467205014.10][CONN][RXD] Heap::check_init: OK -[1467205014.11][CONN][RXD] Heap::destroy -[1467205014.15][CONN][RXD] {{__testcase_finish;C++ heap;1;0}} -[1467205014.15][CONN][INF] found KV pair in stream: {{__testcase_finish;C++ heap;1;0}}, queued... -[1467205014.18][CONN][RXD] >>> 'C++ heap': 1 passed, 0 failed -[1467205014.22][CONN][RXD] >>> Test cases: 4 passed, 0 failed -[1467205014.25][CONN][RXD] {{__testcase_summary;4;0}} -[1467205014.25][CONN][INF] found KV pair in stream: {{__testcase_summary;4;0}}, queued... -[1467205014.27][CONN][RXD] {{end;success}} -[1467205014.27][CONN][INF] found KV pair in stream: {{end;success}}, queued... -[1467205014.28][CONN][RXD] {{__exit;0}} -[1467205014.28][CONN][INF] found KV pair in stream: {{__exit;0}}, queued... -[1467205014.28][HTST][INF] __exit(0) -[1467205014.28][HTST][INF] test suite run finished after 1.02 sec... -[1467205014.28][CONN][INF] received special even '__host_test_finished' value='True', finishing -[1467205014.31][HTST][INF] CONN exited with code: 0 -[1467205014.31][HTST][INF] Some events in queue -[1467205014.31][HTST][INF] __notify_complete(True) -[1467205014.31][HTST][INF] stopped consuming events -[1467205014.31][HTST][INF] host test result() call skipped, received: True -[1467205014.31][HTST][INF] calling blocking teardown() -[1467205014.31][HTST][INF] teardown() finished -[1467205014.31][HTST][INF] {{result;success}} -""" - - self.OUTPUT_WITH_MEMORY_METRICS = """mbedgt: mbed-host-test-runner: started -[1459245860.90][CONN][RXD] {{__testcase_summary;4;0}} -[1459245860.92][CONN][INF] found KV pair in stream: {{end;success}}, queued... -[1459245860.92][CONN][RXD] {{end;success}} -[1459245860.92][CONN][INF] found KV pair in stream: {{max_heap_usage;2284}}, queued... -[1459245860.92][CONN][RXD] {{end;success}} -[1459245860.92][CONN][INF] found KV pair in stream: {{reserved_heap;124124}}, queued... -[1459245860.92][CONN][RXD] {{end;success}} -[1459245860.92][CONN][INF] found KV pair in stream: {{__thread_info;"BE-EF",42,24}}, queued... -[1459245860.92][CONN][RXD] {{end;success}} -[1459245860.92][HTST][INF] __notify_complete(True) -[1459245860.92][CONN][RXD] {{__coverage_start;c:\Work\core-util/source/PoolAllocator.cpp.gcda;6164636772393034c2733f32...a33e...b9}} -[1459245860.92][HTST][INF] test suite run finished after 0.90 sec... -[1459245860.94][HTST][INF] CONN exited with code: 0 -[1459245860.94][HTST][INF] No events in queue -[1459245860.94][HTST][INF] stopped consuming events -[1459245860.94][HTST][INF] host test result() call skipped, received: True -[1459245860.94][HTST][WRN] missing __exit event from DUT -[1459245860.94][HTST][INF] calling blocking teardown() -[1459245860.94][HTST][INF] teardown() finished -[1459245860.94][HTST][INF] {{result;success}} -""" - - def tearDown(self): - pass - - def test_get_test_result(self): - self.assertEqual(mbed_test_api.TEST_RESULT_OK, mbed_test_api.get_test_result(self.OUTPUT_SUCCESS)) - self.assertEqual(mbed_test_api.TEST_RESULT_FAIL, mbed_test_api.get_test_result(self.OUTPUT_FAILURE)) - self.assertEqual(mbed_test_api.TEST_RESULT_TIMEOUT, mbed_test_api.get_test_result(self.OUTPUT_TIMEOUT)) - self.assertEqual(mbed_test_api.TEST_RESULT_UNDEF, mbed_test_api.get_test_result(self.OUTPUT_UNDEF)) - - def test_get_test_result_ok_len(self): - r = mbed_test_api.get_testcase_utest(self.OUTOUT_CSTRING_TEST, 'C strings: %e %E float formatting') - - self.assertEqual(len(r), 6) - self.assertIn("[1459246276.41][CONN][RXD] >>> Running case #7: 'C strings: %e %E float formatting'...", r) - self.assertIn("[1459246276.46][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %e %E float formatting}}, queued...", r) - self.assertIn("[1459246276.46][CONN][RXD] {{__testcase_start;C strings: %e %E float formatting}}", r) - self.assertIn("[1459246276.52][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %e %E float formatting;1;0}}, queued...", r) - self.assertIn("[1459246276.53][CONN][RXD] {{__testcase_finish;C strings: %e %E float formatting;1;0}}", r) - self.assertIn("[1459246276.59][CONN][RXD] >>> 'C strings: %e %E float formatting': 1 passed, 0 failed", r) - - - def test_get_test_result_fail_len(self): - r = mbed_test_api.get_testcase_utest(self.OUTOUT_CSTRING_TEST, 'C strings: %f %f float formatting') - - self.assertEqual(len(r), 9) - self.assertIn("[1459246275.88][CONN][RXD] >>> Running case #6: 'C strings: %f %f float formatting'...", r) - self.assertIn("[1459246275.94][CONN][INF] found KV pair in stream: {{__testcase_start;C strings: %f %f float formatting}}, queued...", r) - self.assertIn("[1459246275.94][CONN][RXD] {{__testcase_start;C strings: %f %f float formatting}}", r) - self.assertIn("[1459246276.10][CONN][RXD] :57::FAIL: Expected '0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000' Was '", r) - self.assertIn("'", r) - self.assertIn("[1459246276.18][CONN][RXD] >>> failure with reason 'Assertion Failed' during 'Case Handler'", r) - self.assertIn("[1459246276.25][CONN][INF] found KV pair in stream: {{__testcase_finish;C strings: %f %f float formatting;0;1}}, queued...", r) - self.assertIn("[1459246276.25][CONN][RXD] {{__testcase_finish;C strings: %f %f float formatting;0;1}}", r) - self.assertIn("[1459246276.34][CONN][RXD] >>> 'C strings: %f %f float formatting': 0 passed, 1 failed with reason 'Test Cases Failed'", r) - - def get_testcase_count_and_names(self): - tc_count, tc_names = mbed_test_api.get_testcase_count_and_names(self.OUTOUT_CSTRING_TEST_CASE_COUNT_AND_NAME) - - self.assertEqual(tc_count, 2) - self.assertIn('C strings: strtok', tc_names) - self.assertIn('C strings: strpbrk', tc_names) - - def test_get_test_result_return_val(self): - - test_case_names = [ - 'C strings: %e %E float formatting', - 'C strings: %g %g float formatting', - 'C strings: %i %d integer formatting', - 'C strings: %u %d integer formatting', - 'C strings: %x %E integer formatting', - 'C strings: strpbrk', - 'C strings: strtok' - ] - - for test_case in test_case_names: - r = mbed_test_api.get_testcase_utest(self.OUTOUT_CSTRING_TEST, test_case) - self.assertEqual(len(r), 6) - - # This failing test case has different long lenght - r = mbed_test_api.get_testcase_utest(self.OUTOUT_CSTRING_TEST, 'C strings: %f %f float formatting') - self.assertEqual(len(r), 9) - - def test_get_testcase_summary_failures(self): - r = mbed_test_api.get_testcase_summary("{{__testcase_summary;;}}") - self.assertEqual(None, r) - - r = mbed_test_api.get_testcase_summary("{{__testcase_summary;-1;-2}}") - self.assertEqual(None, r) - - r = mbed_test_api.get_testcase_summary("{{__testcase_summary;A;0}}") - self.assertEqual(None, r) - - def test_get_testcase_summary_value_failures(self): - r = mbed_test_api.get_testcase_summary("[1459246276.95][CONN][INF] found KV pair in stream: {{__testcase_summary;;}}") - self.assertEqual(None, r) - - r = mbed_test_api.get_testcase_summary("[1459246276.95][CONN][INF] found KV pair in stream: {{__testcase_summary;-1;-2}}") - self.assertEqual(None, r) - - r = mbed_test_api.get_testcase_summary("[1459246276.95][CONN][INF] found KV pair in stream: {{__testcase_summary;A;0}}") - self.assertEqual(None, r) - - def test_get_testcase_summary_ok(self): - - r = mbed_test_api.get_testcase_summary("[1459246276.95][CONN][INF] found KV pair in stream: {{__testcase_summary;0;0}}") - self.assertNotEqual(None, r) - self.assertEqual((0, 0), r) - - r = mbed_test_api.get_testcase_summary(self.OUTOUT_CSTRING_TEST) - self.assertNotEqual(None, r) - self.assertEqual((7, 1), r) # {{__testcase_summary;7;1}} - - r = mbed_test_api.get_testcase_summary(self.OUTPUT_SUCCESS) - self.assertNotEqual(None, r) - self.assertEqual((4, 0), r) # {{__testcase_summary;4;0}} - - def test_get_testcase_result(self): - r = mbed_test_api.get_testcase_result(self.OUTOUT_CSTRING_TEST) - self.assertEqual(len(r), 8) - - test_case_names = [ - 'C strings: %e %E float formatting', - 'C strings: %g %g float formatting', - 'C strings: %i %d integer formatting', - 'C strings: %u %d integer formatting', - 'C strings: %x %E integer formatting', - 'C strings: strpbrk', - 'C strings: strtok' - ] - - for test_case in test_case_names: - tc = r[test_case] - # If data structure is correct - self.assertIn('utest_log', tc) - self.assertIn('time_start', tc) - self.assertIn('time_end', tc) - self.assertIn('failed', tc) - self.assertIn('result', tc) - self.assertIn('passed', tc) - self.assertIn('duration', tc) - # values passed - self.assertEqual(tc['passed'], 1) - self.assertEqual(tc['failed'], 0) - self.assertEqual(tc['result_text'], 'OK') - - # Failing test case - tc = r['C strings: %f %f float formatting'] - self.assertEqual(tc['passed'], 0) - self.assertEqual(tc['failed'], 1) - self.assertEqual(tc['result_text'], 'FAIL') - - def test_get_testcase_result_tescase_name_and_count(self): - r = mbed_test_api.get_testcase_result(self.OUTOUT_GENERIC_TESTS_TESCASE_NAME_AND_COUNT) - self.assertEqual(len(r), 4) - - self.assertIn('Basic', r) - self.assertIn('Blinky', r) - self.assertIn('C++ heap', r) - self.assertIn('C++ stack', r) - - def test_get_testcase_result_tescase_name_and_count(self): - r = mbed_test_api.get_testcase_result(self.OUTOUT_CSTRING_TEST_CASE_COUNT_AND_NAME) - self.assertEqual(len(r), 2) - - self.assertIn('C strings: strpbrk', r) - self.assertIn('C strings: strtok', r) - - self.assertEqual(r['C strings: strpbrk']['result_text'], 'SKIPPED') - self.assertEqual(r['C strings: strtok']['result_text'], 'ERROR') - - - def test_get_test_results_empty_output(self): - result = mbed_test_api.get_test_result("") - self.assertEqual(result, "TIMEOUT") - - def test_get_memory_metrics(self): - result = mbed_test_api.get_memory_metrics(self.OUTPUT_WITH_MEMORY_METRICS) - - self.assertEqual(result[0], 2284) - self.assertEqual(result[1], 124124) - thread_info = list(result[2])[0] - self.assertIn("entry", thread_info) - self.assertEqual(thread_info["entry"], "BE") - self.assertIn("stack_size", thread_info) - self.assertEqual(thread_info["stack_size"], 24) - self.assertIn("max_stack", thread_info) - self.assertEqual(thread_info["max_stack"], 42) - self.assertIn("arg", thread_info) - self.assertEqual(thread_info["arg"], "EF") - - def test_get_testcase_result_start_tag_missing(self): - result = mbed_test_api.get_testcase_result(self.OUTPUT_STARTTAG_MISSING) - self.assertEqual(result['DNS query']['utest_log'], "__testcase_start tag not found.") - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_test_filtered_test_list.py b/tools/python/python_tests/mbed_greentea/mbed_gt_test_filtered_test_list.py deleted file mode 100644 index 65938ce4c1c..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_test_filtered_test_list.py +++ /dev/null @@ -1,294 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest -from mbed_greentea import mbed_greentea_cli - -class GreenteaFilteredTestList(unittest.TestCase): - - def setUp(self): - self.ctest_test_list = {'test1': '\\build\\test1.bin', - 'test2': '\\build\\test2.bin', - 'test3': '\\build\\test3.bin', - 'test4': '\\build\\test4.bin'} - self.test_by_names = None - self.skip_test = None - - self.ctest_test_list_mbed_drivers = {'mbed-drivers-test-c_strings' : './build/mbed-drivers-test-c_strings.bin', - 'mbed-drivers-test-dev_null' : './build/mbed-drivers-test-dev_null.bin', - 'mbed-drivers-test-echo' : './build/mbed-drivers-test-echo.bin', - 'mbed-drivers-test-generic_tests' : './build/mbed-drivers-test-generic_tests.bin', - 'mbed-drivers-test-rtc' : './build/mbed-drivers-test-rtc.bin', - 'mbed-drivers-test-stl_features' : './build/mbed-drivers-test-stl_features.bin', - 'mbed-drivers-test-ticker' : './build/mbed-drivers-test-ticker.bin', - 'mbed-drivers-test-ticker_2' : './build/mbed-drivers-test-ticker_2.bin', - 'mbed-drivers-test-ticker_3' : './build/mbed-drivers-test-ticker_3.bin', - 'mbed-drivers-test-timeout' : './build/mbed-drivers-test-timeout.bin', - 'mbed-drivers-test-wait_us' : './build/mbed-drivers-test-wait_us.bin'} - - self.ctest_test_list_mbed_drivers_ext = {'tests-integration-threaded_blinky' : './build/tests-integration-threaded_blinky.bin', - 'tests-mbed_drivers-c_strings' : './build/tests-mbed_drivers-c_strings.bin', - 'tests-mbed_drivers-callback' : './build/tests-mbed_drivers-callback.bin', - 'tests-mbed_drivers-dev_null' : './build/tests-mbed_drivers-dev_null.bin', - 'tests-mbed_drivers-echo' : './build/tests-mbed_drivers-echo.bin', - 'tests-mbed_drivers-generic_tests' : './build/tests-mbed_drivers-generic_tests.bin', - 'tests-mbed_drivers-rtc' : './build/tests-mbed_drivers-rtc.bin', - 'tests-mbed_drivers-stl_features' : './build/tests-mbed_drivers-stl_features.bin', - 'tests-mbed_drivers-ticker' : './build/tests-mbed_drivers-ticker.bin', - 'tests-mbed_drivers-ticker_2' : './build/tests-mbed_drivers-ticker_2.bin', - 'tests-mbed_drivers-ticker_3' : './build/tests-mbed_drivers-ticker_3.bin', - 'tests-mbed_drivers-timeout' : './build/tests-mbed_drivers-timeout.bin', - 'tests-mbed_drivers-wait_us' : './build/tests-mbed_drivers-wait_us.bin', - 'tests-mbedmicro-mbed-attributes' : './build/tests-mbedmicro-mbed-attributes.bin', - 'tests-mbedmicro-mbed-call_before_main' : './build/tests-mbedmicro-mbed-call_before_main.bin', - 'tests-mbedmicro-mbed-cpp' : './build/tests-mbedmicro-mbed-cpp.bin', - 'tests-mbedmicro-mbed-div' : './build/tests-mbedmicro-mbed-div.bin', - 'tests-mbedmicro-mbed-heap_and_stack' : './build/tests-mbedmicro-mbed-heap_and_stack.bin', - 'tests-mbedmicro-rtos-mbed-basic' : './build/tests-mbedmicro-rtos-mbed-basic.bin', - 'tests-mbedmicro-rtos-mbed-isr' : './build/tests-mbedmicro-rtos-mbed-isr.bin', - 'tests-mbedmicro-rtos-mbed-mail' : './build/tests-mbedmicro-rtos-mbed-mail.bin', - 'tests-mbedmicro-rtos-mbed-mutex' : './build/tests-mbedmicro-rtos-mbed-mutex.bin', - 'tests-mbedmicro-rtos-mbed-queue' : './build/tests-mbedmicro-rtos-mbed-queue.bin', - 'tests-mbedmicro-rtos-mbed-semaphore' : './build/tests-mbedmicro-rtos-mbed-semaphore.bin', - 'tests-mbedmicro-rtos-mbed-signals' : './build/tests-mbedmicro-rtos-mbed-signals.bin', - 'tests-mbedmicro-rtos-mbed-threads' : './build/tests-mbedmicro-rtos-mbed-threads.bin', - 'tests-mbedmicro-rtos-mbed-timer' : './build/tests-mbedmicro-rtos-mbed-timer.bin', - 'tests-storage_abstraction-basicapi' : './build/tests-storage_abstraction-basicapi.bin'} - - def tearDown(self): - pass - - def test_filter_test_list(self): - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {'test1': '\\build\\test1.bin', - 'test2': '\\build\\test2.bin', - 'test3': '\\build\\test3.bin', - 'test4': '\\build\\test4.bin'} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_skip_test(self): - self.skip_test = 'test1,test2' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {'test3': '\\build\\test3.bin', - 'test4': '\\build\\test4.bin'} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_skip_test_invaild(self): - self.skip_test='test1,testXY' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {'test2': '\\build\\test2.bin', - 'test3': '\\build\\test3.bin', - 'test4': '\\build\\test4.bin'} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_test_by_names(self): - self.test_by_names='test3' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {'test3': '\\build\\test3.bin'} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_test_by_names_invalid(self): - self.test_by_names='test3,testXY' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {'test3': '\\build\\test3.bin'} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_list_is_None_skip_test(self): - self.ctest_test_list = None - self.skip_test='test3' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_list_is_None_test_by_names(self): - self.ctest_test_list = None - self.test_by_names='test3' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_list_is_Empty_skip_test(self): - self.ctest_test_list = {} - self.skip_test='test4' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_list_is_Empty_test_by_names(self): - self.ctest_test_list = {} - self.test_by_names='test4' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list, - self.test_by_names, - self.skip_test) - - filtered_test_list = {} - self.assertEqual(filtered_test_list, filtered_ctest_test_list) - - def test_prefix_filter_one_star(self): - self.test_by_names='mbed-drivers-test-t*' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-ticker_3', - 'mbed-drivers-test-timeout'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_one_star_and_no_star(self): - self.test_by_names='mbed-drivers-test-t*,mbed-drivers-test-rtc' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-ticker_3', - 'mbed-drivers-test-timeout', - 'mbed-drivers-test-rtc'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_no_star(self): - self.test_by_names='mbed-drivers-test-ticker_2,mbed-drivers-test-rtc,mbed-drivers-test-ticker' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-rtc'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_merge_n_and_i(self): - self.test_by_names='mbed-drivers-test-ticker_2,mbed-drivers-test-ticker_3,mbed-drivers-test-rtc,mbed-drivers-test-ticker' - self.skip_test = 'mbed-drivers-test-ticker_3' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-rtc'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_merge_n_and_i_repeated(self): - self.test_by_names='mbed-drivers-test-ticker_2,mbed-drivers-test-ticker_3,mbed-drivers-test-rtc,mbed-drivers-test-ticker' - self.skip_test = 'mbed-drivers-test-ticker_3,mbed-drivers-test-ticker_3' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-rtc'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_merge_n_and_i_missing(self): - self.test_by_names='mbed-drivers-test-ticker_2,mbed-drivers-test-ticker_3,mbed-drivers-test-rtc,mbed-drivers-test-ticker' - self.skip_test = 'mbed-drivers-test-ticker_XXX' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers, - self.test_by_names, - self.skip_test) - - expected = ['mbed-drivers-test-ticker', - 'mbed-drivers-test-ticker_2', - 'mbed-drivers-test-ticker_3', - 'mbed-drivers-test-rtc'] - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_merge_n_multi_star(self): - self.test_by_names='tests-mbedmicro-mbed*,tests-mbedmicro-rtos*' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers_ext, - self.test_by_names, - self.skip_test) - - expected = ['tests-mbedmicro-mbed-attributes', - 'tests-mbedmicro-mbed-call_before_main', - 'tests-mbedmicro-mbed-cpp', - 'tests-mbedmicro-mbed-div', - 'tests-mbedmicro-mbed-heap_and_stack', - 'tests-mbedmicro-rtos-mbed-basic', - 'tests-mbedmicro-rtos-mbed-isr', - 'tests-mbedmicro-rtos-mbed-mail', - 'tests-mbedmicro-rtos-mbed-mutex', - 'tests-mbedmicro-rtos-mbed-queue', - 'tests-mbedmicro-rtos-mbed-semaphore', - 'tests-mbedmicro-rtos-mbed-signals', - 'tests-mbedmicro-rtos-mbed-threads', - 'tests-mbedmicro-rtos-mbed-timer'] - - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - - def test_prefix_filter_merge_n_multi_star_and_i(self): - self.test_by_names='tests-mbedmicro-mbed*,tests-mbedmicro-rtos*' - self.skip_test='tests-mbedmicro-rtos-mbed-isr,tests-mbedmicro-rtos-mbed-semaphore,tests-mbedmicro-mbed-call_before_main' - filtered_ctest_test_list = mbed_greentea_cli.create_filtered_test_list(self.ctest_test_list_mbed_drivers_ext, - self.test_by_names, - self.skip_test) - - expected = ['tests-mbedmicro-mbed-attributes', - #'tests-mbedmicro-mbed-call_before_main', - 'tests-mbedmicro-mbed-cpp', - 'tests-mbedmicro-mbed-div', - 'tests-mbedmicro-mbed-heap_and_stack', - 'tests-mbedmicro-rtos-mbed-basic', - #'tests-mbedmicro-rtos-mbed-isr', - 'tests-mbedmicro-rtos-mbed-mail', - 'tests-mbedmicro-rtos-mbed-mutex', - 'tests-mbedmicro-rtos-mbed-queue', - #'tests-mbedmicro-rtos-mbed-semaphore', - 'tests-mbedmicro-rtos-mbed-signals', - 'tests-mbedmicro-rtos-mbed-threads', - 'tests-mbedmicro-rtos-mbed-timer'] - - self.assertEqual(len(expected), len(filtered_ctest_test_list)) - self.assertEqual(set(filtered_ctest_test_list.keys()), set(expected)) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_tests_spec.py b/tools/python/python_tests/mbed_greentea/mbed_gt_tests_spec.py deleted file mode 100644 index 79ddf4c9983..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_tests_spec.py +++ /dev/null @@ -1,232 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import os -import unittest -from mbed_greentea.tests_spec import Test, TestBinary, TestBuild, TestSpec - -simple_test_spec = { - "builds": { - "K64F-ARM": { - "platform": "K64F", - "toolchain": "ARM", - "base_path": "./.build/K64F/ARM", - "baud_rate": 115200, - "tests": { - "mbed-drivers-test-generic_tests":{ - "binaries":[ - { - "binary_type": "bootable", - "path": "./.build/K64F/ARM/mbed-drivers-test-generic_tests.bin" - } - ] - }, - "mbed-drivers-test-c_strings":{ - "binaries":[ - { - "binary_type": "bootable", - "path": "./.build/K64F/ARM/mbed-drivers-test-c_strings.bin" - } - ] - } - } - }, - "K64F-GCC": { - "platform": "K64F", - "toolchain": "GCC_ARM", - "base_path": "./.build/K64F/GCC_ARM", - "baud_rate": 9600, - "tests": { - "mbed-drivers-test-generic_tests":{ - "binaries":[ - { - "binary_type": "bootable", - "path": "./.build/K64F/GCC_ARM/mbed-drivers-test-generic_tests.bin" - } - ] - } - - } - } - - } -} - - -class TestsSpecFunctionality(unittest.TestCase): - - def setUp(self): - self.ts_2_builds = simple_test_spec - - def tearDown(self): - pass - - def test_example(self): - self.assertEqual(True, True) - self.assertNotEqual(True, False) - - def test_initialise_test_spec_with_filename(self): - root_path = os.path.dirname(os.path.realpath(__file__)) - spec_path = os.path.join(root_path, "resources", "test_spec.json") - - self.test_spec = TestSpec(spec_path) - test_builds = self.test_spec.get_test_builds() - - build = list(filter(lambda x: x.get_name() == "K64F-ARM", test_builds))[0] - self.assertEqual(build.get_name(), "K64F-ARM") - self.assertEqual(build.get_platform(), "K64F") - self.assertEqual(build.get_baudrate(), 9600) - self.assertEqual(build.get_path(), "./BUILD/K64F/ARM") - - self.assertEqual(len(build.get_tests()), 2) - self.assertTrue("tests-example-1" in build.get_tests()) - self.assertTrue("tests-example-2" in build.get_tests()) - - test = build.get_tests()["tests-example-1"] - self.assertEqual(test.get_name(), "tests-example-1") - self.assertEqual(test.get_binary().get_path(), "./BUILD/K64F/ARM/tests-mbedmicro-rtos-mbed-mail.bin") - - self.assertIs(type(test_builds), list) - self.assertEqual(len(test_builds), 2) - - def test_initialise_test_spec_with_invalid_filename(self): - root_path = os.path.dirname(os.path.realpath(__file__)) - spec_path = os.path.join(root_path, "resources", "null.json") - - self.test_spec = TestSpec(spec_path) - test_builds = self.test_spec.get_test_builds() - - def test_manually_add_test_binary(self): - test_name = "example-test" - test_path = "test-path" - test = Test(test_name) - self.assertEqual(test.get_name(), test_name) - self.assertEqual(test.get_binary(), None) - - test.add_binary(test_path, "bootable") - self.assertEqual(test.get_binary().get_path(), test_path) - - def test_manually_add_test_to_build(self): - name = "example-test" - test = Test(name) - test_build = TestBuild("build", "K64F", "ARM", 9600, "./") - - self.assertEqual(len(test_build.get_tests()), 0) - test_build.add_test(name, test) - self.assertEqual(len(test_build.get_tests()), 1) - self.assertTrue(name in test_build.get_tests()) - - def test_manually_add_test_build_to_test_spec(self): - test_name = "example-test" - test = Test(test_name) - test_spec = TestSpec(None) - build_name = "example-build" - test_build = TestBuild(build_name, "K64F", "ARM", 9600, "./") - test_build.add_test(test_name, test) - - self.assertEqual(len(test_spec.get_test_builds()), 0) - test_spec.add_test_builds(build_name, test_build) - self.assertEqual(len(test_spec.get_test_builds()), 1) - self.assertTrue(build_name in test_spec.get_test_builds()[0].get_name()) - - def test_get_test_builds(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - test_builds = self.test_spec.get_test_builds() - - self.assertIs(type(test_builds), list) - self.assertEqual(len(test_builds), 2) - - def test_get_test_builds_names(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - test_builds = self.test_spec.get_test_builds() - test_builds_names = [x.get_name() for x in self.test_spec.get_test_builds()] - - self.assertEqual(len(test_builds_names), 2) - self.assertIs(type(test_builds_names), list) - - self.assertIn('K64F-ARM', test_builds_names) - self.assertIn('K64F-GCC', test_builds_names) - - def test_get_test_build(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - test_builds = self.test_spec.get_test_builds() - test_builds_names = [x.get_name() for x in self.test_spec.get_test_builds()] - - self.assertEqual(len(test_builds_names), 2) - self.assertIs(type(test_builds_names), list) - - self.assertNotEqual(None, self.test_spec.get_test_build('K64F-ARM')) - self.assertNotEqual(None, self.test_spec.get_test_build('K64F-GCC')) - - def test_get_build_properties(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - test_builds = self.test_spec.get_test_builds() - test_builds_names = [x.get_name() for x in self.test_spec.get_test_builds()] - - self.assertEqual(len(test_builds_names), 2) - self.assertIs(type(test_builds_names), list) - - k64f_arm = self.test_spec.get_test_build('K64F-ARM') - k64f_gcc = self.test_spec.get_test_build('K64F-GCC') - - self.assertNotEqual(None, k64f_arm) - self.assertNotEqual(None, k64f_gcc) - - self.assertEqual('K64F', k64f_arm.get_platform()) - self.assertEqual('ARM', k64f_arm.get_toolchain()) - self.assertEqual(115200, k64f_arm.get_baudrate()) - - self.assertEqual('K64F', k64f_gcc.get_platform()) - self.assertEqual('GCC_ARM', k64f_gcc.get_toolchain()) - self.assertEqual(9600, k64f_gcc.get_baudrate()) - - def test_get_test_builds_properties(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - test_builds = self.test_spec.get_test_builds() - test_builds_names = [x.get_name() for x in self.test_spec.get_test_builds()] - - self.assertIn('K64F-ARM', test_builds_names) - self.assertIn('K64F-GCC', test_builds_names) - - def test_get_test_builds_names_filter_by_names(self): - self.test_spec = TestSpec() - self.test_spec.parse(self.ts_2_builds) - - filter_by_names = ['K64F-ARM'] - test_builds = self.test_spec.get_test_builds(filter_by_names=filter_by_names) - test_builds_names = [x.get_name() for x in test_builds] - self.assertEqual(len(test_builds_names), 1) - self.assertIn('K64F-ARM', test_builds_names) - - filter_by_names = ['K64F-GCC'] - test_builds = self.test_spec.get_test_builds(filter_by_names=filter_by_names) - test_builds_names = [x.get_name() for x in test_builds] - self.assertEqual(len(test_builds_names), 1) - self.assertIn('K64F-GCC', test_builds_names) - - filter_by_names = ['SOME-PLATFORM-NAME'] - test_builds = self.test_spec.get_test_builds(filter_by_names=filter_by_names) - test_builds_names = [x.get_name() for x in test_builds] - self.assertEqual(len(test_builds_names), 0) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_api.py b/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_api.py deleted file mode 100644 index fd39c2e350d..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_api.py +++ /dev/null @@ -1,87 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import os -import shutil -import tempfile -import unittest -from mbed_greentea import mbed_yotta_api - -def generate_paths_and_write(data): - # Generate some dummy temp directories - curr_dir = os.getcwd() - temp0_dir = tempfile.mkdtemp() - temp1_dir = os.mkdir(os.path.join(temp0_dir, "yotta_targets")) - temp2_dir = os.mkdir(os.path.join(temp0_dir, "yotta_targets", "target_name")) - - with open(os.path.join(os.path.join(temp0_dir, "yotta_targets", "target_name"), "target.json"), "w") as f: - f.write(data) - - return temp0_dir - -class YottaApiFunctionality(unittest.TestCase): - def setUp(self): - self.curr_dir = os.getcwd() - - def tearDown(self): - pass - - def test_build_with_yotta_invalid_target_name(self): - res, ret = mbed_yotta_api.build_with_yotta("invalid_name", True, build_to_debug=True) - self.assertEqual(res, False) - - res, ret = mbed_yotta_api.build_with_yotta("invalid_name", True, build_to_release=True) - self.assertEqual(res, False) - - def test_get_platform_name_from_yotta_target_invalid_target_file(self): - temp0_dir = generate_paths_and_write("test") - - os.chdir(temp0_dir) - result = mbed_yotta_api.get_platform_name_from_yotta_target("target_name") - self.assertEqual(result, None) - os.chdir(self.curr_dir) - - shutil.rmtree(temp0_dir) - - def test_get_platform_name_from_yotta_target_missing_keywords(self): - temp0_dir = generate_paths_and_write("{}") - - os.chdir(temp0_dir) - result = mbed_yotta_api.get_platform_name_from_yotta_target("target_name") - self.assertEqual(result, None) - os.chdir(self.curr_dir) - - shutil.rmtree(temp0_dir) - - def test_get_platform_name_from_yotta_target_missing_targets(self): - temp0_dir = generate_paths_and_write('{"keywords": []}') - - os.chdir(temp0_dir) - result = mbed_yotta_api.get_platform_name_from_yotta_target("target_name") - self.assertEqual(result, None) - os.chdir(self.curr_dir) - - shutil.rmtree(temp0_dir) - - def test_get_platform_name_from_yotta_target_valid_targets(self): - temp0_dir = generate_paths_and_write('{"keywords": ["mbed-target:K64F"]}') - - os.chdir(temp0_dir) - result = mbed_yotta_api.get_platform_name_from_yotta_target("target_name") - self.assertEqual(result, "K64F") - os.chdir(self.curr_dir) - - shutil.rmtree(temp0_dir) diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_config.py b/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_config.py deleted file mode 100644 index 5d8627fdf15..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_config.py +++ /dev/null @@ -1,175 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest -from mbed_greentea.mbed_yotta_module_parse import YottaConfig - - -class YOttaConfigurationParse(unittest.TestCase): - - def setUp(self): - self.YOTTA_CONFIG_LONG = { - "minar": { - "initial_event_pool_size": 50, - "additional_event_pools_size": 100 - }, - "mbed-os": { - "net": { - "stacks": { - "lwip": True - } - }, - "stdio": { - "default-baud": 9600 - } - }, - "cmsis": { - "nvic": { - "ram_vector_address": "0x1FFF0000", - "flash_vector_address": "0x0", - "user_irq_offset": 16, - "user_irq_number": 86 - } - }, - "hardware": { - "pins": { - "LED_RED": "PTB22", - "LED_GREEN": "PTE26", - "LED_BLUE": "PTB21", - "LED1": "LED_RED", - "LED2": "LED_GREEN", - "LED3": "LED_BLUE", - "LED4": "LED_RED", - "SW2": "PTC6", - "SW3": "PTA4", - "USBTX": "PTB17", - "USBRX": "PTB16", - "D0": "PTC16", - "D1": "PTC17", - "D2": "PTB9", - "D3": "PTA1", - "D4": "PTB23", - "D5": "PTA2", - "D6": "PTC2", - "D7": "PTC3", - "D8": "PTA0", - "D9": "PTC4", - "D10": "PTD0", - "D11": "PTD2", - "D12": "PTD3", - "D13": "PTD1", - "D14": "PTE25", - "D15": "PTE24", - "I2C_SCL": "D15", - "I2C_SDA": "D14", - "A0": "PTB2", - "A1": "PTB3", - "A2": "PTB10", - "A3": "PTB11", - "A4": "PTC10", - "A5": "PTC11", - "DAC0_OUT": "0xFEFE" - }, - "test-pins": { - "spi": { - "mosi": "PTD2", - "miso": "PTD3", - "sclk": "PTD1", - "ssel": "PTD0" - }, - "i2c": { - "sda": "PTE25", - "scl": "PTE24" - }, - "serial": { - "tx": "PTC17", - "rx": "PTD2" - } - } - }, - "uvisor": { - "present": 1 - }, - "arch": { - "arm": {} - }, - "mbed": {} - } - - self.YOTTA_CONFIG_SHORT = { - "minar": { - "initial_event_pool_size": 50, - "additional_event_pools_size": 100 - }, - "mbed-os": { - "net": { - "stacks": { - "lwip": True - } - }, - "stdio": { - "default-baud": 38400 - } - }, - "cmsis": { - "nvic": { - "ram_vector_address": "0x1FFF0000", - "flash_vector_address": "0x0", - "user_irq_offset": 16, - "user_irq_number": 86 - } - }, - } - - def tearDown(self): - pass - - def test_get_baudrate_9600(self): - yotta_config = YottaConfig() - yotta_config.set_yotta_config(self.YOTTA_CONFIG_LONG) - self.assertEqual(yotta_config.get_baudrate(), 9600) - - def test_get_baudrate_38400(self): - yotta_config = YottaConfig() - yotta_config.set_yotta_config(self.YOTTA_CONFIG_SHORT) - self.assertEqual(yotta_config.get_baudrate(), 38400) - - def test_get_baudrate_default_115200(self): - yotta_config = YottaConfig() - self.assertEqual(115200, yotta_config.DEFAULT_BAUDRATE) - - def test_get_baudrate_default_115200_no_yotta_config(self): - yotta_config = YottaConfig() - self.assertEqual(yotta_config.get_baudrate(), yotta_config.DEFAULT_BAUDRATE) - - def test_get_baudrate_None(self): - yotta_config = YottaConfig() - yotta_config.set_yotta_config(None) - self.assertEqual(yotta_config.get_baudrate(), yotta_config.DEFAULT_BAUDRATE) - self.assertEqual(115200, yotta_config.DEFAULT_BAUDRATE) - - def test_get_test_pins(self): - yotta_config = YottaConfig() - yotta_config.set_yotta_config(self.YOTTA_CONFIG_LONG) - self.assertEqual(yotta_config.get_baudrate(), 9600) - self.assertIn('spi', yotta_config.get_test_pins()) - self.assertIn('i2c', yotta_config.get_test_pins()) - self.assertIn('serial', yotta_config.get_test_pins()) - - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_module.py b/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_module.py deleted file mode 100644 index 899ddba2b1f..00000000000 --- a/tools/python/python_tests/mbed_greentea/mbed_gt_yotta_module.py +++ /dev/null @@ -1,228 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest -from mbed_greentea.mbed_yotta_module_parse import YottaModule - - -class YOttaConfigurationParse(unittest.TestCase): - - def setUp(self): - # greentea-client defined in 'dependencies' and 'testDependencies' - self.YOTTA_MODULE_LONG = { - "name": "utest", - "version": "1.9.1", - "description": "Simple test harness with unity and greentea integration.", - "keywords": [ - "greentea", - "testing", - "unittest", - "unity", - "unit", - "test", - "asynchronous", - "async", - "mbed-official" - ], - "author": "Niklas Hauser ", - "license": "Apache-2.0", - "dependencies": { - "minar": "^1.0.0", - "core-util": "^1.0.1", - "compiler-polyfill": "^1.2.0", - "mbed-drivers": "~0.12.0", - "greentea-client": "^0.1.2" - }, - "testDependencies": { - "unity": "^2.0.1", - "greentea-client": "^0.1.2" - } - } - - # greentea-client defined in 'dependencies' - self.YOTTA_MODULE_LONG_IN_DEP = { - "name": "utest", - "version": "1.9.1", - "description": "Simple test harness with unity and greentea integration.", - "keywords": [ - "greentea", - "testing", - "unittest", - "unity", - "unit", - "test", - "asynchronous", - "async", - "mbed-official" - ], - "author": "Niklas Hauser ", - "license": "Apache-2.0", - "dependencies": { - "minar": "^1.0.0", - "core-util": "^1.0.1", - "compiler-polyfill": "^1.2.0", - "mbed-drivers": "~0.12.0", - "greentea-client": "^0.1.2" - }, - "testDependencies": { - "unity": "^2.0.1", - } - } - - # greentea-client defined in 'testDependencies' - self.YOTTA_MODULE_LONG_IN_TESTDEP = { - "name": "utest", - "version": "1.9.1", - "description": "Simple test harness with unity and greentea integration.", - "keywords": [ - "greentea", - "testing", - "unittest", - "unity", - "unit", - "test", - "asynchronous", - "async", - "mbed-official" - ], - "author": "Niklas Hauser ", - "license": "Apache-2.0", - "dependencies": { - "minar": "^1.0.0", - "core-util": "^1.0.1", - "compiler-polyfill": "^1.2.0", - "mbed-drivers": "~0.12.0" - }, - "testDependencies": { - "unity": "^2.0.1", - "greentea-client": "^0.1.2" - } - } - - # No dependency to greentea-client - self.YOTTA_MODULE_LONG_NO_DEP = { - "name": "utest", - "version": "1.9.1", - "description": "Simple test harness with unity and greentea integration.", - "keywords": [ - "greentea", - "testing", - "unittest", - "unity", - "unit", - "test", - "asynchronous", - "async", - "mbed-official" - ], - "author": "Niklas Hauser ", - "license": "Apache-2.0", - "dependencies": { - "minar": "^1.0.0", - "core-util": "^1.0.1", - "compiler-polyfill": "^1.2.0", - "mbed-drivers": "~0.12.0" - }, - "testDependencies": { - "unity": "^2.0.1" - } - } - - # Yotta module itself is 'greentea-client' - self.GREENTEA_CLIENT_MODULE = { - "name": "greentea-client", - "version": "0.1.6", - "description": "greentea client for mbed devices.", - "keywords": [ - "greentea", - "greentea-client", - "mbedgt" - ], - "author": "Przemyslaw.Wirkus ", - "homepage": "https://github.com/ARMmbed/greentea-client", - "repository": { - "url": "git@github.com:ARMmbed/greentea-client.git", - "type": "git" - }, - "license": "Apache-2.0", - "dependencies": { - }, - "testDependencies": { - "utest": "^1.10.0", - "unity": "^2.0.0" - } - } - - - - def tearDown(self): - pass - - def test_get_name(self): - yotta_module = YottaModule() - # Modules using Greentea >= v0.2.0 - for module_json in [self.YOTTA_MODULE_LONG, - self.YOTTA_MODULE_LONG_IN_DEP, - self.YOTTA_MODULE_LONG_IN_TESTDEP, - self.YOTTA_MODULE_LONG_NO_DEP]: - yotta_module.set_yotta_module(module_json) - self.assertEqual('utest', yotta_module.get_name()) - - # 'greentea-client' module itself - yotta_module.set_yotta_module(self.GREENTEA_CLIENT_MODULE) - self.assertEqual('greentea-client', yotta_module.get_name()) - - def test_get_dict_items(self): - yotta_module = YottaModule() - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG) - self.assertEqual('Simple test harness with unity and greentea integration.', yotta_module.get_data().get('description')) - self.assertEqual('Apache-2.0', yotta_module.get_data().get('license')) - - def test_check_greentea_client_in_dep(self): - yotta_module = YottaModule() - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG_IN_DEP) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.GREENTEA_CLIENT_MODULE) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG_NO_DEP) - self.assertFalse(yotta_module.check_greentea_client()) - - def test_check_greentea_client_in_test_dep(self): - yotta_module = YottaModule() - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG_IN_TESTDEP) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.GREENTEA_CLIENT_MODULE) - self.assertTrue(yotta_module.check_greentea_client()) - - yotta_module.set_yotta_module(self.YOTTA_MODULE_LONG_NO_DEP) - self.assertFalse(yotta_module.check_greentea_client()) - - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_greentea/report_api.py b/tools/python/python_tests/mbed_greentea/report_api.py deleted file mode 100644 index 88c4ee646b3..00000000000 --- a/tools/python/python_tests/mbed_greentea/report_api.py +++ /dev/null @@ -1,55 +0,0 @@ -""" -mbed SDK -Copyright (c) 2017 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest -from mock import patch - -from mbed_greentea.mbed_report_api import exporter_html, \ - exporter_memory_metrics_csv, exporter_testcase_junit, \ - exporter_testcase_text, exporter_text, exporter_json - - -class ReportEmitting(unittest.TestCase): - - - report_fns = [exporter_html, exporter_memory_metrics_csv, - exporter_testcase_junit, exporter_testcase_text, - exporter_text, exporter_json] - def test_report_zero_tests(self): - test_data = {} - for report_fn in self.report_fns: - report_fn(test_data) - - def test_report_zero_testcases(self): - test_data = { - 'k64f-gcc_arm': { - 'garbage_test_suite' :{ - u'single_test_result': u'NOT_RAN', - u'elapsed_time': 0.0, - u'build_path': u'N/A', - u'build_path_abs': u'N/A', - u'copy_method': u'N/A', - u'image_path': u'N/A', - u'single_test_output': u'\x80abc' , - u'platform_name': u'k64f', - u'test_bin_name': u'N/A', - u'testcase_result': {}, - } - } - } - for report_fn in self.report_fns: - report_fn(test_data) diff --git a/tools/python/python_tests/mbed_greentea/resources/empty/test/CTestTestfile.cmake b/tools/python/python_tests/mbed_greentea/resources/empty/test/CTestTestfile.cmake deleted file mode 100644 index 096b2a3cc8d..00000000000 --- a/tools/python/python_tests/mbed_greentea/resources/empty/test/CTestTestfile.cmake +++ /dev/null @@ -1,6 +0,0 @@ -# CMake generated Testfile for -# Source directory: c:/Work2/mbed-client/test -# Build directory: c:/Work2/mbed-client/build/frdm-k64f-gcc/test -# -# This file includes the relevant testing commands required for -# testing this directory and lists subdirectories to be tested as well. diff --git a/tools/python/python_tests/mbed_greentea/resources/not-empty/test/CTestTestfile.cmake b/tools/python/python_tests/mbed_greentea/resources/not-empty/test/CTestTestfile.cmake deleted file mode 100644 index 04f0fb431ba..00000000000 --- a/tools/python/python_tests/mbed_greentea/resources/not-empty/test/CTestTestfile.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# CMake generated Testfile for -# Source directory: c:/Work2/mbed-client/test -# Build directory: c:/Work2/mbed-client/build/frdm-k64f-gcc/test -# -# This file includes the relevant testing commands required for -# testing this directory and lists subdirectories to be tested as well. -add_test(mbed-client-test-mbedclient-smokeTest "mbed-client-test-mbedclient-smokeTest") -add_test(mbed-client-test-helloworld-mbedclient "mbed-client-test-helloworld-mbedclient") -add_test() diff --git a/tools/python/python_tests/mbed_greentea/resources/test_spec.json b/tools/python/python_tests/mbed_greentea/resources/test_spec.json deleted file mode 100644 index 71fc92beb50..00000000000 --- a/tools/python/python_tests/mbed_greentea/resources/test_spec.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "builds": { - "K64F-ARM": { - "platform": "K64F", - "toolchain": "ARM", - "base_path": "./BUILD/K64F/ARM", - "baud_rate": 9600, - "tests": { - "tests-example-1": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/ARM/tests-mbedmicro-rtos-mbed-mail.bin" - } - ] - }, - "tests-example-2": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/ARM/tests-mbed_drivers-c_strings.bin" - } - ] - } - } - }, - "K64F-GCC": { - "platform": "K64F", - "toolchain": "GCC_ARM", - "base_path": "./BUILD/K64F/GCC_ARM", - "baud_rate": 9600, - "tests": { - "tests-example-7": { - "binaries": [ - { - "binary_type": "bootable", - "path": "./BUILD/K64F/GCC_ARM/tests-mbedmicro-rtos-mbed-mail.bin" - } - ] - } - } - } - } -} diff --git a/tools/python/python_tests/mbed_host_tests/host_test_plugins.py b/tools/python/python_tests/mbed_host_tests/host_test_plugins.py deleted file mode 100644 index 91384ba2966..00000000000 --- a/tools/python/python_tests/mbed_host_tests/host_test_plugins.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -mbed SDK -Copyright (c) 2011-2015 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import unittest - -from mbed_host_tests.host_tests_plugins.module_reset_mbed import HostTestPluginResetMethod_Mbed - -class HostOSDetectionTestCase(unittest.TestCase): - - def setUp(self): - self.plugin_reset_mbed = HostTestPluginResetMethod_Mbed() - - def tearDown(self): - pass - - def test_examle(self): - pass - - def test_pyserial_version_detect(self): - self.assertEqual(1.0, self.plugin_reset_mbed.get_pyserial_version("1.0")) - self.assertEqual(1.0, self.plugin_reset_mbed.get_pyserial_version("1.0.0")) - self.assertEqual(2.7, self.plugin_reset_mbed.get_pyserial_version("2.7")) - self.assertEqual(2.7, self.plugin_reset_mbed.get_pyserial_version("2.7.1")) - self.assertEqual(3.0, self.plugin_reset_mbed.get_pyserial_version("3.0")) - self.assertEqual(3.0, self.plugin_reset_mbed.get_pyserial_version("3.0.1")) - - -if __name__ == '__main__': - unittest.main() diff --git a/tools/python/python_tests/mbed_lstools/base.py b/tools/python/python_tests/mbed_lstools/base.py index 3833d2cb354..4df14081c6c 100644 --- a/tools/python/python_tests/mbed_lstools/base.py +++ b/tools/python/python_tests/mbed_lstools/base.py @@ -20,7 +20,6 @@ import errno import logging import re -import pkg_resources import json from mock import patch, MagicMock from copy import deepcopy diff --git a/tools/python/python_tests/mbed_lstools/mbedls_toolsbase.py b/tools/python/python_tests/mbed_lstools/mbedls_toolsbase.py index 0a900178316..0f5f028be12 100644 --- a/tools/python/python_tests/mbed_lstools/mbedls_toolsbase.py +++ b/tools/python/python_tests/mbed_lstools/mbedls_toolsbase.py @@ -418,7 +418,11 @@ def test_fs_after(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + + # Below is the recommended replacement for assertDictContainsSubset(). + # See: https://stackoverflow.com/a/59777678/7083698 + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) + _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) @@ -494,7 +498,7 @@ def test_fs_before(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) @@ -516,7 +520,7 @@ def test_fs_before(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) diff --git a/tools/python/python_tests/mbed_os_tools/detect/mbedls_toolsbase.py b/tools/python/python_tests/mbed_os_tools/detect/mbedls_toolsbase.py index a4221c2fd6b..6dea2e7da25 100644 --- a/tools/python/python_tests/mbed_os_tools/detect/mbedls_toolsbase.py +++ b/tools/python/python_tests/mbed_os_tools/detect/mbedls_toolsbase.py @@ -413,7 +413,11 @@ def test_fs_after(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + + # Below is the recommended replacement for assertDictContainsSubset(). + # See: https://stackoverflow.com/a/59777678/7083698 + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) + _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) @@ -489,7 +493,7 @@ def test_fs_before(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) @@ -511,7 +515,7 @@ def test_fs_before(self): self.assertIsNotNone(ret_with_details[0]) self.assertEqual(ret[0]['target_id'], new_device_id) self.assertEqual(ret_with_details[0]['daplink_automation_allowed'], '0') - self.assertDictContainsSubset(ret[0], ret_with_details[0]) + self.assertEqual(ret_with_details[0], {**ret_with_details[0], **ret[0]}) _read_htm.assert_called_with(device['mount_point']) _up_details.assert_called_with(device['mount_point']) diff --git a/tools/python/python_tests/requirements.apt.txt b/tools/python/python_tests/requirements.apt.txt deleted file mode 100644 index 745b3968b29..00000000000 --- a/tools/python/python_tests/requirements.apt.txt +++ /dev/null @@ -1,7 +0,0 @@ -python3-pytest -python3-factory-boy -python3-requests-mock -python3-mock -python3-coverage -python3-bs4 -python3-lxml \ No newline at end of file diff --git a/tools/python/python_tests/requirements.txt b/tools/python/python_tests/requirements.txt index f736ed797d8..629c27196bf 100644 --- a/tools/python/python_tests/requirements.txt +++ b/tools/python/python_tests/requirements.txt @@ -1,7 +1,3 @@ -## NOTE: This file must be kept in sync with requirements.apt.txt in the same folder. -## That file gives the equivalent package names of these packages in the apt package manager -## for Ubuntu & Debian - # These are the requirements for running the Python package tests. # They are in addition to the requirements.txt under mbedos/tools/. pytest diff --git a/tools/python/run_python_tests.sh b/tools/python/run_python_tests.sh index b398106635e..52557f25086 100755 --- a/tools/python/run_python_tests.sh +++ b/tools/python/run_python_tests.sh @@ -11,7 +11,7 @@ set -e -PYTHON=python3 +PYTHON=python # Comma separated list of directories to exclude from coverage COVERAGE_EXCLUDES='--omit=python_tests/*' @@ -31,9 +31,6 @@ $PYTHON -m coverage run "$COVERAGE_EXCLUDES" -a -m pytest python_tests/scancode_ # test case filenames for some packages. So, the "-p *.py" argument is needed to # make it look for any files as tests, not just ones ending in _test.py. -echo ">> Running unittests for mbed_greentea package" -$PYTHON -m coverage run "$COVERAGE_EXCLUDES" -a -m unittest discover -p '*.py' python_tests.mbed_greentea - echo ">> Running unittests for mbed_host_tests package" $PYTHON -m coverage run "$COVERAGE_EXCLUDES" -a -m unittest discover -p '*.py' python_tests.mbed_host_tests diff --git a/tools/requirements.txt b/tools/requirements.txt index 6d271d7e6c4..e72058494cd 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -1,7 +1,3 @@ -## NOTE: This file must be kept in sync with requirements.apt.txt in the same folder. -## That file gives the equivalent package names of these packages in the apt package manager -## for Ubuntu & Debian - PrettyTable<=1.0.1; python_version < '3.6' prettytable>=2.0,<4.0; python_version >= '3.6' future>=0.18.0,<1.0 @@ -27,6 +23,9 @@ colorama>=0.3,<0.5 json5 humanize~=4.9.0 +# Install pyocd so that it's available in the venv if the user chooses to use it +pyocd + # beautifulsoup only needed for USB device detection on Mac beautifulsoup4; sys_platform == 'darwin' lxml; sys_platform == 'darwin' @@ -36,4 +35,7 @@ cryptography cbor # Needed for downloading CMSIS MCU descriptions -cmsis-pack-manager~=0.5.0 \ No newline at end of file +cmsis-pack-manager~=0.5.0 + +# cffi is a dependency of cmsis-pack-manager, but cffi needs a prerelease to support Python 3.13 +cffi>=1.17.0rc1; python_version >= '3.13' \ No newline at end of file