Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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