mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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