mirror of https://github.com/ARMmbed/mbed-os.git
Host test copy functionality migration: copy functionality partially moved to host_test (tested with basic set of tests, not with e.g. NET tests.
Host test copy functionality: TODO: modify rest of host tests to use self.mbed.reset() and self.mbed.copy_image() according to curent test scipt APIpull/719/head
parent
16dbfa3f72
commit
4d8dfed27f
|
@ -25,6 +25,7 @@ except ImportError, e:
|
||||||
import os
|
import os
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
|
from os.path import exists
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import host_tests_plugins
|
import host_tests_plugins
|
||||||
|
@ -92,7 +93,7 @@ class Mbed:
|
||||||
# Options related to copy / reset mbed device
|
# Options related to copy / reset mbed device
|
||||||
self.port = self.options.port
|
self.port = self.options.port
|
||||||
self.disk = self.options.disk
|
self.disk = self.options.disk
|
||||||
self.image_path = self.options.image_path
|
self.image_path = self.options.image_path.strip('"')
|
||||||
self.copy_method = self.options.copy_method
|
self.copy_method = self.options.copy_method
|
||||||
|
|
||||||
self.serial = None
|
self.serial = None
|
||||||
|
@ -174,21 +175,29 @@ class Mbed:
|
||||||
# Flush serials to get only input after reset
|
# Flush serials to get only input after reset
|
||||||
self.flush()
|
self.flush()
|
||||||
if self.options.forced_reset_type:
|
if self.options.forced_reset_type:
|
||||||
host_tests_plugins.call_plugin('ResetMethod', self.options.forced_reset_type, disk=self.disk)
|
result = host_tests_plugins.call_plugin('ResetMethod', self.options.forced_reset_type, disk=self.disk)
|
||||||
else:
|
else:
|
||||||
host_tests_plugins.call_plugin('ResetMethod', 'default', serial=self.serial)
|
result = host_tests_plugins.call_plugin('ResetMethod', 'default', serial=self.serial)
|
||||||
# Give time to wait for the image loading
|
# Give time to wait for the image loading
|
||||||
reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
|
reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
|
||||||
self.reset_timeout(reset_tout_s)
|
self.reset_timeout(reset_tout_s)
|
||||||
|
return result
|
||||||
|
|
||||||
def copy_image(self, image_path=None, disk=None, copy_method=None):
|
def copy_image(self, image_path=None, disk=None, copy_method=None):
|
||||||
""" Copy file depending on method you want to use. Handles exception
|
""" Closure for copy_image_raw() method.
|
||||||
and return code from shell copy commands.
|
Method which is actually copying image to mbed
|
||||||
"""
|
"""
|
||||||
|
# Set closure environment
|
||||||
image_path = image_path if image_path is not None else self.image_path
|
image_path = image_path if image_path is not None else self.image_path
|
||||||
disk = disk if disk is not None else self.disk
|
disk = disk if disk is not None else self.disk
|
||||||
copy_method = copy_method if copy_method is not None else self.copy_method
|
copy_method = copy_method if copy_method is not None else self.copy_method
|
||||||
|
# Call proper copy method
|
||||||
|
return self.copy_image_raw(image_path, disk, copy_method)
|
||||||
|
|
||||||
|
def copy_image_raw(self, image_path=None, disk=None, copy_method=None):
|
||||||
|
""" Copy file depending on method you want to use. Handles exception
|
||||||
|
and return code from shell copy commands.
|
||||||
|
"""
|
||||||
if copy_method is not None:
|
if copy_method is not None:
|
||||||
# image_path - Where is binary with target's firmware
|
# image_path - Where is binary with target's firmware
|
||||||
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk)
|
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk)
|
||||||
|
@ -214,6 +223,7 @@ class TestResults:
|
||||||
self.RESULT_ERROR = 'error'
|
self.RESULT_ERROR = 'error'
|
||||||
self.RESULT_IO_SERIAL = 'ioerr_serial'
|
self.RESULT_IO_SERIAL = 'ioerr_serial'
|
||||||
self.RESULT_NO_IMAGE = 'no_image'
|
self.RESULT_NO_IMAGE = 'no_image'
|
||||||
|
self.RESULT_IOERR_COPY = "ioerr_copy"
|
||||||
|
|
||||||
|
|
||||||
class Test(TestResults):
|
class Test(TestResults):
|
||||||
|
@ -226,6 +236,19 @@ class Test(TestResults):
|
||||||
""" Test runner for host test. This function will start executing
|
""" Test runner for host test. This function will start executing
|
||||||
test and forward test result via serial port to test suite
|
test and forward test result via serial port to test suite
|
||||||
"""
|
"""
|
||||||
|
# Copy image to device
|
||||||
|
self.notify("HOST: Copy image onto target...")
|
||||||
|
result = self.mbed.copy_image()
|
||||||
|
if not result:
|
||||||
|
self.print_result(self.RESULT_IOERR_COPY)
|
||||||
|
|
||||||
|
# Reset device
|
||||||
|
self.notify("HOST: Reset target...")
|
||||||
|
result = self.mbed.reset()
|
||||||
|
if not result:
|
||||||
|
self.print_result(self.RESULT_IO_SERIAL)
|
||||||
|
|
||||||
|
# Run test
|
||||||
try:
|
try:
|
||||||
result = self.test()
|
result = self.test()
|
||||||
self.print_result(self.RESULT_SUCCESS if result else self.RESULT_FAILURE)
|
self.print_result(self.RESULT_SUCCESS if result else self.RESULT_FAILURE)
|
||||||
|
@ -234,7 +257,8 @@ class Test(TestResults):
|
||||||
self.print_result(self.RESULT_ERROR)
|
self.print_result(self.RESULT_ERROR)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
""" Setup and check if configuration for test is correct. E.g. if serial port can be opened
|
""" Setup and check if configuration for test is
|
||||||
|
correct. E.g. if serial port can be opened.
|
||||||
"""
|
"""
|
||||||
result = True
|
result = True
|
||||||
if not self.mbed.serial:
|
if not self.mbed.serial:
|
||||||
|
@ -263,7 +287,6 @@ class DefaultTest(Test):
|
||||||
serial_init_res = self.mbed.init_serial()
|
serial_init_res = self.mbed.init_serial()
|
||||||
if not serial_init_res:
|
if not serial_init_res:
|
||||||
self.print_result(self.RESULT_IO_SERIAL)
|
self.print_result(self.RESULT_IO_SERIAL)
|
||||||
self.mbed.reset()
|
|
||||||
|
|
||||||
|
|
||||||
class Simple(DefaultTest):
|
class Simple(DefaultTest):
|
||||||
|
@ -271,7 +294,7 @@ class Simple(DefaultTest):
|
||||||
output from MUT, no supervision over test running in MUT is executed.
|
output from MUT, no supervision over test running in MUT is executed.
|
||||||
Just waiting for result
|
Just waiting for result
|
||||||
"""
|
"""
|
||||||
def run(self):
|
def test(self):
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
c = self.mbed.serial_read(512)
|
c = self.mbed.serial_read(512)
|
||||||
|
|
|
@ -592,30 +592,6 @@ class SingleTestRunner(object):
|
||||||
result = self.TEST_LOOPS_DICT[test_id]
|
result = self.TEST_LOOPS_DICT[test_id]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def image_copy_method_selector(self, target_name, image_path, disk, copy_method,
|
|
||||||
images_config=None, image_dest=None, verbose=False):
|
|
||||||
""" Function copied image file and fiddles with image configuration files in needed.
|
|
||||||
This function will select proper image configuration (modify image config file
|
|
||||||
if needed) after image is copied.
|
|
||||||
"""
|
|
||||||
image_dest = image_dest if image_dest is not None else ''
|
|
||||||
_copy_res, _err_msg, _copy_method = self.file_copy_method_selector(image_path, disk, copy_method, image_dest=image_dest, verbose=verbose)
|
|
||||||
return _copy_res, _err_msg, _copy_method
|
|
||||||
|
|
||||||
def file_copy_method_selector(self, image_path, disk, copy_method, image_dest='', verbose=False):
|
|
||||||
""" Copy file depending on method you want to use. Handles exception
|
|
||||||
and return code from shell copy commands.
|
|
||||||
"""
|
|
||||||
result = False
|
|
||||||
resutl_msg = '' # TODO: pass result_msg from plugin to test suite
|
|
||||||
if copy_method is not None:
|
|
||||||
# image_path - Where is binary with target's firmware
|
|
||||||
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk)
|
|
||||||
else:
|
|
||||||
copy_method = 'default'
|
|
||||||
result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk)
|
|
||||||
return result, resutl_msg, copy_method
|
|
||||||
|
|
||||||
def delete_file(self, file_path):
|
def delete_file(self, file_path):
|
||||||
""" Remove file from the system
|
""" Remove file from the system
|
||||||
"""
|
"""
|
||||||
|
@ -684,7 +660,7 @@ class SingleTestRunner(object):
|
||||||
# Host test execution
|
# Host test execution
|
||||||
start_host_exec_time = time()
|
start_host_exec_time = time()
|
||||||
|
|
||||||
single_test_result = self.TEST_RESULT_UNDEF # singe test run result
|
single_test_result = self.TEST_RESULT_UNDEF # single test run result
|
||||||
_copy_method = selected_copy_method
|
_copy_method = selected_copy_method
|
||||||
|
|
||||||
if not exists(image_path):
|
if not exists(image_path):
|
||||||
|
@ -693,28 +669,19 @@ class SingleTestRunner(object):
|
||||||
single_test_output = self.logger.log_line(self.logger.LogType.ERROR, 'Image file does not exist: %s'% image_path)
|
single_test_output = self.logger.log_line(self.logger.LogType.ERROR, 'Image file does not exist: %s'% image_path)
|
||||||
print single_test_output
|
print single_test_output
|
||||||
else:
|
else:
|
||||||
# Choose one method of copy files to mbed MSD drive
|
sleep(target_by_mcu.program_cycle_s())
|
||||||
_copy_res, _err_msg, _copy_method = self.image_copy_method_selector(target_name, image_path, disk, selected_copy_method,
|
# Host test execution
|
||||||
images_config, image_dest)
|
start_host_exec_time = time()
|
||||||
|
|
||||||
if not _copy_res: # copy error to mbed MSD
|
host_test_verbose = self.opts_verbose_test_result_only or self.opts_verbose
|
||||||
single_test_result = self.TEST_RESULT_IOERR_COPY
|
host_test_reset = self.opts_mut_reset_type if reset_type is None else reset_type
|
||||||
single_test_output = self.logger.log_line(self.logger.LogType.ERROR, "Copy method '%s' failed. Reason: %s"% (_copy_method, _err_msg))
|
single_test_result, single_test_output = self.run_host_test(test.host_test,
|
||||||
print single_test_output
|
image_path, disk, port, duration,
|
||||||
else:
|
micro=target_name,
|
||||||
sleep(target_by_mcu.program_cycle_s())
|
verbose=host_test_verbose,
|
||||||
# Host test execution
|
reset=host_test_reset,
|
||||||
start_host_exec_time = time()
|
reset_tout=reset_tout,
|
||||||
|
copy_method=selected_copy_method)
|
||||||
host_test_verbose = self.opts_verbose_test_result_only or self.opts_verbose
|
|
||||||
host_test_reset = self.opts_mut_reset_type if reset_type is None else reset_type
|
|
||||||
single_test_result, single_test_output = self.run_host_test(test.host_test,
|
|
||||||
image_path, disk, port, duration,
|
|
||||||
micro=target_name,
|
|
||||||
verbose=host_test_verbose,
|
|
||||||
reset=host_test_reset,
|
|
||||||
reset_tout=reset_tout,
|
|
||||||
copy_method=selected_copy_method)
|
|
||||||
|
|
||||||
# Store test result
|
# Store test result
|
||||||
test_all_result.append(single_test_result)
|
test_all_result.append(single_test_result)
|
||||||
|
|
Loading…
Reference in New Issue