BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/singletest.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | #!/usr/bin/env python2 |
borlanic | 0:02dd72d1d465 | 2 | |
borlanic | 0:02dd72d1d465 | 3 | """ |
borlanic | 0:02dd72d1d465 | 4 | mbed SDK |
borlanic | 0:02dd72d1d465 | 5 | Copyright (c) 2011-2014 ARM Limited |
borlanic | 0:02dd72d1d465 | 6 | |
borlanic | 0:02dd72d1d465 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 8 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 9 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 10 | |
borlanic | 0:02dd72d1d465 | 11 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 12 | |
borlanic | 0:02dd72d1d465 | 13 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 14 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 16 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 17 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 18 | |
borlanic | 0:02dd72d1d465 | 19 | Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com> |
borlanic | 0:02dd72d1d465 | 20 | """ |
borlanic | 0:02dd72d1d465 | 21 | |
borlanic | 0:02dd72d1d465 | 22 | """ |
borlanic | 0:02dd72d1d465 | 23 | File format example: test_spec.json: |
borlanic | 0:02dd72d1d465 | 24 | { |
borlanic | 0:02dd72d1d465 | 25 | "targets": { |
borlanic | 0:02dd72d1d465 | 26 | "KL46Z": ["ARM", "GCC_ARM"], |
borlanic | 0:02dd72d1d465 | 27 | "LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "IAR"], |
borlanic | 0:02dd72d1d465 | 28 | "LPC11U24": ["uARM"], |
borlanic | 0:02dd72d1d465 | 29 | "NRF51822": ["ARM"] |
borlanic | 0:02dd72d1d465 | 30 | } |
borlanic | 0:02dd72d1d465 | 31 | } |
borlanic | 0:02dd72d1d465 | 32 | |
borlanic | 0:02dd72d1d465 | 33 | File format example: muts_all.json: |
borlanic | 0:02dd72d1d465 | 34 | { |
borlanic | 0:02dd72d1d465 | 35 | "1" : {"mcu": "LPC1768", |
borlanic | 0:02dd72d1d465 | 36 | "port":"COM4", |
borlanic | 0:02dd72d1d465 | 37 | "disk":"J:\\", |
borlanic | 0:02dd72d1d465 | 38 | "peripherals": ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"] |
borlanic | 0:02dd72d1d465 | 39 | }, |
borlanic | 0:02dd72d1d465 | 40 | |
borlanic | 0:02dd72d1d465 | 41 | "2" : {"mcu": "KL25Z", |
borlanic | 0:02dd72d1d465 | 42 | "port":"COM7", |
borlanic | 0:02dd72d1d465 | 43 | "disk":"G:\\", |
borlanic | 0:02dd72d1d465 | 44 | "peripherals": ["digital_loop", "port_loop", "analog_loop"] |
borlanic | 0:02dd72d1d465 | 45 | } |
borlanic | 0:02dd72d1d465 | 46 | } |
borlanic | 0:02dd72d1d465 | 47 | """ |
borlanic | 0:02dd72d1d465 | 48 | |
borlanic | 0:02dd72d1d465 | 49 | |
borlanic | 0:02dd72d1d465 | 50 | # Be sure that the tools directory is in the search path |
borlanic | 0:02dd72d1d465 | 51 | import sys |
borlanic | 0:02dd72d1d465 | 52 | from os.path import join, abspath, dirname |
borlanic | 0:02dd72d1d465 | 53 | |
borlanic | 0:02dd72d1d465 | 54 | ROOT = abspath(join(dirname(__file__), "..")) |
borlanic | 0:02dd72d1d465 | 55 | sys.path.insert(0, ROOT) |
borlanic | 0:02dd72d1d465 | 56 | |
borlanic | 0:02dd72d1d465 | 57 | |
borlanic | 0:02dd72d1d465 | 58 | # Check: Extra modules which are required by core test suite |
borlanic | 0:02dd72d1d465 | 59 | from tools.utils import check_required_modules |
borlanic | 0:02dd72d1d465 | 60 | check_required_modules(['prettytable', 'serial']) |
borlanic | 0:02dd72d1d465 | 61 | |
borlanic | 0:02dd72d1d465 | 62 | # Imports related to mbed build api |
borlanic | 0:02dd72d1d465 | 63 | from tools.build_api import mcu_toolchain_matrix |
borlanic | 0:02dd72d1d465 | 64 | |
borlanic | 0:02dd72d1d465 | 65 | # Imports from TEST API |
borlanic | 0:02dd72d1d465 | 66 | from tools.test_api import SingleTestRunner |
borlanic | 0:02dd72d1d465 | 67 | from tools.test_api import singletest_in_cli_mode |
borlanic | 0:02dd72d1d465 | 68 | from tools.test_api import detect_database_verbose |
borlanic | 0:02dd72d1d465 | 69 | from tools.test_api import get_json_data_from_file |
borlanic | 0:02dd72d1d465 | 70 | from tools.test_api import get_avail_tests_summary_table |
borlanic | 0:02dd72d1d465 | 71 | from tools.test_api import get_default_test_options_parser |
borlanic | 0:02dd72d1d465 | 72 | from tools.test_api import print_muts_configuration_from_json |
borlanic | 0:02dd72d1d465 | 73 | from tools.test_api import print_test_configuration_from_json |
borlanic | 0:02dd72d1d465 | 74 | from tools.test_api import get_autodetected_MUTS_list |
borlanic | 0:02dd72d1d465 | 75 | from tools.test_api import get_autodetected_TEST_SPEC |
borlanic | 0:02dd72d1d465 | 76 | from tools.test_api import get_module_avail |
borlanic | 0:02dd72d1d465 | 77 | from tools.test_exporters import ReportExporter, ResultExporterType |
borlanic | 0:02dd72d1d465 | 78 | |
borlanic | 0:02dd72d1d465 | 79 | |
borlanic | 0:02dd72d1d465 | 80 | # Importing extra modules which can be not installed but if available they can extend test suite functionality |
borlanic | 0:02dd72d1d465 | 81 | try: |
borlanic | 0:02dd72d1d465 | 82 | import mbed_lstools |
borlanic | 0:02dd72d1d465 | 83 | from tools.compliance.ioper_runner import IOperTestRunner |
borlanic | 0:02dd72d1d465 | 84 | from tools.compliance.ioper_runner import get_available_oper_test_scopes |
borlanic | 0:02dd72d1d465 | 85 | except: |
borlanic | 0:02dd72d1d465 | 86 | pass |
borlanic | 0:02dd72d1d465 | 87 | |
borlanic | 0:02dd72d1d465 | 88 | def get_version(): |
borlanic | 0:02dd72d1d465 | 89 | """ Returns test script version |
borlanic | 0:02dd72d1d465 | 90 | """ |
borlanic | 0:02dd72d1d465 | 91 | single_test_version_major = 1 |
borlanic | 0:02dd72d1d465 | 92 | single_test_version_minor = 5 |
borlanic | 0:02dd72d1d465 | 93 | return (single_test_version_major, single_test_version_minor) |
borlanic | 0:02dd72d1d465 | 94 | |
borlanic | 0:02dd72d1d465 | 95 | |
borlanic | 0:02dd72d1d465 | 96 | if __name__ == '__main__': |
borlanic | 0:02dd72d1d465 | 97 | # Command line options |
borlanic | 0:02dd72d1d465 | 98 | parser = get_default_test_options_parser() |
borlanic | 0:02dd72d1d465 | 99 | |
borlanic | 0:02dd72d1d465 | 100 | parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s).""" |
borlanic | 0:02dd72d1d465 | 101 | parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json""" |
borlanic | 0:02dd72d1d465 | 102 | |
borlanic | 0:02dd72d1d465 | 103 | opts = parser.parse_args() |
borlanic | 0:02dd72d1d465 | 104 | |
borlanic | 0:02dd72d1d465 | 105 | # Print scrip version |
borlanic | 0:02dd72d1d465 | 106 | if opts.version: |
borlanic | 0:02dd72d1d465 | 107 | print parser.description |
borlanic | 0:02dd72d1d465 | 108 | print parser.epilog |
borlanic | 0:02dd72d1d465 | 109 | print "Version %d.%d"% get_version() |
borlanic | 0:02dd72d1d465 | 110 | exit(0) |
borlanic | 0:02dd72d1d465 | 111 | |
borlanic | 0:02dd72d1d465 | 112 | if opts.db_url and opts.verbose_test_configuration_only: |
borlanic | 0:02dd72d1d465 | 113 | detect_database_verbose(opts.db_url) |
borlanic | 0:02dd72d1d465 | 114 | exit(0) |
borlanic | 0:02dd72d1d465 | 115 | |
borlanic | 0:02dd72d1d465 | 116 | # Print summary / information about automation test status |
borlanic | 0:02dd72d1d465 | 117 | if opts.test_automation_report: |
borlanic | 0:02dd72d1d465 | 118 | print get_avail_tests_summary_table(platform_filter=opts.general_filter_regex) |
borlanic | 0:02dd72d1d465 | 119 | exit(0) |
borlanic | 0:02dd72d1d465 | 120 | |
borlanic | 0:02dd72d1d465 | 121 | # Print summary / information about automation test status |
borlanic | 0:02dd72d1d465 | 122 | if opts.test_case_report: |
borlanic | 0:02dd72d1d465 | 123 | test_case_report_cols = ['id', |
borlanic | 0:02dd72d1d465 | 124 | 'automated', |
borlanic | 0:02dd72d1d465 | 125 | 'description', |
borlanic | 0:02dd72d1d465 | 126 | 'peripherals', |
borlanic | 0:02dd72d1d465 | 127 | 'host_test', |
borlanic | 0:02dd72d1d465 | 128 | 'duration', |
borlanic | 0:02dd72d1d465 | 129 | 'source_dir'] |
borlanic | 0:02dd72d1d465 | 130 | print get_avail_tests_summary_table(cols=test_case_report_cols, |
borlanic | 0:02dd72d1d465 | 131 | result_summary=False, |
borlanic | 0:02dd72d1d465 | 132 | join_delim='\n', |
borlanic | 0:02dd72d1d465 | 133 | platform_filter=opts.general_filter_regex) |
borlanic | 0:02dd72d1d465 | 134 | exit(0) |
borlanic | 0:02dd72d1d465 | 135 | |
borlanic | 0:02dd72d1d465 | 136 | # Only prints matrix of supported toolchains |
borlanic | 0:02dd72d1d465 | 137 | if opts.supported_toolchains: |
borlanic | 0:02dd72d1d465 | 138 | print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex) |
borlanic | 0:02dd72d1d465 | 139 | exit(0) |
borlanic | 0:02dd72d1d465 | 140 | |
borlanic | 0:02dd72d1d465 | 141 | test_spec = None |
borlanic | 0:02dd72d1d465 | 142 | MUTs = None |
borlanic | 0:02dd72d1d465 | 143 | |
borlanic | 0:02dd72d1d465 | 144 | if hasattr(opts, 'auto_detect') and opts.auto_detect: |
borlanic | 0:02dd72d1d465 | 145 | # If auto_detect attribute is present, we assume other auto-detection |
borlanic | 0:02dd72d1d465 | 146 | # parameters like 'toolchains_filter' are also set. |
borlanic | 0:02dd72d1d465 | 147 | print "MBEDLS: Detecting connected mbed-enabled devices... " |
borlanic | 0:02dd72d1d465 | 148 | |
borlanic | 0:02dd72d1d465 | 149 | MUTs = get_autodetected_MUTS_list() |
borlanic | 0:02dd72d1d465 | 150 | |
borlanic | 0:02dd72d1d465 | 151 | for mut in MUTs.values(): |
borlanic | 0:02dd72d1d465 | 152 | print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'], |
borlanic | 0:02dd72d1d465 | 153 | mut['port'], |
borlanic | 0:02dd72d1d465 | 154 | mut['disk']) |
borlanic | 0:02dd72d1d465 | 155 | |
borlanic | 0:02dd72d1d465 | 156 | # Set up parameters for test specification filter function (we need to set toolchains per target here) |
borlanic | 0:02dd72d1d465 | 157 | use_default_toolchain = 'default' in opts.toolchains_filter if opts.toolchains_filter is not None else True |
borlanic | 0:02dd72d1d465 | 158 | use_supported_toolchains = 'all' in opts.toolchains_filter if opts.toolchains_filter is not None else False |
borlanic | 0:02dd72d1d465 | 159 | toolchain_filter = opts.toolchains_filter |
borlanic | 0:02dd72d1d465 | 160 | platform_name_filter = opts.general_filter_regex if opts.general_filter_regex is not None else opts.general_filter_regex |
borlanic | 0:02dd72d1d465 | 161 | # Test specification with information about each target and associated toolchain |
borlanic | 0:02dd72d1d465 | 162 | test_spec = get_autodetected_TEST_SPEC(MUTs.values(), |
borlanic | 0:02dd72d1d465 | 163 | use_default_toolchain=use_default_toolchain, |
borlanic | 0:02dd72d1d465 | 164 | use_supported_toolchains=use_supported_toolchains, |
borlanic | 0:02dd72d1d465 | 165 | toolchain_filter=toolchain_filter, |
borlanic | 0:02dd72d1d465 | 166 | platform_name_filter=platform_name_filter) |
borlanic | 0:02dd72d1d465 | 167 | else: |
borlanic | 0:02dd72d1d465 | 168 | # Open file with test specification |
borlanic | 0:02dd72d1d465 | 169 | # test_spec_filename tells script which targets and their toolchain(s) |
borlanic | 0:02dd72d1d465 | 170 | # should be covered by the test scenario |
borlanic | 0:02dd72d1d465 | 171 | opts.auto_detect = False |
borlanic | 0:02dd72d1d465 | 172 | test_spec = get_json_data_from_file(opts.test_spec_filename) if opts.test_spec_filename else None |
borlanic | 0:02dd72d1d465 | 173 | if test_spec is None: |
borlanic | 0:02dd72d1d465 | 174 | if not opts.test_spec_filename: |
borlanic | 0:02dd72d1d465 | 175 | parser.print_help() |
borlanic | 0:02dd72d1d465 | 176 | exit(-1) |
borlanic | 0:02dd72d1d465 | 177 | |
borlanic | 0:02dd72d1d465 | 178 | # Get extra MUTs if applicable |
borlanic | 0:02dd72d1d465 | 179 | MUTs = get_json_data_from_file(opts.muts_spec_filename) if opts.muts_spec_filename else None |
borlanic | 0:02dd72d1d465 | 180 | |
borlanic | 0:02dd72d1d465 | 181 | if MUTs is None: |
borlanic | 0:02dd72d1d465 | 182 | if not opts.muts_spec_filename: |
borlanic | 0:02dd72d1d465 | 183 | parser.print_help() |
borlanic | 0:02dd72d1d465 | 184 | exit(-1) |
borlanic | 0:02dd72d1d465 | 185 | |
borlanic | 0:02dd72d1d465 | 186 | if opts.verbose_test_configuration_only: |
borlanic | 0:02dd72d1d465 | 187 | print "MUTs configuration in %s:" % ('auto-detected' if opts.auto_detect else opts.muts_spec_filename) |
borlanic | 0:02dd72d1d465 | 188 | if MUTs: |
borlanic | 0:02dd72d1d465 | 189 | print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex) |
borlanic | 0:02dd72d1d465 | 190 | |
borlanic | 0:02dd72d1d465 | 191 | print "Test specification in %s:" % ('auto-detected' if opts.auto_detect else opts.test_spec_filename) |
borlanic | 0:02dd72d1d465 | 192 | if test_spec: |
borlanic | 0:02dd72d1d465 | 193 | print print_test_configuration_from_json(test_spec) |
borlanic | 0:02dd72d1d465 | 194 | exit(0) |
borlanic | 0:02dd72d1d465 | 195 | |
borlanic | 0:02dd72d1d465 | 196 | if get_module_avail('mbed_lstools'): |
borlanic | 0:02dd72d1d465 | 197 | if opts.operability_checks: |
borlanic | 0:02dd72d1d465 | 198 | # Check if test scope is valid and run tests |
borlanic | 0:02dd72d1d465 | 199 | test_scope = get_available_oper_test_scopes() |
borlanic | 0:02dd72d1d465 | 200 | if opts.operability_checks in test_scope: |
borlanic | 0:02dd72d1d465 | 201 | tests = IOperTestRunner(scope=opts.operability_checks) |
borlanic | 0:02dd72d1d465 | 202 | test_results = tests.run() |
borlanic | 0:02dd72d1d465 | 203 | |
borlanic | 0:02dd72d1d465 | 204 | # Export results in form of JUnit XML report to separate file |
borlanic | 0:02dd72d1d465 | 205 | if opts.report_junit_file_name: |
borlanic | 0:02dd72d1d465 | 206 | report_exporter = ReportExporter(ResultExporterType.JUNIT_OPER) |
borlanic | 0:02dd72d1d465 | 207 | report_exporter.report_to_file(test_results, opts.report_junit_file_name) |
borlanic | 0:02dd72d1d465 | 208 | else: |
borlanic | 0:02dd72d1d465 | 209 | print "Unknown interoperability test scope name: '%s'" % (opts.operability_checks) |
borlanic | 0:02dd72d1d465 | 210 | print "Available test scopes: %s" % (','.join(["'%s'" % n for n in test_scope])) |
borlanic | 0:02dd72d1d465 | 211 | |
borlanic | 0:02dd72d1d465 | 212 | exit(0) |
borlanic | 0:02dd72d1d465 | 213 | |
borlanic | 0:02dd72d1d465 | 214 | # Verbose test specification and MUTs configuration |
borlanic | 0:02dd72d1d465 | 215 | if MUTs and opts.verbose: |
borlanic | 0:02dd72d1d465 | 216 | print print_muts_configuration_from_json(MUTs) |
borlanic | 0:02dd72d1d465 | 217 | if test_spec and opts.verbose: |
borlanic | 0:02dd72d1d465 | 218 | print print_test_configuration_from_json(test_spec) |
borlanic | 0:02dd72d1d465 | 219 | |
borlanic | 0:02dd72d1d465 | 220 | if opts.only_build_tests: |
borlanic | 0:02dd72d1d465 | 221 | # We are skipping testing phase, and suppress summary |
borlanic | 0:02dd72d1d465 | 222 | opts.suppress_summary = True |
borlanic | 0:02dd72d1d465 | 223 | |
borlanic | 0:02dd72d1d465 | 224 | single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value, |
borlanic | 0:02dd72d1d465 | 225 | _test_loops_list=opts.test_loops_list, |
borlanic | 0:02dd72d1d465 | 226 | _muts=MUTs, |
borlanic | 0:02dd72d1d465 | 227 | _clean=opts.clean, |
borlanic | 0:02dd72d1d465 | 228 | _parser=parser, |
borlanic | 0:02dd72d1d465 | 229 | _opts=opts, |
borlanic | 0:02dd72d1d465 | 230 | _opts_db_url=opts.db_url, |
borlanic | 0:02dd72d1d465 | 231 | _opts_log_file_name=opts.log_file_name, |
borlanic | 0:02dd72d1d465 | 232 | _opts_report_html_file_name=opts.report_html_file_name, |
borlanic | 0:02dd72d1d465 | 233 | _opts_report_junit_file_name=opts.report_junit_file_name, |
borlanic | 0:02dd72d1d465 | 234 | _opts_report_build_file_name=opts.report_build_file_name, |
borlanic | 0:02dd72d1d465 | 235 | _opts_report_text_file_name=opts.report_text_file_name, |
borlanic | 0:02dd72d1d465 | 236 | _test_spec=test_spec, |
borlanic | 0:02dd72d1d465 | 237 | _opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk, |
borlanic | 0:02dd72d1d465 | 238 | _opts_goanna_for_tests=opts.goanna_for_tests, |
borlanic | 0:02dd72d1d465 | 239 | _opts_shuffle_test_order=opts.shuffle_test_order, |
borlanic | 0:02dd72d1d465 | 240 | _opts_shuffle_test_seed=opts.shuffle_test_seed, |
borlanic | 0:02dd72d1d465 | 241 | _opts_test_by_names=opts.test_by_names, |
borlanic | 0:02dd72d1d465 | 242 | _opts_peripheral_by_names=opts.peripheral_by_names, |
borlanic | 0:02dd72d1d465 | 243 | _opts_test_only_peripheral=opts.test_only_peripheral, |
borlanic | 0:02dd72d1d465 | 244 | _opts_test_only_common=opts.test_only_common, |
borlanic | 0:02dd72d1d465 | 245 | _opts_verbose_skipped_tests=opts.verbose_skipped_tests, |
borlanic | 0:02dd72d1d465 | 246 | _opts_verbose_test_result_only=opts.verbose_test_result_only, |
borlanic | 0:02dd72d1d465 | 247 | _opts_verbose=opts.verbose, |
borlanic | 0:02dd72d1d465 | 248 | _opts_firmware_global_name=opts.firmware_global_name, |
borlanic | 0:02dd72d1d465 | 249 | _opts_only_build_tests=opts.only_build_tests, |
borlanic | 0:02dd72d1d465 | 250 | _opts_parallel_test_exec=opts.parallel_test_exec, |
borlanic | 0:02dd72d1d465 | 251 | _opts_suppress_summary=opts.suppress_summary, |
borlanic | 0:02dd72d1d465 | 252 | _opts_test_x_toolchain_summary=opts.test_x_toolchain_summary, |
borlanic | 0:02dd72d1d465 | 253 | _opts_copy_method=opts.copy_method, |
borlanic | 0:02dd72d1d465 | 254 | _opts_mut_reset_type=opts.mut_reset_type, |
borlanic | 0:02dd72d1d465 | 255 | _opts_jobs=opts.jobs, |
borlanic | 0:02dd72d1d465 | 256 | _opts_waterfall_test=opts.waterfall_test, |
borlanic | 0:02dd72d1d465 | 257 | _opts_consolidate_waterfall_test=opts.consolidate_waterfall_test, |
borlanic | 0:02dd72d1d465 | 258 | _opts_extend_test_timeout=opts.extend_test_timeout, |
borlanic | 0:02dd72d1d465 | 259 | _opts_auto_detect=opts.auto_detect) |
borlanic | 0:02dd72d1d465 | 260 | |
borlanic | 0:02dd72d1d465 | 261 | # Runs test suite in CLI mode |
borlanic | 0:02dd72d1d465 | 262 | if (singletest_in_cli_mode(single_test)): |
borlanic | 0:02dd72d1d465 | 263 | exit(0) |
borlanic | 0:02dd72d1d465 | 264 | else: |
borlanic | 0:02dd72d1d465 | 265 | exit(-1) |