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

ARMmbed / mbed-os-tools / #447

09 Jun 2024 08:56PM UTC coverage: 58.956% (-1.0%) from 59.947%
#447

push

coveralls-python

web-flow
Merge eddec8328 into c467d6f14

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

384 existing lines in 14 files now uncovered.

2890 of 4902 relevant lines covered (58.96%)

0.59 hits per line

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

46.88
/src/mbed_os_tools/test/host_tests_plugins/module_reset_mbed.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 re
1✔
17
import pkg_resources
1✔
18
from .host_test_plugins import HostTestPluginBase
1✔
19

20

21
class HostTestPluginResetMethod_Mbed(HostTestPluginBase):
1✔
22

23
    # Plugin interface
24
    name = 'HostTestPluginResetMethod_Mbed'
1✔
25
    type = 'ResetMethod'
1✔
26
    stable = True
1✔
27
    capabilities = ['default']
1✔
28
    required_parameters = ['serial']
1✔
29

30
    def __init__(self):
1✔
31
        """! ctor
32
        @details We can check module version by referring to version attribute
33
        import pkg_resources
34
        print pkg_resources.require("mbed-host-tests")[0].version
35
        '2.7'
36
        """
37
        HostTestPluginBase.__init__(self)
1✔
38
        self.re_float = re.compile("^\d+\.\d+")
1✔
39
        pyserial_version = pkg_resources.require("pyserial")[0].version
1✔
40
        self.pyserial_version = self.get_pyserial_version(pyserial_version)
1✔
41
        self.is_pyserial_v3 = float(self.pyserial_version) >= 3.0
1✔
42

43
    def get_pyserial_version(self, pyserial_version):
1✔
44
        """! Retrieve pyserial module version
45
        @return Returns float with pyserial module number
46
        """
47
        version = 3.0
1✔
48
        m = self.re_float.search(pyserial_version)
1✔
49
        if m:
1✔
50
            try:
1✔
51
                version = float(m.group(0))
1✔
52
            except ValueError:
×
53
                version = 3.0   # We will assume you've got latest (3.0+)
×
54
        return version
1✔
55

56
    def safe_sendBreak(self, serial):
1✔
57
        """! Closure for pyserial version dependant API calls
58
        """
UNCOV
59
        if self.is_pyserial_v3:
×
UNCOV
60
            return self._safe_sendBreak_v3_0(serial)
×
61
        return self._safe_sendBreak_v2_7(serial)
×
62

63
    def _safe_sendBreak_v2_7(self, serial):
1✔
64
        """! pyserial 2.7 API implementation of sendBreak/setBreak
65
        @details
66
        Below API is deprecated for pyserial 3.x versions!
67
        http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.sendBreak
68
        http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.setBreak
69
        """
70
        result = True
×
71
        try:
×
72
            serial.sendBreak()
×
73
        except:
×
74
            # In Linux a termios.error is raised in sendBreak and in setBreak.
75
            # The following setBreak() is needed to release the reset signal on the target mcu.
76
            try:
×
77
                serial.setBreak(False)
×
78
            except:
×
79
                result = False
×
80
        return result
×
81

82
    def _safe_sendBreak_v3_0(self, serial):
1✔
83
        """! pyserial 3.x API implementation of send_brea / break_condition
84
        @details
85
        http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.send_break
86
        http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.break_condition
87
        """
UNCOV
88
        result = True
×
UNCOV
89
        try:
×
UNCOV
90
            serial.send_break()
×
UNCOV
91
        except:
×
92
            # In Linux a termios.error is raised in sendBreak and in setBreak.
93
            # The following break_condition = False is needed to release the reset signal on the target mcu.
UNCOV
94
            try:
×
UNCOV
95
                serial.break_condition = False
×
96
            except Exception as e:
×
97
                self.print_plugin_error("Error while doing 'serial.break_condition = False' : %s"% str(e))
×
98
                result = False
×
UNCOV
99
        return result
×
100

101
    def setup(self, *args, **kwargs):
1✔
102
        """! Configure plugin, this function should be called before plugin execute() method is used.
103
        """
104
        return True
1✔
105

106
    def execute(self, capability, *args, **kwargs):
1✔
107
        """! Executes capability by name
108

109
        @param capability Capability name
110
        @param args Additional arguments
111
        @param kwargs Additional arguments
112
        @details Each capability e.g. may directly just call some command line program or execute building pythonic function
113
        @return Capability call return value
114
        """
UNCOV
115
        if not kwargs['serial']:
×
116
            self.print_plugin_error("Error: serial port not set (not opened?)")
×
117
            return False
×
118

UNCOV
119
        result = False
×
UNCOV
120
        if self.check_parameters(capability, *args, **kwargs) is True:
×
UNCOV
121
            if kwargs['serial']:
×
UNCOV
122
                if capability == 'default':
×
UNCOV
123
                    serial = kwargs['serial']
×
UNCOV
124
                    result = self.safe_sendBreak(serial)
×
UNCOV
125
        return result
×
126

127

128
def load_plugin():
1✔
129
    """! Returns plugin available in this module
130
    """
131
    return HostTestPluginResetMethod_Mbed()
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