Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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