Mbed Host Tests
__init__.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2011-2016 ARM Limited
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18"""
19
20
21"""! @package mbed-host-tests
22
23Flash, reset and perform host supervised tests on mbed platforms.
24Write your own programs (import this package) or use 'mbedhtrun' command line tool instead.
25
26"""
27
28
29import os
30import imp
31import inspect
32from os import listdir
33from os.path import isfile, join, abspath, basename
34import sys
35from optparse import OptionParser
36from optparse import SUPPRESS_HELP
37from mbed_host_tests import host_tests_plugins
38from mbed_host_tests.host_tests_registry import HostRegistry
39from mbed_host_tests.host_tests import BaseHostTest, event_callback
40
41
42# Set the default baud rate
43DEFAULT_BAUD_RATE = 9600
44
45###############################################################################
46# Functional interface for test supervisor registry
47###############################################################################
48
49
50def get_plugin_caps(methods=None):
51 if not methods:
52 methods = ['CopyMethod', 'ResetMethod']
53 result = {}
54 for method in methods:
55 result[method] = host_tests_plugins.get_plugin_caps(method)
56 return result
57
58
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.
63 """
64 parser = OptionParser()
65
66 parser.add_option("-m", "--micro",
67 dest="micro",
68 help="Target microcontroller name",
69 metavar="MICRO")
70
71 parser.add_option("-p", "--port",
72 dest="port",
73 help="Serial port of the target",
74 metavar="PORT")
75
76 parser.add_option("-d", "--disk",
77 dest="disk",
78 help="Target disk (mount point) path",
79 metavar="DISK_PATH")
80
81 parser.add_option("-t", "--target-id",
82 dest="target_id",
83 help="Unique Target Id or mbed platform",
84 metavar="TARGET_ID")
85
86 parser.add_option("", "--sync",
87 dest="sync_behavior",
88 default=2,
89 type=int,
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")
92
93 parser.add_option("", "--sync-timeout",
94 dest="sync_timeout",
95 default=5,
96 type=int,
97 help="Define delay in seconds between __sync packet (Default is 5 seconds)",
98 metavar="SYNC_TIMEOUT")
99
100 parser.add_option("-f", "--image-path",
101 dest="image_path",
102 help="Path with target's binary image",
103 metavar="IMAGE_PATH")
104
105 copy_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('CopyMethod'))
106
107 parser.add_option("-c", "--copy",
108 dest="copy_method",
109 help="Copy (flash the target) method selector. " + copy_methods_str,
110 metavar="COPY_METHOD")
111
112 parser.add_option("", "--retry-copy",
113 dest="retry_copy",
114 default=3,
115 type=int,
116 help="Number of attempts to flash the target",
117 metavar="RETRY_COPY")
118
119 parser.add_option("", "--tag-filters",
120 dest="tag_filters",
121 default="",
122 type=str,
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")
125
126 reset_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('ResetMethod'))
127
128 parser.add_option("-r", "--reset",
129 dest="forced_reset_type",
130 help="Forces different type of reset. " + reset_methods_str)
131
132 parser.add_option("-C", "--program_cycle_s",
133 dest="program_cycle_s",
134 default=4,
135 help="Program cycle sleep. Define how many seconds you want wait after copying binary onto target (Default is 4 second)",
136 type="float",
137 metavar="PROGRAM_CYCLE_S")
138
139 parser.add_option("-R", "--reset-timeout",
140 dest="forced_reset_timeout",
141 default=1,
142 metavar="NUMBER",
143 type="float",
144 help="When forcing a reset using option -r you can set up after reset idle delay in seconds (Default is 1 second)")
145
146 parser.add_option("--process-start-timeout",
147 dest="process_start_timeout",
148 default=60,
149 metavar="NUMBER",
150 type="float",
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)")
152
153 parser.add_option("-e", "--enum-host-tests",
154 dest="enum_host_tests",
155 action="append",
156 default=["./test/host_tests"],
157 help="Define directory with local host tests")
158
159 parser.add_option('', '--test-cfg',
160 dest='json_test_configuration',
161 help='Pass to host test class data about host test configuration')
162
163 parser.add_option('', '--list',
164 dest='list_reg_hts',
165 default=False,
166 action="store_true",
167 help='Prints registered host test and exits')
168
169 parser.add_option('', '--plugins',
170 dest='list_plugins',
171 default=False,
172 action="store_true",
173 help='Prints registered plugins and exits')
174
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')
178
179 # Show --fm option only if "fm_agent" module installed
180 try:
181 imp.find_module('fm_agent')
182 except ImportError:
183 fm_help=SUPPRESS_HELP
184 else:
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',
188 metavar="CONFIG",
189 default=None,
190 help=fm_help)
191
192 parser.add_option('', '--run',
193 dest='run_binary',
194 default=False,
195 action="store_true",
196 help='Runs binary image on target (workflow: flash, reset, output console)')
197
198 parser.add_option('', '--skip-flashing',
199 dest='skip_flashing',
200 default=False,
201 action="store_true",
202 help='Skips use of copy/flash plugin. Note: target will not be reflashed')
203
204 parser.add_option('', '--skip-reset',
205 dest='skip_reset',
206 default=False,
207 action="store_true",
208 help='Skips use of reset plugin. Note: target will not be reset')
209
210 parser.add_option('-P', '--polling-timeout',
211 dest='polling_timeout',
212 default=60,
213 metavar="NUMBER",
214 type="int",
215 help='Timeout in sec for readiness of mount point and serial port of local or remote device. Default 60 sec')
216
217 parser.add_option('-b', '--send-break',
218 dest='send_break_cmd',
219 default=False,
220 action="store_true",
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')
222
223 parser.add_option('', '--baud-rate',
224 dest='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>",
226 metavar="BAUD_RATE")
227
228 parser.add_option('-v', '--verbose',
229 dest='verbose',
230 default=False,
231 action="store_true",
232 help='More verbose mode')
233
234 parser.add_option('', '--serial-output-file',
235 dest='serial_output_file',
236 default=None,
237 help='Save target serial output to this file.')
238
239 parser.add_option('', '--compare-log',
240 dest='compare_log',
241 default=None,
242 help='Log file to compare with the serial output from target.')
243
244 parser.add_option('', '--version',
245 dest='version',
246 default=False,
247 action="store_true",
248 help='Prints package version and exits')
249
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"""
252
253 (options, _) = parser.parse_args()
254
255 if len(sys.argv) == 1:
256 parser.print_help()
257 sys.exit()
258
259 return options
def init_host_test_cli_params()
Function creates CLI parser object and returns populated options object.
Definition: __init__.py:59