Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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