Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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