BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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