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 python
elessair 0:f269e3021894 2 """
elessair 0:f269e3021894 3 mbed SDK
elessair 0:f269e3021894 4 Copyright (c) 2011-2013 ARM Limited
elessair 0:f269e3021894 5
elessair 0:f269e3021894 6 Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 7 you may not use this file except in compliance with the License.
elessair 0:f269e3021894 8 You may obtain a copy of the License at
elessair 0:f269e3021894 9
elessair 0:f269e3021894 10 http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 11
elessair 0:f269e3021894 12 Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 13 distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 15 See the License for the specific language governing permissions and
elessair 0:f269e3021894 16 limitations under the License.
elessair 0:f269e3021894 17 """
elessair 0:f269e3021894 18 import sys
elessair 0:f269e3021894 19 from time import time
elessair 0:f269e3021894 20 from os.path import join, abspath, dirname, normpath
elessair 0:f269e3021894 21 from optparse import OptionParser
elessair 0:f269e3021894 22 import json
elessair 0:f269e3021894 23 from shutil import copy
elessair 0:f269e3021894 24
elessair 0:f269e3021894 25 # Be sure that the tools directory is in the search path
elessair 0:f269e3021894 26 ROOT = abspath(join(dirname(__file__), ".."))
elessair 0:f269e3021894 27 sys.path.insert(0, ROOT)
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 from tools.build_api import build_mbed_libs
elessair 0:f269e3021894 30 from tools.build_api import write_build_report
elessair 0:f269e3021894 31 from tools.build_api import get_mbed_official_release
elessair 0:f269e3021894 32 from tools.options import extract_profile
elessair 0:f269e3021894 33 from tools.targets import TARGET_MAP, TARGET_NAMES
elessair 0:f269e3021894 34 from tools.test_exporters import ReportExporter, ResultExporterType
elessair 0:f269e3021894 35 from tools.test_api import SingleTestRunner
elessair 0:f269e3021894 36 from tools.test_api import singletest_in_cli_mode
elessair 0:f269e3021894 37 from tools.paths import TEST_DIR, MBED_LIBRARIES
elessair 0:f269e3021894 38 from tools.tests import TEST_MAP
elessair 0:f269e3021894 39
elessair 0:f269e3021894 40 OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
elessair 0:f269e3021894 41
elessair 0:f269e3021894 42 if __name__ == '__main__':
elessair 0:f269e3021894 43 parser = OptionParser()
elessair 0:f269e3021894 44 parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
elessair 0:f269e3021894 45 help="Build using only the official toolchain for each target")
elessair 0:f269e3021894 46 parser.add_option("-j", "--jobs", type="int", dest="jobs",
elessair 0:f269e3021894 47 default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
elessair 0:f269e3021894 48 parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
elessair 0:f269e3021894 49 default=False, help="Verbose diagnostic output")
elessair 0:f269e3021894 50 parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
elessair 0:f269e3021894 51
elessair 0:f269e3021894 52 parser.add_option("--profile", dest="profile", action="append", default=[])
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 parser.add_option("-L", "--list-config", action="store_true", dest="list_config",
elessair 0:f269e3021894 57 default=False, help="List the platforms and toolchains in the release in JSON")
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59 parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file")
elessair 0:f269e3021894 60
elessair 0:f269e3021894 61 parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)")
elessair 0:f269e3021894 62
elessair 0:f269e3021894 63
elessair 0:f269e3021894 64 options, args = parser.parse_args()
elessair 0:f269e3021894 65
elessair 0:f269e3021894 66
elessair 0:f269e3021894 67
elessair 0:f269e3021894 68 if options.list_config:
elessair 0:f269e3021894 69 print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4)
elessair 0:f269e3021894 70 sys.exit()
elessair 0:f269e3021894 71
elessair 0:f269e3021894 72 start = time()
elessair 0:f269e3021894 73 build_report = {}
elessair 0:f269e3021894 74 build_properties = {}
elessair 0:f269e3021894 75
elessair 0:f269e3021894 76 platforms = None
elessair 0:f269e3021894 77 if options.platforms != "":
elessair 0:f269e3021894 78 platforms = set(options.platforms.split(","))
elessair 0:f269e3021894 79
elessair 0:f269e3021894 80 if options.build_tests:
elessair 0:f269e3021894 81 # Get all paths
elessair 0:f269e3021894 82 directories = options.build_tests.split(',')
elessair 0:f269e3021894 83 for i in range(len(directories)):
elessair 0:f269e3021894 84 directories[i] = normpath(join(TEST_DIR, directories[i]))
elessair 0:f269e3021894 85
elessair 0:f269e3021894 86 test_names = []
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 for test_id in TEST_MAP.keys():
elessair 0:f269e3021894 89 # Prevents tests with multiple source dirs from being checked
elessair 0:f269e3021894 90 if isinstance( TEST_MAP[test_id].source_dir, basestring):
elessair 0:f269e3021894 91 test_path = normpath(TEST_MAP[test_id].source_dir)
elessair 0:f269e3021894 92 for directory in directories:
elessair 0:f269e3021894 93 if directory in test_path:
elessair 0:f269e3021894 94 test_names.append(test_id)
elessair 0:f269e3021894 95
elessair 0:f269e3021894 96 mut_counter = 1
elessair 0:f269e3021894 97 mut = {}
elessair 0:f269e3021894 98 test_spec = {
elessair 0:f269e3021894 99 "targets": {}
elessair 0:f269e3021894 100 }
elessair 0:f269e3021894 101
elessair 0:f269e3021894 102 if options.toolchains:
elessair 0:f269e3021894 103 print "Only building using the following toolchains: %s" % (options.toolchains)
elessair 0:f269e3021894 104
elessair 0:f269e3021894 105 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
elessair 0:f269e3021894 106 toolchains = None
elessair 0:f269e3021894 107 if platforms is not None and not target_name in platforms:
elessair 0:f269e3021894 108 print("Excluding %s from release" % target_name)
elessair 0:f269e3021894 109 continue
elessair 0:f269e3021894 110
elessair 0:f269e3021894 111 if target_name not in TARGET_NAMES:
elessair 0:f269e3021894 112 print "Target '%s' is not a valid target. Excluding from release"
elessair 0:f269e3021894 113 continue
elessair 0:f269e3021894 114
elessair 0:f269e3021894 115 if options.official_only:
elessair 0:f269e3021894 116 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
elessair 0:f269e3021894 117 else:
elessair 0:f269e3021894 118 toolchains = toolchain_list
elessair 0:f269e3021894 119
elessair 0:f269e3021894 120 if options.toolchains:
elessair 0:f269e3021894 121 toolchainSet = set(toolchains)
elessair 0:f269e3021894 122 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
elessair 0:f269e3021894 123
elessair 0:f269e3021894 124 mut[str(mut_counter)] = {
elessair 0:f269e3021894 125 "mcu": target_name
elessair 0:f269e3021894 126 }
elessair 0:f269e3021894 127
elessair 0:f269e3021894 128 mut_counter += 1
elessair 0:f269e3021894 129
elessair 0:f269e3021894 130 test_spec["targets"][target_name] = toolchains
elessair 0:f269e3021894 131
elessair 0:f269e3021894 132 single_test = SingleTestRunner(_muts=mut,
elessair 0:f269e3021894 133 _parser=parser,
elessair 0:f269e3021894 134 _opts=options,
elessair 0:f269e3021894 135 _opts_report_build_file_name=options.report_build_file_name,
elessair 0:f269e3021894 136 _test_spec=test_spec,
elessair 0:f269e3021894 137 _opts_test_by_names=",".join(test_names),
elessair 0:f269e3021894 138 _opts_verbose=options.verbose,
elessair 0:f269e3021894 139 _opts_only_build_tests=True,
elessair 0:f269e3021894 140 _opts_suppress_summary=True,
elessair 0:f269e3021894 141 _opts_jobs=options.jobs,
elessair 0:f269e3021894 142 _opts_include_non_automated=True,
elessair 0:f269e3021894 143 _opts_build_report=build_report,
elessair 0:f269e3021894 144 _opts_build_properties=build_properties)
elessair 0:f269e3021894 145 # Runs test suite in CLI mode
elessair 0:f269e3021894 146 test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute()
elessair 0:f269e3021894 147 else:
elessair 0:f269e3021894 148 for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
elessair 0:f269e3021894 149 if platforms is not None and not target_name in platforms:
elessair 0:f269e3021894 150 print("Excluding %s from release" % target_name)
elessair 0:f269e3021894 151 continue
elessair 0:f269e3021894 152
elessair 0:f269e3021894 153 if target_name not in TARGET_NAMES:
elessair 0:f269e3021894 154 print "Target '%s' is not a valid target. Excluding from release"
elessair 0:f269e3021894 155 continue
elessair 0:f269e3021894 156
elessair 0:f269e3021894 157 if options.official_only:
elessair 0:f269e3021894 158 toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
elessair 0:f269e3021894 159 else:
elessair 0:f269e3021894 160 toolchains = toolchain_list
elessair 0:f269e3021894 161
elessair 0:f269e3021894 162 if options.toolchains:
elessair 0:f269e3021894 163 print "Only building using the following toolchains: %s" % (options.toolchains)
elessair 0:f269e3021894 164 toolchainSet = set(toolchains)
elessair 0:f269e3021894 165 toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
elessair 0:f269e3021894 166
elessair 0:f269e3021894 167 for toolchain in toolchains:
elessair 0:f269e3021894 168 id = "%s::%s" % (target_name, toolchain)
elessair 0:f269e3021894 169
elessair 0:f269e3021894 170 profile = extract_profile(parser, options, toolchain)
elessair 0:f269e3021894 171
elessair 0:f269e3021894 172 try:
elessair 0:f269e3021894 173 built_mbed_lib = build_mbed_libs(TARGET_MAP[target_name],
elessair 0:f269e3021894 174 toolchain,
elessair 0:f269e3021894 175 verbose=options.verbose,
elessair 0:f269e3021894 176 jobs=options.jobs,
elessair 0:f269e3021894 177 report=build_report,
elessair 0:f269e3021894 178 properties=build_properties,
elessair 0:f269e3021894 179 build_profile=profile)
elessair 0:f269e3021894 180
elessair 0:f269e3021894 181 except Exception, e:
elessair 0:f269e3021894 182 print str(e)
elessair 0:f269e3021894 183
elessair 0:f269e3021894 184 # copy targets.json file as part of the release
elessair 0:f269e3021894 185 copy(join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'), MBED_LIBRARIES)
elessair 0:f269e3021894 186
elessair 0:f269e3021894 187 # Write summary of the builds
elessair 0:f269e3021894 188 if options.report_build_file_name:
elessair 0:f269e3021894 189 file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
elessair 0:f269e3021894 190 file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties)
elessair 0:f269e3021894 191
elessair 0:f269e3021894 192 print "\n\nCompleted in: (%.2f)s" % (time() - start)
elessair 0:f269e3021894 193
elessair 0:f269e3021894 194 print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
elessair 0:f269e3021894 195 status = print_report_exporter.report(build_report)
elessair 0:f269e3021894 196
elessair 0:f269e3021894 197 if not status:
elessair 0:f269e3021894 198 sys.exit(1)