Skip to content

Commit 054d33a

Browse files
committed
Added handler to catch file copy exceptions. Both suprocess.call() and shutils.copy are handled. tested with shutil.copy, cp and xcopy. Note: xcopy is in interactive mode by defalt.
1 parent c159494 commit 054d33a

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

workspace_tools/singletest.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import optparse
7676
import pprint
7777
import re
78+
import os
7879
from types import ListType
7980
from prettytable import PrettyTable
8081

@@ -140,6 +141,9 @@ class SingleTestRunner(object):
140141
TEST_RESULT_FAIL = "FAIL"
141142
TEST_RESULT_ERROR = "ERROR"
142143
TEST_RESULT_UNDEF = "UNDEF"
144+
TEST_RESULT_IOERR_COPY = "IOERR_COPY"
145+
TEST_RESULT_IOERR_DISK = "IOERR_DISK"
146+
TEST_RESULT_TIMEOUT = "TIMEOUT"
143147

144148
# mbed test suite -> SingleTestRunner
145149
TEST_RESULT_MAPPING = {"success" : TEST_RESULT_OK,
@@ -170,12 +174,29 @@ def file_copy_method_selector(self, image_path, disk, copy_method):
170174
fdst.write(buf)
171175
IOError: [Errno 28] No space left on device
172176
"""
177+
result = True
178+
resutl_msg = ""
173179
if copy_method == "cp" or copy_method == "copy" or copy_method == "xcopy":
174-
cmd = [copy_method, image_path.encode('ascii', 'ignore'), disk.encode('ascii', 'ignore') + basename(image_path).encode('ascii', 'ignore')]
175-
call(cmd, shell=True)
180+
cmd = [copy_method,
181+
image_path.encode('ascii', 'ignore'),
182+
disk.encode('ascii', 'ignore') + basename(image_path).encode('ascii', 'ignore')]
183+
try:
184+
ret = call(cmd, shell=True)
185+
if ret:
186+
resutl_msg = "Return code: %d. Command: "% ret + " ".join(cmd)
187+
result = False
188+
except Exception, e:
189+
resutl_msg = e
190+
result = False
176191
else:
192+
copy_method = "shutils.copy()"
177193
# Default python method
178-
copy(image_path, disk)
194+
try:
195+
copy(image_path, disk)
196+
except Exception, e:
197+
resutl_msg = e
198+
result = False
199+
return result, resutl_msg, copy_method
179200

180201
def delete_file(file_path):
181202
""" Remove file from the system """
@@ -232,18 +253,25 @@ def handle(self, test_spec, target_name, toolchain_name):
232253
disk += '/'
233254

234255
# Choose one method of copy files to mbed virtual drive
235-
self.file_copy_method_selector(image_path, disk, opts.copy_method)
236-
237-
# Copy Extra Files
238-
if not target_by_mcu.is_disk_virtual and test.extra_files:
239-
for f in test.extra_files:
240-
copy(f, disk)
241-
242-
sleep(target_by_mcu.program_cycle_s())
256+
_copy_res, _err_msg, _copy_method = self.file_copy_method_selector(image_path, disk, opts.copy_method)
243257

244258
# Host test execution
245259
start_host_exec_time = time()
246-
test_result = self.run_host_test(test.host_test, disk, port, duration, opts.verbose)
260+
261+
if not _copy_res: # Serial port copy error
262+
test_result = "IOERR_COPY"
263+
print "Error: Copy method '%s'. %s"% (_copy_method, _err_msg)
264+
else:
265+
# Copy Extra Files
266+
if not target_by_mcu.is_disk_virtual and test.extra_files:
267+
for f in test.extra_files:
268+
copy(f, disk)
269+
270+
sleep(target_by_mcu.program_cycle_s())
271+
# Host test execution
272+
start_host_exec_time = time()
273+
test_result = self.run_host_test(test.host_test, disk, port, duration, opts.verbose)
274+
247275
elapsed_time = time() - start_host_exec_time
248276
print print_test_result(test_result, target_name, toolchain_name,
249277
test_id, test_description, elapsed_time, duration)
@@ -616,10 +644,15 @@ def generate_test_summary(test_summary):
616644
pt.align["Test Description"] = "l" # Left align
617645
pt.padding_width = 1 # One space between column edges and contents (default)
618646

619-
result_dict = { single_test.TEST_RESULT_OK : 0,
620-
single_test.TEST_RESULT_FAIL : 0,
621-
single_test.TEST_RESULT_ERROR : 0,
622-
single_test.TEST_RESULT_UNDEF : 0 }
647+
result_dict = {single_test.TEST_RESULT_OK : 0,
648+
single_test.TEST_RESULT_FAIL : 0,
649+
single_test.TEST_RESULT_ERROR : 0,
650+
single_test.TEST_RESULT_UNDEF : 0,
651+
single_test.TEST_RESULT_UNDEF : 0,
652+
single_test.TEST_RESULT_UNDEF : 0,
653+
single_test.TEST_RESULT_IOERR_COPY : 0,
654+
single_test.TEST_RESULT_IOERR_DISK : 0,
655+
single_test.TEST_RESULT_TIMEOUT : 0 }
623656

624657
for test in test_summary:
625658
if test[0] in result_dict:
@@ -794,6 +827,10 @@ def generate_test_summary(test_summary):
794827
for toolchain in toolchains:
795828
# print '=== %s::%s ===' % (target, toolchain)
796829
# Let's build our test
830+
if target not in TARGET_MAP:
831+
print 'Skipped tests for %s target. Target platform not found' % (target)
832+
continue
833+
797834
T = TARGET_MAP[target]
798835
build_mbed_libs_options = ["analyze"] if opts.goanna_for_mbed_sdk else None
799836
build_mbed_libs_result = build_mbed_libs(T, toolchain, options=build_mbed_libs_options)
@@ -827,6 +864,7 @@ def generate_test_summary(test_summary):
827864
print "TargetTest::%s::TestSkipped(%s)" % (target, ",".join(test_peripherals))
828865
continue
829866

867+
# This is basic structure storing test results
830868
test_result = {
831869
'target': target,
832870
'toolchain': toolchain,

0 commit comments

Comments
 (0)