• 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

34.04
/src/mbed_os_tools/test/host_tests_plugins/module_copy_shell.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 os
1✔
17
from os.path import join, basename
1✔
18
from .host_test_plugins import HostTestPluginBase
1✔
19

20

21
class HostTestPluginCopyMethod_Shell(HostTestPluginBase):
1✔
22
    # Plugin interface
23
    name = 'HostTestPluginCopyMethod_Shell'
1✔
24
    type = 'CopyMethod'
1✔
25
    stable = True
1✔
26
    capabilities = ['shell', 'cp', 'copy', 'xcopy']
1✔
27
    required_parameters = ['image_path', 'destination_disk']
1✔
28

29
    def __init__(self):
1✔
30
        """ ctor
31
        """
32
        HostTestPluginBase.__init__(self)
1✔
33

34
    def setup(self, *args, **kwargs):
1✔
35
        """ Configure plugin, this function should be called before plugin execute() method is used.
36
        """
37
        return True
1✔
38

39
    def execute(self, capability, *args, **kwargs):
1✔
40
        """! Executes capability by name
41

42
        @param capability Capability name
43
        @param args Additional arguments
44
        @param kwargs Additional arguments
45
        @details Each capability e.g. may directly just call some command line program or execute building pythonic function
46
        @return Capability call return value
47
        """
UNCOV
48
        if not kwargs['image_path']:
×
49
            self.print_plugin_error("Error: image path not specified")
×
50
            return False
×
51

UNCOV
52
        if not kwargs['destination_disk']:
×
53
            self.print_plugin_error("Error: destination disk not specified")
×
54
            return False
×
55

56
        # This optional parameter can be used if TargetID is provided (-t switch)
UNCOV
57
        target_id = kwargs.get('target_id', None)
×
UNCOV
58
        pooling_timeout = kwargs.get('polling_timeout', 60)
×
59

UNCOV
60
        result = False
×
UNCOV
61
        if self.check_parameters(capability, *args, **kwargs):
×
UNCOV
62
            if kwargs['image_path'] and kwargs['destination_disk']:
×
UNCOV
63
                image_path = os.path.normpath(kwargs['image_path'])
×
UNCOV
64
                destination_disk = os.path.normpath(kwargs['destination_disk'])
×
65
                # Wait for mount point to be ready
66
                # if mount point changed according to target_id use new mount point
67
                # available in result (_, destination_disk) of check_mount_point_ready
UNCOV
68
                mount_res, destination_disk = self.check_mount_point_ready(destination_disk, target_id=target_id, timeout=pooling_timeout)  # Blocking
×
UNCOV
69
                if not mount_res:
×
70
                    return result # mount point is not ready return
×
71
                # Prepare correct command line parameter values
UNCOV
72
                image_base_name = basename(image_path)
×
UNCOV
73
                destination_path = join(destination_disk, image_base_name)
×
UNCOV
74
                if capability == 'shell':
×
UNCOV
75
                    if os.name == 'nt': capability = 'copy'
×
UNCOV
76
                    elif os.name == 'posix': capability = 'cp'
×
UNCOV
77
                if capability == 'cp' or capability == 'copy' or capability == 'copy':
×
UNCOV
78
                    copy_method = capability
×
UNCOV
79
                    cmd = [copy_method, image_path, destination_path]
×
UNCOV
80
                    if os.name == 'posix':
×
UNCOV
81
                        result = self.run_command(cmd, shell=False)
×
UNCOV
82
                        if os.uname()[0] == 'Linux':
×
UNCOV
83
                            result = result and self.run_command(["sync", "-f", destination_path])
×
84
                        else:
UNCOV
85
                            result = result and self.run_command(["sync"])
×
86
                    else:
UNCOV
87
                        result = self.run_command(cmd)
×
UNCOV
88
        return result
×
89

90

91
def load_plugin():
1✔
92
    """ Returns plugin available in this module
93
    """
94
    return HostTestPluginCopyMethod_Shell()
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