2015-04-22 22:23:19 +00:00
|
|
|
#! /usr/bin/env python2
|
2013-02-18 15:32:11 +00:00
|
|
|
"""
|
2013-08-06 13:38:00 +00:00
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
TEST BUILD & RUN
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
from time import sleep
|
2014-09-05 10:48:37 +00:00
|
|
|
from shutil import copy
|
2016-06-09 22:11:23 +00:00
|
|
|
from os.path import join, abspath, dirname, isfile, isdir
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
# Be sure that the tools directory is in the search path
|
|
|
|
ROOT = abspath(join(dirname(__file__), ".."))
|
2013-12-19 13:02:57 +00:00
|
|
|
sys.path.insert(0, ROOT)
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.utils import args_error
|
|
|
|
from tools.paths import BUILD_DIR
|
|
|
|
from tools.paths import RTOS_LIBRARIES
|
|
|
|
from tools.paths import RPC_LIBRARY
|
|
|
|
from tools.paths import ETH_LIBRARY
|
|
|
|
from tools.paths import USB_HOST_LIBRARIES, USB_LIBRARIES
|
|
|
|
from tools.paths import DSP_LIBRARIES
|
|
|
|
from tools.paths import FS_LIBRARY
|
|
|
|
from tools.paths import UBLOX_LIBRARY
|
|
|
|
from tools.tests import TESTS, Test, TEST_MAP
|
|
|
|
from tools.tests import TEST_MBED_LIB
|
2016-06-24 22:15:01 +00:00
|
|
|
from tools.tests import test_known, test_name_known
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.targets import TARGET_MAP
|
|
|
|
from tools.options import get_default_options_parser
|
|
|
|
from tools.build_api import build_project
|
2016-06-12 00:06:15 +00:00
|
|
|
from tools.build_api import mcu_toolchain_matrix
|
2016-06-24 22:15:01 +00:00
|
|
|
from utils import argparse_filestring_type
|
|
|
|
from argparse import ArgumentTypeError
|
2016-06-21 15:55:01 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
# Parse Options
|
|
|
|
parser = get_default_options_parser()
|
2016-06-24 22:15:01 +00:00
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
group.add_argument("-p",
|
|
|
|
type=test_known,
|
2014-12-03 10:53:50 +00:00
|
|
|
dest="program",
|
2013-02-18 15:32:11 +00:00
|
|
|
help="The index of the desired test program: [0-%d]" % (len(TESTS)-1))
|
2014-12-03 10:53:50 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-n",
|
|
|
|
type=test_name_known,
|
|
|
|
dest="program",
|
2013-06-24 13:32:08 +00:00
|
|
|
help="The name of the desired test program")
|
2014-12-03 10:53:50 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-j", "--jobs",
|
|
|
|
type=int,
|
2014-12-03 10:53:50 +00:00
|
|
|
dest="jobs",
|
2016-06-09 22:11:23 +00:00
|
|
|
default=0,
|
|
|
|
help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
|
2014-12-03 10:53:50 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-v", "--verbose",
|
2014-12-03 10:53:50 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="verbose",
|
|
|
|
default=False,
|
|
|
|
help="Verbose diagnostic output")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--silent",
|
2014-12-03 10:53:50 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="silent",
|
|
|
|
default=False,
|
|
|
|
help="Silent diagnostic output (no copy, compile notification)")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-D",
|
|
|
|
nargs="*",
|
2014-12-03 10:53:50 +00:00
|
|
|
dest="macros",
|
2013-10-21 08:11:06 +00:00
|
|
|
help="Add a macro definition")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-S", "--supported-toolchains",
|
2016-06-12 00:06:15 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="supported_toolchains",
|
|
|
|
default=False,
|
|
|
|
help="Displays supported matrix of MCUs and toolchains")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument('-f', '--filter',
|
2016-06-12 00:06:15 +00:00
|
|
|
dest='general_filter_regex',
|
|
|
|
default=None,
|
|
|
|
help='For some commands you can use filter to filter out results')
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
# Local run
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--automated", action="store_true", dest="automated",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=False, help="Automated test")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--host", dest="host_test",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="Host test")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--extra", dest="extra",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="Extra files")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--peripherals", dest="peripherals",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="Required peripherals")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--dep", dest="dependencies",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="Dependencies")
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
|
|
|
|
default=None, help="The source (input) directory", nargs="*")
|
|
|
|
parser.add_argument("--duration", type=int, dest="duration",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="Duration of the test")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--build", dest="build_dir",
|
2013-10-20 15:17:10 +00:00
|
|
|
default=None, help="The build (output) directory")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-N", "--artifact-name", dest="artifact_name",
|
2016-06-09 22:11:23 +00:00
|
|
|
default=None, help="The built project's name")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-d", "--disk", dest="disk",
|
2013-02-18 15:32:11 +00:00
|
|
|
default=None, help="The mbed disk")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-s", "--serial", dest="serial",
|
2013-02-18 15:32:11 +00:00
|
|
|
default=None, help="The mbed serial port")
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-b", "--baud", type=int, dest="baud",
|
2013-02-18 15:32:11 +00:00
|
|
|
default=None, help="The mbed serial baud rate")
|
2016-06-24 22:15:01 +00:00
|
|
|
group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests",
|
2014-03-27 11:17:53 +00:00
|
|
|
default=False, help="List available tests in order and exit")
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
# Ideally, all the tests with a single "main" thread can be run with, or
|
2014-12-01 14:51:55 +00:00
|
|
|
# without the rtos, eth, usb_host, usb, dsp, fat, ublox
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--rtos",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true", dest="rtos",
|
|
|
|
default=False, help="Link with RTOS library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--rpc",
|
2015-11-15 08:52:54 +00:00
|
|
|
action="store_true", dest="rpc",
|
|
|
|
default=False, help="Link with RPC library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--eth",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true", dest="eth",
|
|
|
|
default=False,
|
|
|
|
help="Link with Ethernet library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--usb_host",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="usb_host",
|
|
|
|
default=False,
|
|
|
|
help="Link with USB Host library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--usb",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="usb",
|
|
|
|
default=False,
|
|
|
|
help="Link with USB Device library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--dsp",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="dsp",
|
|
|
|
default=False,
|
|
|
|
help="Link with DSP library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--fat",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="fat",
|
|
|
|
default=False,
|
|
|
|
help="Link with FS ad SD card file system library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--ublox",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="ublox",
|
|
|
|
default=False,
|
|
|
|
help="Link with U-Blox library")
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("--testlib",
|
2014-12-01 14:51:55 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="testlib",
|
|
|
|
default=False,
|
|
|
|
help="Link with mbed test library")
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2013-06-10 14:44:08 +00:00
|
|
|
# Specify a different linker script
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-l", "--linker", dest="linker_script",
|
|
|
|
type=argparse_filestring_type,
|
2013-06-10 14:44:08 +00:00
|
|
|
default=None, help="use the specified linker script")
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
options = parser.parse_args()
|
2013-10-20 15:17:10 +00:00
|
|
|
|
2016-06-12 00:06:15 +00:00
|
|
|
# Only prints matrix of supported toolchains
|
|
|
|
if options.supported_toolchains:
|
|
|
|
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
|
|
|
|
exit(0)
|
|
|
|
|
2014-03-27 11:17:53 +00:00
|
|
|
# Print available tests in order and exit
|
|
|
|
if options.list_tests is True:
|
|
|
|
print '\n'.join(map(str, sorted(TEST_MAP.values())))
|
|
|
|
sys.exit()
|
|
|
|
|
2013-10-20 15:17:10 +00:00
|
|
|
# force program to "0" if a source dir is specified
|
|
|
|
if options.source_dir is not None:
|
|
|
|
p = 0
|
|
|
|
else:
|
2013-06-24 13:32:08 +00:00
|
|
|
# Program Number or name
|
2016-06-24 22:15:01 +00:00
|
|
|
p = options.program
|
2014-12-01 15:33:30 +00:00
|
|
|
|
|
|
|
# If 'p' was set via -n to list of numbers make this a single element integer list
|
|
|
|
if type(p) != type([]):
|
|
|
|
p = [p]
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
# Target
|
|
|
|
if options.mcu is None :
|
|
|
|
args_error(parser, "[ERROR] You should specify an MCU")
|
2016-06-24 22:15:01 +00:00
|
|
|
mcu = options.mcu[0]
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
# Toolchain
|
|
|
|
if options.tool is None:
|
|
|
|
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
|
2016-06-24 22:15:01 +00:00
|
|
|
toolchain = options.tool[0]
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
# Test
|
2014-12-01 15:07:17 +00:00
|
|
|
for test_no in p:
|
|
|
|
test = Test(test_no)
|
|
|
|
if options.automated is not None: test.automated = options.automated
|
|
|
|
if options.dependencies is not None: test.dependencies = options.dependencies
|
|
|
|
if options.host_test is not None: test.host_test = options.host_test;
|
|
|
|
if options.peripherals is not None: test.peripherals = options.peripherals;
|
|
|
|
if options.duration is not None: test.duration = options.duration;
|
|
|
|
if options.extra is not None: test.extra_files = options.extra
|
|
|
|
|
|
|
|
if not test.is_supported(mcu, toolchain):
|
|
|
|
print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# Linking with extra libraries
|
|
|
|
if options.rtos: test.dependencies.append(RTOS_LIBRARIES)
|
2015-11-15 08:52:54 +00:00
|
|
|
if options.rpc: test.dependencies.append(RPC_LIBRARY)
|
2014-12-01 15:07:17 +00:00
|
|
|
if options.eth: test.dependencies.append(ETH_LIBRARY)
|
|
|
|
if options.usb_host: test.dependencies.append(USB_HOST_LIBRARIES)
|
|
|
|
if options.usb: test.dependencies.append(USB_LIBRARIES)
|
|
|
|
if options.dsp: test.dependencies.append(DSP_LIBRARIES)
|
|
|
|
if options.fat: test.dependencies.append(FS_LIBRARY)
|
|
|
|
if options.ublox: test.dependencies.append(UBLOX_LIBRARY)
|
|
|
|
if options.testlib: test.dependencies.append(TEST_MBED_LIB)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
try:
|
2016-06-09 22:50:03 +00:00
|
|
|
bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, test.dependencies, options.options,
|
2014-12-01 15:33:30 +00:00
|
|
|
linker_script=options.linker_script,
|
|
|
|
clean=options.clean,
|
|
|
|
verbose=options.verbose,
|
2014-12-03 10:53:50 +00:00
|
|
|
silent=options.silent,
|
2014-12-01 15:33:30 +00:00
|
|
|
macros=options.macros,
|
2016-06-09 22:11:23 +00:00
|
|
|
jobs=options.jobs,
|
|
|
|
name=options.artifact_name)
|
2014-12-01 15:33:30 +00:00
|
|
|
print 'Image: %s'% bin_file
|
2014-12-01 15:07:17 +00:00
|
|
|
|
|
|
|
if options.disk:
|
|
|
|
# Simple copy to the mbed disk
|
2014-12-01 15:33:30 +00:00
|
|
|
copy(bin_file, options.disk)
|
2014-12-01 15:07:17 +00:00
|
|
|
|
|
|
|
if options.serial:
|
|
|
|
# Import pyserial: https://pypi.python.org/pypi/pyserial
|
|
|
|
from serial import Serial
|
|
|
|
|
2016-06-27 21:01:52 +00:00
|
|
|
sleep(TARGET_MAP[mcu].program_cycle_s)
|
2014-12-01 15:07:17 +00:00
|
|
|
|
|
|
|
serial = Serial(options.serial, timeout = 1)
|
|
|
|
if options.baud:
|
|
|
|
serial.setBaudrate(options.baud)
|
|
|
|
|
|
|
|
serial.flushInput()
|
|
|
|
serial.flushOutput()
|
2014-03-27 11:17:53 +00:00
|
|
|
|
2014-06-23 16:34:10 +00:00
|
|
|
try:
|
2014-12-01 15:07:17 +00:00
|
|
|
serial.sendBreak()
|
2014-06-23 16:34:10 +00:00
|
|
|
except:
|
2014-12-01 15:07:17 +00:00
|
|
|
# In linux a termios.error is raised in sendBreak and in setBreak.
|
|
|
|
# The following setBreak() is needed to release the reset signal on the target mcu.
|
|
|
|
try:
|
|
|
|
serial.setBreak(False)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
while True:
|
|
|
|
c = serial.read(512)
|
|
|
|
sys.stdout.write(c)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
except KeyboardInterrupt, e:
|
|
|
|
print "\n[CTRL+c] exit"
|
|
|
|
except Exception,e:
|
|
|
|
if options.verbose:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
else:
|
|
|
|
print "[ERROR] %s" % str(e)
|
2016-06-09 22:11:23 +00:00
|
|
|
|
|
|
|
sys.exit(1)
|