def __call__(self, args): if not is_mbed_dir(): error("Run this command from a mbed project directory.") return False try: from workspace_tools.build_api import build_project from workspace_tools.targets import TARGET_MAP, TARGET_NAMES from workspace_tools.toolchains import TOOLCHAINS except: error("Unable to initialize build system.") error("Check that 'mbed-tools' is installed.") return False p = OptionParser() p.add_option("-m", "--mcu", dest="mcu") p.add_option("-t", "--toolchain", dest="toolchain") p.add_option("-c", "--clean", action="store_true", dest="clean", default=False) p.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False) p.add_option("-b", "--build", dest="build_dir") (options, args) = p.parse_args(args) if args: return None mcu = options.mcu or cfg.get("mcu") toolchain = options.toolchain or cfg.get("toolchain") if not mcu: error("MCU not specified, aborting.") return False if not toolchain: error("Toolchain not specified, aborting.") return False if not mcu in TARGET_NAMES: error("Invalid MCU '%s', valid choices: %s" % (mcu, ','.join(TARGET_NAMES))) return False if not toolchain in TOOLCHAINS: error("Invalid toolchain '%s', valid choices: %s" % (toolchain, ','.join(TOOLCHAINS))) return False target = TARGET_MAP[mcu] if not toolchain in target.supported_toolchains: error("Toolchain '%s' is not supported for target '%s'." % (toolchain, mcu)) error("Supported toolchains: %s" % ' '.join(target.supported_toolchains)) return False build_dir = options.build_dir or cfg.get("build_dir") or join(os.getcwd(), ".build") if options.build_dir and not cfg.get("build_dir"): cfg.set("build_dir", abspath(options.build_dir)) build_dir = join(build_dir, "%s_%s" % (mcu, toolchain)) try: build_project(os.getcwd(), build_dir, target, toolchain, [], [], linker_script=None, clean=options.clean, verbose=options.verbose) except KeyboardInterrupt, e: info("\n[CTRL+c] exit")
def benchmarks(): # CSV Data csv_data = csv.writer(open(BENCHMARK_DATA_PATH, 'wb')) csv_data.writerow( ['Toolchain', "Target", "Benchmark", "code", "data", "bss", "flash"]) # Build for toolchain in ['ARM', 'uARM', 'GCC_CR', 'GCC_ARM']: for mcu in ["LPC1768", "LPC11U24"]: # Build Libraries build_mbed_libs(mcu, toolchain) # Build benchmarks build_dir = join(BUILD_DIR, "benchmarks", mcu, toolchain) for test_id, title in BENCHMARKS: # Build Benchmark try: test = TEST_MAP[test_id] path = build_project(test.source_dir, join(build_dir, test_id), mcu, toolchain, test.dependencies) base, ext = splitext(path) # Check Size code, data, bss, flash = get_size(base + '.elf') csv_data.writerow( [toolchain, mcu, title, code, data, bss, flash]) except Exception, e: print "Unable to build %s for toolchain %s targeting %s" % ( test_id, toolchain, mcu) print e
def benchmarks(): # CSV Data csv_data = csv.writer(open(BENCHMARK_DATA_PATH, 'wb')) csv_data.writerow(['Toolchain', "Target", "Benchmark", "code", "data", "bss", "flash"]) # Build for toolchain in ['ARM', 'uARM', 'GCC_CR', 'GCC_CS', 'GCC_ARM']: for mcu in ["LPC1768", "LPC11U24"]: # Build Libraries build_mbed_libs(mcu, toolchain) # Build benchmarks build_dir = join(BUILD_DIR, "benchmarks", mcu, toolchain) for test_id, title in BENCHMARKS: # Build Benchmark try: test = TEST_MAP[test_id] path = build_project(test.source_dir, join(build_dir, test_id), mcu, toolchain, test.dependencies) base, ext = splitext(path) # Check Size code, data, bss, flash = get_size(base+'.elf') csv_data.writerow([toolchain, mcu, title, code, data, bss, flash]) except Exception, e: print "Unable to build %s for toolchain %s targeting %s" % (test_id, toolchain, mcu) print e
# TODO: move this 2 below loops to separate function INC_DIRS = [] for lib_id in libraries: if 'inc_dirs_ext' in LIBRARY_MAP[lib_id] and LIBRARY_MAP[lib_id]['inc_dirs_ext']: INC_DIRS.extend(LIBRARY_MAP[lib_id]['inc_dirs_ext']) MACROS = [] for lib_id in libraries: if 'macros' in LIBRARY_MAP[lib_id] and LIBRARY_MAP[lib_id]['macros']: MACROS.extend(LIBRARY_MAP[lib_id]['macros']) project_name = opts.firmware_global_name if opts.firmware_global_name else None path = build_project(test.source_dir, join(build_dir, test_id), T, toolchain, test.dependencies, options=build_project_options, clean=clean, verbose=opts.verbose, name=project_name, macros=MACROS, inc_dirs=INC_DIRS) test_result_cache = join(dirname(path), "test_result.json") if opts.only_build_tests: # We are skipping testing phase, and suppress summary opts.suppress_summary = True continue # For an automated test the duration act as a timeout after # which the test gets interrupted test_spec = shape_test_request(target, path, test_id, test.duration) test_loops = single_test.get_test_loop_count(test_id)
if options.rtos: test.dependencies.append(RTOS_LIBRARIES) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) if options.source_dir is not None: test.source_dir = options.source_dir build_dir = options.source_dir if options.build_dir is not None: build_dir = options.build_dir target = TARGET_MAP[mcu] try: bin = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options, linker_script=options.linker_script, clean=options.clean, verbose=options.verbose, macros=options.macros, jobs=options.jobs) print 'Image: %s' % bin if options.disk: # Simple copy to the mbed disk copy(bin, options.disk) if options.serial: # Import pyserial: https://pypi.python.org/pypi/pyserial from serial import Serial sleep(target.program_cycle_s()) serial = Serial(options.serial, timeout = 1)
build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) if options.source_dir is not None: test.source_dir = options.source_dir build_dir = options.source_dir if options.build_dir is not None: build_dir = options.build_dir target = TARGET_MAP[mcu] try: bin_file = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options, linker_script=options.linker_script, clean=options.clean, verbose=options.verbose, silent=options.silent, macros=options.macros, jobs=options.jobs) print 'Image: %s' % bin_file if options.disk: # Simple copy to the mbed disk copy(bin_file, options.disk) if options.serial: # Import pyserial: https://pypi.python.org/pypi/pyserial from serial import Serial
if test_ids is not None and test_id not in test_ids: continue if test.automated and test.is_supported(target, toolchain): # Check if the server has the capability to serve our test request if not test_server.available(target, test.peripherals): print "The test server does not have such device: %s, %s" % (target, test.peripherals) continue test_result = { 'target': target, 'toolchain': toolchain, 'test_id': test_id, } path = build_project(test.source_dir, join(build_dir, test_id), target, toolchain, test.dependencies, clean=clean) test_result_cache = join(dirname(path), "test_result.json") if not clean and exists(test_result_cache): test_result = load_data(test_result_cache) else: # For an automated test the duration act as a timeout after # which the test gets interrupted report = test_server.request(target, path, test.duration, test_id) test_result['result'] = report['result'] store_data(test_result_cache, test_result) tests_results.append(test_result) print str(test_result) + '\n' if test_result['result'] == 'success':
continue if test.automated and test.is_supported(target, toolchain): if not is_peripherals_available(target, test.peripherals): if opts.verbose: print "TargetTest::%s::TestSkipped(%s)" % (target, ",".join(test.peripherals)) continue test_result = { 'target': target, 'toolchain': toolchain, 'test_id': test_id, } path = build_project(test.source_dir, join(build_dir, test_id), T, toolchain, test.dependencies, clean=clean, verbose=opts.verbose) test_result_cache = join(dirname(path), "test_result.json") # For an automated test the duration act as a timeout after # which the test gets interrupted test_spec = shape_test_request(target, path, test_id, test.duration) single_test_result = single_test.handle(test_spec, target, toolchain) test_summary.append(single_test_result) # print test_spec, target, toolchain elapsed_time = time() - start # Human readable summary if not opts.suppress_summary:
# Test test = Test(p) if not test.is_supported(mcu, toolchain): print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) sys.exit() # RTOS if options.rtos: test.dependencies.append(RTOS_LIBRARIES) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) target = TARGET_MAP[mcu] try: bin = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, clean=options.clean, verbose=options.verbose) print 'Image: %s' % bin if options.disk: # Simple copy to the mbed disk copy(bin, options.disk) if options.serial: sleep(target.program_cycle_s) serial = Serial(options.serial, timeout = 1) if options.baud: serial.setBaudrate(options.baud) serial.flushInput() serial.flushOutput() serial.sendBreak()
mcu, toolchain) sys.exit() # RTOS if options.rtos: test.dependencies.append(RTOS_LIBRARIES) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) target = TARGET_MAP[mcu] try: bin = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options, linker_script=options.linker_script, clean=options.clean, verbose=options.verbose) print 'Image: %s' % bin if options.disk: # Simple copy to the mbed disk copy(bin, options.disk) if options.serial: # Import pyserial: https://pypi.python.org/pypi/pyserial from serial import Serial sleep(target.program_cycle_s())
if test.automated and test.is_supported(target, toolchain): # Check if the server has the capability to serve our test request if not test_server.available(target, test.peripherals): print "The test server does not have such device: %s, %s" % ( target, test.peripherals) continue test_result = { 'target': target, 'toolchain': toolchain, 'test_id': test_id, } path = build_project(test.source_dir, join(build_dir, test_id), target, toolchain, test.dependencies, clean=clean) test_result_cache = join(dirname(path), "test_result.json") if not clean and exists(test_result_cache): test_result = load_data(test_result_cache) else: # For an automated test the duration act as a timeout after # which the test gets interrupted report = test_server.request(target, path, test.duration, test_id) test_result['result'] = report['result'] store_data(test_result_cache, test_result) tests_results.append(test_result)
INC_DIRS.extend( LIBRARY_MAP[lib_id]['inc_dirs_ext']) MACROS = [] for lib_id in libraries: if 'macros' in LIBRARY_MAP[lib_id] and LIBRARY_MAP[ lib_id]['macros']: MACROS.extend(LIBRARY_MAP[lib_id]['macros']) project_name = opts.firmware_global_name if opts.firmware_global_name else None path = build_project(test.source_dir, join(build_dir, test_id), T, toolchain, test.dependencies, options=build_project_options, clean=clean, verbose=opts.verbose, name=project_name, macros=MACROS, inc_dirs=INC_DIRS) test_result_cache = join(dirname(path), "test_result.json") if opts.only_build_tests: # We are skipping testing phase, and suppress summary opts.suppress_summary = True continue # For an automated test the duration act as a timeout after # which the test gets interrupted
target, ",".join(test.peripherals)) continue test_result = { 'target': target, 'toolchain': toolchain, 'test_id': test_id, } build_project_options = [ "analyze" ] if opts.goanna_for_tests else None path = build_project(test.source_dir, join(build_dir, test_id), T, toolchain, test.dependencies, options=build_project_options, clean=clean, verbose=opts.verbose) test_result_cache = join(dirname(path), "test_result.json") # For an automated test the duration act as a timeout after # which the test gets interrupted test_spec = shape_test_request(target, path, test_id, test.duration) single_test_result = single_test.handle( test_spec, target, toolchain) test_summary.append(single_test_result) # print test_spec, target, toolchain
# Test test = Test(p) if not test.is_supported(mcu, toolchain): print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) sys.exit() # RTOS if options.rtos: test.dependencies.append(RTOS_LIBRARIES) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) target = TARGET_MAP[mcu] try: bin = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, clean=options.clean, verbose=options.verbose) print 'Image: %s' % bin if options.disk: # Simple copy to the mbed disk copy(bin, options.disk) if options.serial: # Import pyserial: https://pypi.python.org/pypi/pyserial from serial import Serial sleep(target.program_cycle_s) serial = Serial(options.serial, timeout = 1) if options.baud: serial.setBaudrate(options.baud) serial.flushInput()