]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/workspace_tools/singletest.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / workspace_tools / singletest.py
1 #!/usr/bin/env python2
2
3 """
4 mbed SDK
5 Copyright (c) 2011-2014 ARM Limited
6
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
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
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.
18
19 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
20 """
21
22 """
23 File format example: test_spec.json:
24 {
25 "targets": {
26 "KL46Z": ["ARM", "GCC_ARM"],
27 "LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "GCC_CS", "IAR"],
28 "LPC11U24": ["uARM"],
29 "NRF51822": ["ARM"]
30 }
31 }
32
33 File format example: muts_all.json:
34 {
35 "1" : {"mcu": "LPC1768",
36 "port":"COM4",
37 "disk":"J:\\",
38 "peripherals": ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"]
39 },
40
41 "2" : {"mcu": "KL25Z",
42 "port":"COM7",
43 "disk":"G:\\",
44 "peripherals": ["digital_loop", "port_loop", "analog_loop"]
45 }
46 }
47 """
48
49
50 # Be sure that the tools directory is in the search path
51 import sys
52 from os.path import join, abspath, dirname
53
54 ROOT = abspath(join(dirname(__file__), ".."))
55 sys.path.insert(0, ROOT)
56
57
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'])
61
62 # Imports related to mbed build api
63 from workspace_tools.build_api import mcu_toolchain_matrix
64
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
77
78 # Importing extra modules which can be not installed but if available they can extend test suite functionality
79 try:
80 import mbed_lstools
81 except:
82 pass
83
84 def get_version():
85 """ Returns test script version
86 """
87 single_test_version_major = 1
88 single_test_version_minor = 4
89 return (single_test_version_major, single_test_version_minor)
90
91
92 if __name__ == '__main__':
93 # Command line options
94 parser = get_default_test_options_parser()
95
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"""
98
99 (opts, args) = parser.parse_args()
100
101 # Print scrip version
102 if opts.version:
103 print parser.description
104 print parser.epilog
105 print "Version %d.%d"% get_version()
106 exit(0)
107
108 if opts.db_url and opts.verbose_test_configuration_only:
109 detect_database_verbose(opts.db_url)
110 exit(0)
111
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)
115 exit(0)
116
117 # Print summary / information about automation test status
118 if opts.test_case_report:
119 test_case_report_cols = ['id',
120 'automated',
121 'description',
122 'peripherals',
123 'host_test',
124 'duration',
125 'source_dir']
126 print get_avail_tests_summary_table(cols=test_case_report_cols,
127 result_summary=False,
128 join_delim='\n',
129 platform_filter=opts.general_filter_regex)
130 exit(0)
131
132 # Only prints matrix of supported toolchains
133 if opts.supported_toolchains:
134 print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
135 exit(0)
136
137 test_spec = None
138 MUTs = None
139
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... "
144
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'],
150 mut['serial_port'],
151 mut['mount_point'])
152
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)
166 else:
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:
173 parser.print_help()
174 exit(-1)
175
176 # Get extra MUTs if applicable
177 MUTs = get_json_data_from_file(opts.muts_spec_filename) if opts.muts_spec_filename else None
178
179 if MUTs is None:
180 if not opts.muts_spec_filename:
181 parser.print_help()
182 exit(-1)
183
184 if opts.verbose_test_configuration_only:
185 print "MUTs configuration in %s:"% ('auto-detected' if opts.auto_detect else opts.muts_spec_filename)
186 if MUTs:
187 print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex)
188 print
189 print "Test specification in %s:"% ('auto-detected' if opts.auto_detect else opts.test_spec_filename)
190 if test_spec:
191 print print_test_configuration_from_json(test_spec)
192 exit(0)
193
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)
199
200 if opts.only_build_tests:
201 # We are skipping testing phase, and suppress summary
202 opts.suppress_summary = True
203
204 single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value,
205 _test_loops_list=opts.test_loops_list,
206 _muts=MUTs,
207 _clean=opts.clean,
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)
235
236 # Runs test suite in CLI mode
237 singletest_in_cli_mode(single_test)
Imprint / Impressum