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