• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ARMmbed / mbed-os-tools / #449

10 Jun 2024 04:59AM UTC coverage: 66.721% (+6.8%) from 59.947%
#449

push

coveralls-python

web-flow
Merge e6930c309 into c467d6f14

2 of 2 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

3266 of 4895 relevant lines covered (66.72%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/src/mbed_os_tools/test/__init__.py
1
# Copyright (c) 2018, Arm Limited and affiliates.
2
# SPDX-License-Identifier: Apache-2.0
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16

17
"""! @package mbed-host-tests
18

19
Flash, reset and  perform host supervised tests on mbed platforms.
20
Write your own programs (import this package) or use 'mbedhtrun'
21
command line tool instead.
22

23
"""
24

25
import importlib
1✔
26
import sys
1✔
27
from optparse import OptionParser
1✔
28
from optparse import SUPPRESS_HELP
1✔
29
from . import host_tests_plugins
1✔
30
from .host_tests_registry import HostRegistry  # noqa: F401
1✔
31
from .host_tests import BaseHostTest, event_callback  # noqa: F401
1✔
32

33
# Set the default baud rate
34
DEFAULT_BAUD_RATE = 9600
1✔
35

36
###############################################################################
37
# Functional interface for test supervisor registry
38
###############################################################################
39

40

41
def get_plugin_caps(methods=None):
1✔
42
    if not methods:
×
43
        methods = ["CopyMethod", "ResetMethod"]
×
44
    result = {}
×
45
    for method in methods:
×
46
        result[method] = host_tests_plugins.get_plugin_caps(method)
×
47
    return result
×
48

49

50
def init_host_test_cli_params():
1✔
51
    """! Function creates CLI parser object and returns populated options object.
52
    @return Function returns 'options' object returned from OptionParser class
53
    @details Options object later can be used to populate host test selector script.
54
    """
55
    parser = OptionParser()
1✔
56

57
    parser.add_option(
1✔
58
        "-m",
59
        "--micro",
60
        dest="micro",
61
        help="Target microcontroller name",
62
        metavar="MICRO",
63
    )
64

65
    parser.add_option(
1✔
66
        "-p", "--port", dest="port", help="Serial port of the target", metavar="PORT"
67
    )
68

69
    parser.add_option(
1✔
70
        "-d",
71
        "--disk",
72
        dest="disk",
73
        help="Target disk (mount point) path",
74
        metavar="DISK_PATH",
75
    )
76

77
    parser.add_option(
1✔
78
        "-t",
79
        "--target-id",
80
        dest="target_id",
81
        help="Unique Target Id or mbed platform",
82
        metavar="TARGET_ID",
83
    )
84

85
    parser.add_option(
1✔
86
        "",
87
        "--sync",
88
        dest="sync_behavior",
89
        default=2,
90
        type=int,
91
        help=(
92
            "Define how many times __sync packet will be sent to device: 0: "
93
            "none; -1: forever; 1,2,3... - number of times (Default 2 time)"
94
        ),
95
        metavar="SYNC_BEHAVIOR",
96
    )
97

98
    parser.add_option(
1✔
99
        "",
100
        "--sync-timeout",
101
        dest="sync_timeout",
102
        default=5,
103
        type=int,
104
        help="Define delay in seconds between __sync packet (Default is 5 seconds)",
105
        metavar="SYNC_TIMEOUT",
106
    )
107

108
    parser.add_option(
1✔
109
        "-f",
110
        "--image-path",
111
        dest="image_path",
112
        help="Path with target's binary image",
113
        metavar="IMAGE_PATH",
114
    )
115

116
    copy_methods_str = "Plugin support: " + ", ".join(
1✔
117
        host_tests_plugins.get_plugin_caps("CopyMethod")
118
    )
119

120
    parser.add_option(
1✔
121
        "-c",
122
        "--copy",
123
        dest="copy_method",
124
        help="Copy (flash the target) method selector. " + copy_methods_str,
125
        metavar="COPY_METHOD",
126
    )
127

128
    parser.add_option(
1✔
129
        "",
130
        "--retry-copy",
131
        dest="retry_copy",
132
        default=3,
133
        type=int,
134
        help="Number of attempts to flash the target",
135
        metavar="RETRY_COPY",
136
    )
137

138
    parser.add_option(
1✔
139
        "",
140
        "--tag-filters",
141
        dest="tag_filters",
142
        default="",
143
        type=str,
144
        help=(
145
            "Comma seperated list of device tags used when allocating a target "
146
            "to specify required hardware or attributes [--tag-filters tag1,tag2]"
147
        ),
148
        metavar="TAG_FILTERS",
149
    )
150

151
    reset_methods_str = "Plugin support: " + ", ".join(
1✔
152
        host_tests_plugins.get_plugin_caps("ResetMethod")
153
    )
154

155
    parser.add_option(
1✔
156
        "-r",
157
        "--reset",
158
        dest="forced_reset_type",
159
        help="Forces different type of reset. " + reset_methods_str,
160
    )
161

162
    parser.add_option(
1✔
163
        "-C",
164
        "--program_cycle_s",
165
        dest="program_cycle_s",
166
        default=4,
167
        help=(
168
            "Program cycle sleep. Define how many seconds you want wait after "
169
            "copying binary onto target (Default is 4 second)"
170
        ),
171
        type="float",
172
        metavar="PROGRAM_CYCLE_S",
173
    )
174

175
    parser.add_option(
1✔
176
        "-R",
177
        "--reset-timeout",
178
        dest="forced_reset_timeout",
179
        default=1,
180
        metavar="NUMBER",
181
        type="float",
182
        help=(
183
            "When forcing a reset using option -r you can set up after reset "
184
            "idle delay in seconds (Default is 1 second)"
185
        ),
186
    )
187

188
    parser.add_option(
1✔
189
        "--process-start-timeout",
190
        dest="process_start_timeout",
191
        default=60,
192
        metavar="NUMBER",
193
        type="float",
194
        help=(
195
            "This sets the maximum time in seconds to wait for an internal "
196
            "process to start. This mostly only affects machines under heavy "
197
            "load (Default is 60 seconds)"
198
        ),
199
    )
200

201
    parser.add_option(
1✔
202
        "-e",
203
        "--enum-host-tests",
204
        dest="enum_host_tests",
205
        action="append",
206
        default=["./test/host_tests"],
207
        help="Define directory with local host tests",
208
    )
209

210
    parser.add_option(
1✔
211
        "",
212
        "--test-cfg",
213
        dest="json_test_configuration",
214
        help="Pass to host test class data about host test configuration",
215
    )
216

217
    parser.add_option(
1✔
218
        "",
219
        "--list",
220
        dest="list_reg_hts",
221
        default=False,
222
        action="store_true",
223
        help="Prints registered host test and exits",
224
    )
225

226
    parser.add_option(
1✔
227
        "",
228
        "--plugins",
229
        dest="list_plugins",
230
        default=False,
231
        action="store_true",
232
        help="Prints registered plugins and exits",
233
    )
234

235
    parser.add_option(
1✔
236
        "-g",
237
        "--grm",
238
        dest="global_resource_mgr",
239
        help=(
240
            'Global resource manager: "<remote mgr module>:<host url or IP address>'
241
            '[:<port>]", Ex. "module_name:10.2.123.43:3334", '
242
            'module_name:https://example.com"'
243
        ),
244
    )
245

246
    # Show --fm option only if "fm_agent" module installed
247
    try:
1✔
248
        importlib.util.find_spec("fm_agent")
1✔
UNCOV
249
    except ImportError:
×
UNCOV
250
        fm_help = SUPPRESS_HELP
×
251
    else:
252
        fm_help = (
1✔
253
            'Fast Model connection, This option requires mbed-fastmodel-agent '
254
            'module installed, list CONFIGs via "mbedfm"'
255
        )
256
    parser.add_option(
1✔
257
        "",
258
        "--fm",
259
        dest="fast_model_connection",
260
        metavar="CONFIG",
261
        default=None,
262
        help=fm_help,
263
    )
264

265
    parser.add_option(
1✔
266
        "",
267
        "--run",
268
        dest="run_binary",
269
        default=False,
270
        action="store_true",
271
        help="Runs binary image on target (workflow: flash, reset, output console)",
272
    )
273

274
    parser.add_option(
1✔
275
        "",
276
        "--skip-flashing",
277
        dest="skip_flashing",
278
        default=False,
279
        action="store_true",
280
        help="Skips use of copy/flash plugin. Note: target will not be reflashed",
281
    )
282

283
    parser.add_option(
1✔
284
        "",
285
        "--skip-reset",
286
        dest="skip_reset",
287
        default=False,
288
        action="store_true",
289
        help="Skips use of reset plugin. Note: target will not be reset",
290
    )
291

292
    parser.add_option(
1✔
293
        "-P",
294
        "--polling-timeout",
295
        dest="polling_timeout",
296
        default=60,
297
        metavar="NUMBER",
298
        type="int",
299
        help=(
300
            "Timeout in sec for readiness of mount point and serial port of "
301
            "local or remote device. Default 60 sec"
302
        ),
303
    )
304

305
    parser.add_option(
1✔
306
        "-b",
307
        "--send-break",
308
        dest="send_break_cmd",
309
        default=False,
310
        action="store_true",
311
        help=(
312
            "Send reset signal to board on specified port (-p PORT) and print "
313
            "serial output. You can combine this with (-r RESET_TYPE) switch"
314
        ),
315
    )
316

317
    parser.add_option(
1✔
318
        "",
319
        "--baud-rate",
320
        dest="baud_rate",
321
        help=(
322
            "Baud rate of target, overrides values from mbed-ls, disk/mount "
323
            "point (-d, --disk-path), and serial port -p <port>:<baud rate>"
324
        ),
325
        metavar="BAUD_RATE",
326
    )
327

328
    parser.add_option(
1✔
329
        "-v",
330
        "--verbose",
331
        dest="verbose",
332
        default=False,
333
        action="store_true",
334
        help="More verbose mode",
335
    )
336

337
    parser.add_option(
1✔
338
        "",
339
        "--serial-output-file",
340
        dest="serial_output_file",
341
        default=None,
342
        help="Save target serial output to this file.",
343
    )
344

345
    parser.add_option(
1✔
346
        "",
347
        "--compare-log",
348
        dest="compare_log",
349
        default=None,
350
        help="Log file to compare with the serial output from target.",
351
    )
352

353
    parser.add_option(
1✔
354
        "",
355
        "--version",
356
        dest="version",
357
        default=False,
358
        action="store_true",
359
        help="Prints package version and exits",
360
    )
361

362
    parser.add_option(
1✔
363
        "",
364
        "--format",
365
        dest="format",
366
        help="Image file format passed to pyocd (elf, bin, hex, axf...).",
367
    )
368

369
    parser.description = (
1✔
370
        """Flash, reset and perform host supervised tests on mbed platforms"""
371
    )
372
    parser.epilog = (
1✔
373
        """Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F"""
374
    )
375

376
    (options, _) = parser.parse_args()
1✔
377

378
    if len(sys.argv) == 1:
1✔
379
        parser.print_help()
×
380
        sys.exit()
×
381

382
    return options
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc