Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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