3 Copyright (c) 2011-2016 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
23 from time
import sleep
24 from mbed_host_tests
import DEFAULT_BAUD_RATE
30 """! Base class for a host driven test
31 @details This class stores information about things like disk, port, serial speed etc.
32 Class is also responsible for manipulation of serial port between host and mbed device
57 port_config = self.
portport.split(
':')
if self.
portport
else ''
58 if len(port_config) == 2:
60 self.
portport = port_config[0]
62 elif len(port_config) == 3:
64 self.
portport = port_config[0]
73 if self.
optionsoptions.json_test_configuration
is not None:
75 json_test_configuration_path = self.
optionsoptions.json_test_configuration.strip(
"\"'")
77 self.
loggerlogger.prn_inf(
"Loading test configuration from '%s'..." % json_test_configuration_path)
78 with open(json_test_configuration_path)
as data_file:
79 self.
test_cfgtest_cfg = json.load(data_file)
81 self.
loggerlogger.prn_err(
"Test configuration JSON file '{0}' I/O error({1}): {2}"
82 .format(json_test_configuration_path, e.errno, e.strerror))
84 self.
loggerlogger.prn_err(
"Test configuration JSON Unexpected error:", str(e))
87 def copy_image(self, image_path=None, disk=None, copy_method=None, port=None, retry_copy=5):
88 """! Closure for copy_image_raw() method.
89 @return Returns result from copy plugin
91 def get_remount_count(disk_path, tries=2):
92 """! Get the remount count from 'DETAILS.TXT' file
93 @return Returns count, None if not-available
95 for cur_try
in range(1, tries + 1):
97 files_on_disk = [x.upper()
for x
in os.listdir(disk_path)]
98 if 'DETAILS.TXT' in files_on_disk:
99 with open(os.path.join(disk_path,
'DETAILS.TXT'),
'r')
as details_txt:
100 for line
in details_txt.readlines():
101 if 'Remount count:' in line:
102 return int(line.replace(
'Remount count: ',
''))
110 self.
loggerlogger.prn_err(
"Failed to get remount count due to OSError.", str(e))
111 self.
loggerlogger.prn_inf(
"Retrying in 1 second (try %s of %s)" % (cur_try, tries))
116 def check_flash_error(target_id, disk, initial_remount_count):
117 """! Check for flash errors
118 @return Returns false if FAIL.TXT present, else true
121 self.
loggerlogger.prn_wrn(
"Target ID not found: Skipping flash check and retry")
124 bad_files = set([
'FAIL.TXT'])
128 mbeds = mbed_lstools.create()
129 mbed_list = mbeds.list_mbeds()
131 mbed_target = next((x
for x
in mbed_list
if x[
'target_id']==target_id),
None)
133 if mbed_target
is not None:
134 if 'mount_point' in mbed_target
and mbed_target[
'mount_point']
is not None:
135 if not initial_remount_count
is None:
136 new_remount_count = get_remount_count(disk)
137 if not new_remount_count
is None and new_remount_count == initial_remount_count:
143 items = set([x.upper()
for x
in os.listdir(mbed_target[
'mount_point'])])
144 common_items = bad_files.intersection(items)
146 print(
"Failed to enumerate disk files, retrying")
149 for common_item
in common_items:
150 full_path = os.path.join(mbed_target[
'mount_point'], common_item)
151 self.
loggerlogger.prn_err(
"Found %s"% (full_path))
152 bad_file_contents =
"[failed to read bad file]"
154 with open(full_path,
"r")
as bad_file:
155 bad_file_contents = bad_file.read()
156 except IOError
as error:
157 self.
loggerlogger.prn_err(
"Error opening '%s': %s" % (full_path, error))
159 self.
loggerlogger.prn_err(
"Error file contents:\n%s" % bad_file_contents)
179 self.
loggerlogger.prn_err(
"Error: image path not specified")
182 if not os.path.isfile(image_path):
183 self.
loggerlogger.prn_err(
"Error: image file (%s) not found" % image_path)
186 for count
in range(0, retry_copy):
187 initial_remount_count = get_remount_count(disk)
189 result = self.
copy_image_rawcopy_image_raw(image_path, disk, copy_method, port)
193 result = check_flash_error(target_id, disk, initial_remount_count)
198 def copy_image_raw(self, image_path=None, disk=None, copy_method=None, port=None):
199 """! Copy file depending on method you want to use. Handles exception
200 and return code from shell copy commands.
201 @return Returns result from copy plugin
202 @details Method which is actually copying image to mbed
211 }.get(copy_method, copy_method)
213 result = ht_plugins.call_plugin(
'CopyMethod',
215 image_path=image_path,
217 destination_disk=disk,
224 Performs hardware reset of target ned device.
229 result = ht_plugins.call_plugin(
'ResetMethod',
232 device_info=device_info)
234 self.
portport = device_info[
'serial_port']
235 self.
diskdisk = device_info[
'mount_point']
Yet another logger flavour.
Base class for a host driven test.
def copy_image(self, image_path=None, disk=None, copy_method=None, port=None, retry_copy=5)
Closure for copy_image_raw() method.
def copy_image_raw(self, image_path=None, disk=None, copy_method=None, port=None)
Copy file depending on method you want to use.
def __init__(self, options)