5 Copyright (c) 2011-2014 ARM Limited
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
19 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
23 File format example: test_spec.json:
26 "KL46Z": ["ARM", "GCC_ARM"],
27 "LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "GCC_CS", "IAR"],
33 File format example: muts_all.json:
35 "1" : {"mcu": "LPC1768",
38 "peripherals": ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"]
41 "2" : {"mcu": "KL25Z",
44 "peripherals": ["digital_loop", "port_loop", "analog_loop"]
50 # Be sure that the tools directory is in the search path
52 from os.path import join, abspath, dirname
54 ROOT = abspath(join(dirname(__file__), ".."))
55 sys.path.insert(0, ROOT)
58 # Check: Extra modules which are required by core test suite
59 from workspace_tools.utils import check_required_modules
60 check_required_modules(['prettytable', 'serial'])
62 # Imports related to mbed build api
63 from workspace_tools.build_api import mcu_toolchain_matrix
65 # Imports from TEST API
66 from workspace_tools.test_api import SingleTestRunner
67 from workspace_tools.test_api import singletest_in_cli_mode
68 from workspace_tools.test_api import detect_database_verbose
69 from workspace_tools.test_api import get_json_data_from_file
70 from workspace_tools.test_api import get_avail_tests_summary_table
71 from workspace_tools.test_api import get_default_test_options_parser
72 from workspace_tools.test_api import print_muts_configuration_from_json
73 from workspace_tools.test_api import print_test_configuration_from_json
74 from workspace_tools.test_api import get_autodetected_MUTS
75 from workspace_tools.test_api import get_autodetected_TEST_SPEC
76 from workspace_tools.test_api import get_module_avail
78 # Importing extra modules which can be not installed but if available they can extend test suite functionality
85 """ Returns test script version
87 single_test_version_major = 1
88 single_test_version_minor = 4
89 return (single_test_version_major, single_test_version_minor)
92 if __name__ == '__main__':
93 # Command line options
94 parser = get_default_test_options_parser()
96 parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s)."""
97 parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json"""
99 (opts, args) = parser.parse_args()
101 # Print scrip version
103 print parser.description
105 print "Version %d.%d"% get_version()
108 if opts.db_url and opts.verbose_test_configuration_only:
109 detect_database_verbose(opts.db_url)
112 # Print summary / information about automation test status
113 if opts.test_automation_report:
114 print get_avail_tests_summary_table(platform_filter=opts.general_filter_regex)
117 # Print summary / information about automation test status
118 if opts.test_case_report:
119 test_case_report_cols = ['id',
126 print get_avail_tests_summary_table(cols=test_case_report_cols,
127 result_summary=False,
129 platform_filter=opts.general_filter_regex)
132 # Only prints matrix of supported toolchains
133 if opts.supported_toolchains:
134 print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
140 if hasattr(opts, 'auto_detect') and opts.auto_detect:
141 # If auto_detect attribute is present, we assume other auto-detection
142 # parameters like 'toolchains_filter' are also set.
143 print "MBEDLS: Detecting connected mbed-enabled devices... "
145 if get_module_avail('mbed_lstools'):
146 mbeds = mbed_lstools.create()
147 muts_list = mbeds.list_mbeds()
148 for mut in muts_list:
149 print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['platform_name'],
153 # Set up parameters for test specification filter function (we need to set toolchains per target here)
154 use_default_toolchain = 'default' in opts.toolchains_filter.split(',') if opts.toolchains_filter is not None else True
155 use_supported_toolchains = 'all' in opts.toolchains_filter.split(',') if opts.toolchains_filter is not None else False
156 toolchain_filter = opts.toolchains_filter
157 platform_name_filter = opts.general_filter_regex.split(',') if opts.general_filter_regex is not None else opts.general_filter_regex
158 # Test specification with information about each target and associated toolchain
159 test_spec = get_autodetected_TEST_SPEC(muts_list,
160 use_default_toolchain=use_default_toolchain,
161 use_supported_toolchains=use_supported_toolchains,
162 toolchain_filter=toolchain_filter,
163 platform_name_filter=platform_name_filter)
164 # MUTs configuration auto-detection
165 MUTs = get_autodetected_MUTS(muts_list)
167 # Open file with test specification
168 # test_spec_filename tells script which targets and their toolchain(s)
169 # should be covered by the test scenario
170 test_spec = get_json_data_from_file(opts.test_spec_filename) if opts.test_spec_filename else None
171 if test_spec is None:
172 if not opts.test_spec_filename:
176 # Get extra MUTs if applicable
177 MUTs = get_json_data_from_file(opts.muts_spec_filename) if opts.muts_spec_filename else None
180 if not opts.muts_spec_filename:
184 if opts.verbose_test_configuration_only:
185 print "MUTs configuration in %s:"% ('auto-detected' if opts.auto_detect else opts.muts_spec_filename)
187 print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex)
189 print "Test specification in %s:"% ('auto-detected' if opts.auto_detect else opts.test_spec_filename)
191 print print_test_configuration_from_json(test_spec)
194 # Verbose test specification and MUTs configuration
195 if MUTs and opts.verbose:
196 print print_muts_configuration_from_json(MUTs)
197 if test_spec and opts.verbose:
198 print print_test_configuration_from_json(test_spec)
200 if opts.only_build_tests:
201 # We are skipping testing phase, and suppress summary
202 opts.suppress_summary = True
204 single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value,
205 _test_loops_list=opts.test_loops_list,
208 _opts_db_url=opts.db_url,
209 _opts_log_file_name=opts.log_file_name,
210 _opts_report_html_file_name=opts.report_html_file_name,
211 _opts_report_junit_file_name=opts.report_junit_file_name,
212 _opts_report_build_file_name=opts.report_build_file_name,
213 _test_spec=test_spec,
214 _opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk,
215 _opts_goanna_for_tests=opts.goanna_for_tests,
216 _opts_shuffle_test_order=opts.shuffle_test_order,
217 _opts_shuffle_test_seed=opts.shuffle_test_seed,
218 _opts_test_by_names=opts.test_by_names,
219 _opts_peripheral_by_names=opts.peripheral_by_names,
220 _opts_test_only_peripheral=opts.test_only_peripheral,
221 _opts_test_only_common=opts.test_only_common,
222 _opts_verbose_skipped_tests=opts.verbose_skipped_tests,
223 _opts_verbose_test_result_only=opts.verbose_test_result_only,
224 _opts_verbose=opts.verbose,
225 _opts_firmware_global_name=opts.firmware_global_name,
226 _opts_only_build_tests=opts.only_build_tests,
227 _opts_parallel_test_exec=opts.parallel_test_exec,
228 _opts_suppress_summary=opts.suppress_summary,
229 _opts_test_x_toolchain_summary=opts.test_x_toolchain_summary,
230 _opts_copy_method=opts.copy_method,
231 _opts_mut_reset_type=opts.mut_reset_type,
232 _opts_jobs=opts.jobs,
233 _opts_waterfall_test=opts.waterfall_test,
234 _opts_extend_test_timeout=opts.extend_test_timeout)
236 # Runs test suite in CLI mode
237 singletest_in_cli_mode(single_test)