Added new flag -L to list all tests available. Also removed trailing spaces

pull/237/head
Przemek Wirkus 2014-03-27 11:17:53 +00:00
parent 3d49a491d4
commit 493ad639e2
1 changed files with 27 additions and 20 deletions

View File

@ -75,18 +75,25 @@ if __name__ == '__main__':
default=None, help="The mbed serial port") default=None, help="The mbed serial port")
parser.add_option("-b", "--baud", type="int", dest="baud", parser.add_option("-b", "--baud", type="int", dest="baud",
default=None, help="The mbed serial baud rate") default=None, help="The mbed serial baud rate")
parser.add_option("-L", "--list-tests", action="store_true", dest="list_tests",
default=False, help="List available tests in order and exit")
# Ideally, all the tests with a single "main" thread can be run with, or # Ideally, all the tests with a single "main" thread can be run with, or
# without the rtos # without the rtos
parser.add_option("--rtos", action="store_true", dest="rtos", parser.add_option("--rtos", action="store_true", dest="rtos",
default=False, help="Link to the rtos") default=False, help="Link to the rtos")
# Specify a different linker script # Specify a different linker script
parser.add_option("-l", "--linker", dest="linker_script", parser.add_option("-l", "--linker", dest="linker_script",
default=None, help="use the specified linker script") default=None, help="use the specified linker script")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
# Print available tests in order and exit
if options.list_tests is True:
print '\n'.join(map(str, sorted(TEST_MAP.values())))
sys.exit()
# force program to "0" if a source dir is specified # force program to "0" if a source dir is specified
if options.source_dir is not None: if options.source_dir is not None:
p = 0 p = 0
@ -106,22 +113,22 @@ if __name__ == '__main__':
args_error(parser, "[ERROR] Program with name '%s' not found" % n) args_error(parser, "[ERROR] Program with name '%s' not found" % n)
else: else:
n = alias n = alias
p = TEST_MAP[n].n p = TEST_MAP[n].n
if p is None or (p < 0) or (p > (len(TESTS)-1)): if p is None or (p < 0) or (p > (len(TESTS)-1)):
message = "[ERROR] You have to specify one of the following tests:\n" message = "[ERROR] You have to specify one of the following tests:\n"
message += '\n'.join(map(str, sorted(TEST_MAP.values()))) message += '\n'.join(map(str, sorted(TEST_MAP.values())))
args_error(parser, message) args_error(parser, message)
# Target # Target
if options.mcu is None : if options.mcu is None :
args_error(parser, "[ERROR] You should specify an MCU") args_error(parser, "[ERROR] You should specify an MCU")
mcu = options.mcu mcu = options.mcu
# Toolchain # Toolchain
if options.tool is None: if options.tool is None:
args_error(parser, "[ERROR] You should specify a TOOLCHAIN") args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
toolchain = options.tool toolchain = options.tool
# Test # Test
test = Test(p) test = Test(p)
if options.automated is not None: if options.automated is not None:
@ -140,19 +147,19 @@ if __name__ == '__main__':
if not test.is_supported(mcu, toolchain): if not test.is_supported(mcu, toolchain):
print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)
sys.exit() sys.exit()
# RTOS # RTOS
if options.rtos: if options.rtos:
test.dependencies.append(RTOS_LIBRARIES) test.dependencies.append(RTOS_LIBRARIES)
build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
if options.source_dir is not None: if options.source_dir is not None:
test.source_dir = options.source_dir test.source_dir = options.source_dir
build_dir = options.source_dir build_dir = options.source_dir
if options.build_dir is not None: if options.build_dir is not None:
build_dir = options.build_dir build_dir = options.build_dir
target = TARGET_MAP[mcu] target = TARGET_MAP[mcu]
try: try:
bin = build_project(test.source_dir, build_dir, target, toolchain, bin = build_project(test.source_dir, build_dir, target, toolchain,
@ -161,31 +168,31 @@ if __name__ == '__main__':
clean=options.clean, verbose=options.verbose, clean=options.clean, verbose=options.verbose,
macros=options.macros) macros=options.macros)
print 'Image: %s' % bin print 'Image: %s' % bin
if options.disk: if options.disk:
# Simple copy to the mbed disk # Simple copy to the mbed disk
copy(bin, options.disk) copy(bin, options.disk)
if options.serial: if options.serial:
# Import pyserial: https://pypi.python.org/pypi/pyserial # Import pyserial: https://pypi.python.org/pypi/pyserial
from serial import Serial from serial import Serial
sleep(target.program_cycle_s()) sleep(target.program_cycle_s())
serial = Serial(options.serial, timeout = 1) serial = Serial(options.serial, timeout = 1)
if options.baud: if options.baud:
serial.setBaudrate(options.baud) serial.setBaudrate(options.baud)
serial.flushInput() serial.flushInput()
serial.flushOutput() serial.flushOutput()
serial.sendBreak() serial.sendBreak()
while True: while True:
c = serial.read(512) c = serial.read(512)
sys.stdout.write(c) sys.stdout.write(c)
sys.stdout.flush() sys.stdout.flush()
except KeyboardInterrupt, e: except KeyboardInterrupt, e:
print "\n[CTRL+c] exit" print "\n[CTRL+c] exit"
except Exception,e: except Exception,e: