init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

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