3 Copyright (c) 2011-2016 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
21 """! @package mbed-host-tests
23 Flash, reset and perform host supervised tests on mbed platforms.
24 Write your own programs (import this package) or use 'mbedhtrun' command line tool instead.
32 from os
import listdir
33 from os.path
import isfile, join, abspath, basename
35 from optparse
import OptionParser
36 from optparse
import SUPPRESS_HELP
37 from mbed_host_tests
import host_tests_plugins
43 DEFAULT_BAUD_RATE = 9600
52 methods = [
'CopyMethod',
'ResetMethod']
54 for method
in methods:
55 result[method] = host_tests_plugins.get_plugin_caps(method)
60 """! Function creates CLI parser object and returns populated options object.
61 @return Function returns 'options' object returned from OptionParser class
62 @details Options object later can be used to populate host test selector script.
64 parser = OptionParser()
66 parser.add_option(
"-m",
"--micro",
68 help=
"Target microcontroller name",
71 parser.add_option(
"-p",
"--port",
73 help=
"Serial port of the target",
76 parser.add_option(
"-d",
"--disk",
78 help=
"Target disk (mount point) path",
81 parser.add_option(
"-t",
"--target-id",
83 help=
"Unique Target Id or mbed platform",
86 parser.add_option(
"",
"--sync",
90 help=
"Define how many times __sync packet will be sent to device: 0: none; -1: forever; 1,2,3... - number of times (Default 2 time)",
91 metavar=
"SYNC_BEHAVIOR")
93 parser.add_option(
"",
"--sync-timeout",
97 help=
"Define delay in seconds between __sync packet (Default is 5 seconds)",
98 metavar=
"SYNC_TIMEOUT")
100 parser.add_option(
"-f",
"--image-path",
102 help=
"Path with target's binary image",
103 metavar=
"IMAGE_PATH")
105 copy_methods_str =
"Plugin support: " +
', '.join(host_tests_plugins.get_plugin_caps(
'CopyMethod'))
107 parser.add_option(
"-c",
"--copy",
109 help=
"Copy (flash the target) method selector. " + copy_methods_str,
110 metavar=
"COPY_METHOD")
112 parser.add_option(
"",
"--retry-copy",
116 help=
"Number of attempts to flash the target",
117 metavar=
"RETRY_COPY")
119 parser.add_option(
"",
"--tag-filters",
123 help=
"Comma seperated list of device tags used when allocating a target to specify required hardware or attributes [--tag-filters tag1,tag2]",
124 metavar=
"TAG_FILTERS")
126 reset_methods_str =
"Plugin support: " +
', '.join(host_tests_plugins.get_plugin_caps(
'ResetMethod'))
128 parser.add_option(
"-r",
"--reset",
129 dest=
"forced_reset_type",
130 help=
"Forces different type of reset. " + reset_methods_str)
132 parser.add_option(
"-C",
"--program_cycle_s",
133 dest=
"program_cycle_s",
135 help=
"Program cycle sleep. Define how many seconds you want wait after copying binary onto target (Default is 4 second)",
137 metavar=
"PROGRAM_CYCLE_S")
139 parser.add_option(
"-R",
"--reset-timeout",
140 dest=
"forced_reset_timeout",
144 help=
"When forcing a reset using option -r you can set up after reset idle delay in seconds (Default is 1 second)")
146 parser.add_option(
"--process-start-timeout",
147 dest=
"process_start_timeout",
151 help=
"This sets the maximum time in seconds to wait for an internal process to start. This mostly only affects machines under heavy load (Default is 60 seconds)")
153 parser.add_option(
"-e",
"--enum-host-tests",
154 dest=
"enum_host_tests",
156 default=[
"./test/host_tests"],
157 help=
"Define directory with local host tests")
159 parser.add_option(
'',
'--test-cfg',
160 dest=
'json_test_configuration',
161 help=
'Pass to host test class data about host test configuration')
163 parser.add_option(
'',
'--list',
167 help=
'Prints registered host test and exits')
169 parser.add_option(
'',
'--plugins',
173 help=
'Prints registered plugins and exits')
175 parser.add_option(
'-g',
'--grm',
176 dest=
'global_resource_mgr',
177 help=
'[Experimental] Global resource manager service module name, IP and port, example remote_client:10.2.123.43:3334')
181 imp.find_module(
'fm_agent')
183 fm_help=SUPPRESS_HELP
185 fm_help=
'Fast Model connection, This option requires mbed-fastmodel-agent module installed, list CONFIGs via "mbedfm"'
186 parser.add_option(
'',
'--fm',
187 dest=
'fast_model_connection',
192 parser.add_option(
'',
'--run',
196 help=
'Runs binary image on target (workflow: flash, reset, output console)')
198 parser.add_option(
'',
'--skip-flashing',
199 dest=
'skip_flashing',
202 help=
'Skips use of copy/flash plugin. Note: target will not be reflashed')
204 parser.add_option(
'',
'--skip-reset',
208 help=
'Skips use of reset plugin. Note: target will not be reset')
210 parser.add_option(
'-P',
'--polling-timeout',
211 dest=
'polling_timeout',
215 help=
'Timeout in sec for readiness of mount point and serial port of local or remote device. Default 60 sec')
217 parser.add_option(
'-b',
'--send-break',
218 dest=
'send_break_cmd',
221 help=
'Send reset signal to board on specified port (-p PORT) and print serial output. You can combine this with (-r RESET_TYPE) switch')
223 parser.add_option(
'',
'--baud-rate',
225 help=
"Baud rate of target, overrides values from mbed-ls, disk/mount point (-d, --disk-path), and serial port -p <port>:<baud rate>",
228 parser.add_option(
'-v',
'--verbose',
232 help=
'More verbose mode')
234 parser.add_option(
'',
'--serial-output-file',
235 dest=
'serial_output_file',
237 help=
'Save target serial output to this file.')
239 parser.add_option(
'',
'--compare-log',
242 help=
'Log file to compare with the serial output from target.')
244 parser.add_option(
'',
'--version',
248 help=
'Prints package version and exits')
250 parser.description =
"""Flash, reset and perform host supervised tests on mbed platforms"""
251 parser.epilog =
"""Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F"""
253 (options, _) = parser.parse_args()
255 if len(sys.argv) == 1:
def init_host_test_cli_params()
Function creates CLI parser object and returns populated options object.
def get_plugin_caps(methods=None)
Functional interface for test supervisor registry.