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

ARMmbed / mbed-os-tools / #457

24 Aug 2024 09:15PM UTC coverage: 0.0% (-59.9%) from 59.947%
#457

push

coveralls-python

web-flow
Merge 7c6dbce13 into c467d6f14

0 of 4902 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/mbed_os_tools/test/host_tests_toolbox/host_functional.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
import sys
×
17
import json
×
18
from time import sleep
×
19
from serial import Serial, SerialException
×
20
from .. import host_tests_plugins, DEFAULT_BAUD_RATE
×
21

22

23
def flash_dev(disk=None,
×
24
              image_path=None,
25
              copy_method='default',
26
              port=None,
27
              program_cycle_s=4):
28
    """! Flash device using pythonic interface
29
    @param disk Switch -d <disk>
30
    @param image_path Switch -f <image_path>
31
    @param copy_method Switch -c <copy_method> (default: shell)
32
    @param port Switch -p <port>
33
    """
34
    if copy_method == 'default':
×
35
        copy_method = 'shell'
×
36
    result = False
×
37
    result = host_tests_plugins.call_plugin('CopyMethod',
×
38
                                            copy_method,
39
                                            image_path=image_path,
40
                                            serial=port,
41
                                            destination_disk=disk)
42
    sleep(program_cycle_s)
×
43
    return result
×
44

45
def reset_dev(port=None,
×
46
              disk=None,
47
              reset_type='default',
48
              reset_timeout=1,
49
              serial_port=None,
50
              baudrate=DEFAULT_BAUD_RATE,
51
              timeout=1,
52
              verbose=False):
53
    """! Reset device using pythonic interface
54
    @param port Switch -p <port>
55
    @param disk Switch -d <disk>
56
    @param reset_type Switch -r <reset_type>
57
    @param reset_timeout Switch -R <reset_timeout>
58
    @param serial_port Serial port handler, set to None if you want this function to open serial
59

60
    @param baudrate Serial port baudrate
61
    @param timeout Serial port timeout
62
    @param verbose Verbose mode
63
    """
64

65
    result = False
×
66
    if not serial_port:
×
67
        try:
×
68
            with Serial(port, baudrate=baudrate, timeout=timeout) as serial_port:
×
69
                result = host_tests_plugins.call_plugin('ResetMethod',
×
70
                                                        reset_type,
71
                                                        serial=serial_port,
72
                                                        disk=disk)
73
            sleep(reset_timeout)
×
74
        except SerialException as e:
×
75
            if verbose:
×
76
                print("%s" % (str(e)))
×
77
            result = False
×
78
    return result
×
79

80
def handle_send_break_cmd(port,
×
81
                          disk,
82
                          reset_type=None,
83
                          baudrate=None,
84
                          timeout=1,
85
                          verbose=False):
86
    """! Resets platforms and prints serial port output
87
        @detail Mix with switch -r RESET_TYPE and -p PORT for versatility
88
    """
89
    if not reset_type:
×
90
        reset_type = 'default'
×
91

92
    port_config = port.split(':')
×
93
    if len(port_config) == 2:
×
94
        # -p COM4:115200
95
        port = port_config[0]
×
96
        baudrate = int(port_config[1]) if not baudrate else baudrate
×
97
    elif len(port_config) == 3:
×
98
        # -p COM4:115200:0.5
99
        port = port_config[0]
×
100
        baudrate = int(port_config[1]) if not baudrate else baudrate
×
101
        timeout = float(port_config[2])
×
102

103
    # Use default baud rate value if not set
104
    if not baudrate:
×
105
        baudrate = DEFAULT_BAUD_RATE
×
106

107
    if verbose:
×
108
        print("mbedhtrun: serial port configuration: %s:%s:%s"% (port, str(baudrate), str(timeout)))
×
109

110
    try:
×
111
        serial_port = Serial(port, baudrate=baudrate, timeout=timeout)
×
112
    except Exception as e:
×
113
        print("mbedhtrun: %s" % (str(e)))
×
114
        print(json.dumps({
×
115
            "port" : port,
116
            "disk" : disk,
117
            "baudrate" : baudrate,
118
            "timeout" : timeout,
119
            "reset_type" : reset_type,
120
            }, indent=4))
121
        return False
×
122

123
    serial_port.flush()
×
124
    # Reset using one of the plugins
125
    result = host_tests_plugins.call_plugin('ResetMethod', reset_type, serial=serial_port, disk=disk)
×
126
    if not result:
×
127
        print("mbedhtrun: reset plugin failed")
×
128
        print(json.dumps({
×
129
            "port" : port,
130
            "disk" : disk,
131
            "baudrate" : baudrate,
132
            "timeout" : timeout,
133
            "reset_type" : reset_type
134
            }, indent=4))
135
        return False
×
136

137
    print("mbedhtrun: serial dump started (use ctrl+c to break)")
×
138
    try:
×
139
        while True:
140
            test_output = serial_port.read(512)
×
141
            if test_output:
×
142
                sys.stdout.write('%s'% test_output)
×
143
            if "{end}" in test_output:
×
144
                if verbose:
×
145
                    print()
×
146
                    print("mbedhtrun: stopped (found '{end}' terminator)")
×
147
                break
×
148
    except KeyboardInterrupt:
×
149
        print("ctrl+c break")
×
150

151
    serial_port.close()
×
152
    return True
×
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

© 2025 Coveralls, Inc