Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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