5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

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