Mbed Host Tests
module_copy_mps2.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2011-2018 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
20import os
21from shutil import copy
22from .host_test_plugins import HostTestPluginBase
23
24
25class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
26 # MPS2 specific flashing / binary setup funcitons
27
28 name = 'HostTestPluginCopyMethod_MPS2'
29 type = 'CopyMethod'
30 stable = True
31 capabilities = ['mps2']
32 required_parameters = ['image_path', 'destination_disk']
33
34 def __init__(self):
35 """ ctor
36 """
37 HostTestPluginBase.__init__(self)
38
39 def mps2_copy(self, image_path, destination_disk):
40 """! mps2 copy method for "mbed enabled" devices.
41 This copies the file on the MPS2 keeping the same extension but
42 renaming it "mbed.extension"
43 @param image_path Path to file to be copied
44 @param destination_disk Path to destination (mbed mount point)
45
46 @details this uses shutil copy to copy the file.
47
48 @return Returns True if copy (flashing) was successful
49 """
50 result = True
51 # Keep the same extension in the test spec and on the MPS2
52 _, extension = os.path.splitext(image_path);
53 destination_path = os.path.join(destination_disk, "mbed" + extension)
54 try:
55 copy(image_path, destination_path)
56 # sync command on mac ignores command line arguments.
57 if os.name == 'posix':
58 result = self.run_command('sync -f %s' % destination_path, shell=True)
59 except Exception as e:
60 self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_path))
61 self.print_plugin_error("Error: %s"% str(e))
62 result = False
63
64 return result
65
66 def setup(self, *args, **kwargs):
67 """ Configure plugin, this function should be called before plugin execute() method is used.
68 """
69 return True
70
71 def execute(self, capability, *args, **kwargs):
72 """! Executes capability by name.
73 @details Each capability may directly just call some command line program or execute building pythonic function
74 @return Returns True if 'capability' operation was successful
75 """
76
77
78 if not kwargs['image_path']:
79 self.print_plugin_error("Error: image path not specified")
80 return False
81
82 if not kwargs['destination_disk']:
83 self.print_plugin_error("Error: destination disk not specified")
84 return False
85
86 # This optional parameter can be used if TargetID is provided (-t switch)
87 target_id = kwargs.get('target_id', None)
88 pooling_timeout = kwargs.get('polling_timeout', 60)
89 result = False
90
91 if self.check_parameters(capability, *args, **kwargs):
92 # Capability 'default' is a dummy capability
93 if kwargs['image_path'] and kwargs['destination_disk']:
94 if capability == 'mps2':
95 image_path = os.path.normpath(kwargs['image_path'])
96 destination_disk = os.path.normpath(kwargs['destination_disk'])
97 # Wait for mount point to be ready
98 # if mount point changed according to target_id use new mount point
99 # available in result (_, destination_disk) of check_mount_point_ready
100 result, destination_disk = self.check_mount_point_ready(destination_disk, target_id=target_id, timeout=pooling_timeout) # Blocking
101 if result:
102 result = self.mps2_copy(image_path, destination_disk)
103 return result
104
105
107 """ Returns plugin available in this module
108 """
def run_command(self, cmd, shell=True)
Runs command from command line.
def check_mount_point_ready(self, destination_disk, init_delay=0.2, loop_delay=0.25, target_id=None, timeout=60)
Waits until destination_disk is ready and can be accessed by e.g.
def print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
def check_parameters(self, capability, *args, **kwargs)
This function should be ran each time we call execute() to check if none of the required parameters i...
def mps2_copy(self, image_path, destination_disk)
mps2 copy method for "mbed enabled" devices.
def execute(self, capability, *args, **kwargs)
Executes capability by name.