Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:02dd72d1d465 1 """
borlanic 0:02dd72d1d465 2 mbed SDK
borlanic 0:02dd72d1d465 3 Copyright (c) 2011-2013 ARM Limited
borlanic 0:02dd72d1d465 4
borlanic 0:02dd72d1d465 5 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:02dd72d1d465 6 you may not use this file except in compliance with the License.
borlanic 0:02dd72d1d465 7 You may obtain a copy of the License at
borlanic 0:02dd72d1d465 8
borlanic 0:02dd72d1d465 9 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:02dd72d1d465 10
borlanic 0:02dd72d1d465 11 Unless required by applicable law or agreed to in writing, software
borlanic 0:02dd72d1d465 12 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:02dd72d1d465 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:02dd72d1d465 14 See the License for the specific language governing permissions and
borlanic 0:02dd72d1d465 15 limitations under the License.
borlanic 0:02dd72d1d465 16 """
borlanic 0:02dd72d1d465 17
borlanic 0:02dd72d1d465 18 # Check if 'serial' module is installed
borlanic 0:02dd72d1d465 19 try:
borlanic 0:02dd72d1d465 20 from serial import Serial
borlanic 0:02dd72d1d465 21 except ImportError, e:
borlanic 0:02dd72d1d465 22 print "Error: Can't import 'serial' module: %s"% e
borlanic 0:02dd72d1d465 23 exit(-1)
borlanic 0:02dd72d1d465 24
borlanic 0:02dd72d1d465 25 import os
borlanic 0:02dd72d1d465 26 import re
borlanic 0:02dd72d1d465 27 import types
borlanic 0:02dd72d1d465 28 from sys import stdout
borlanic 0:02dd72d1d465 29 from time import sleep, time
borlanic 0:02dd72d1d465 30 from optparse import OptionParser
borlanic 0:02dd72d1d465 31
borlanic 0:02dd72d1d465 32 import host_tests_plugins
borlanic 0:02dd72d1d465 33
borlanic 0:02dd72d1d465 34 # This is a little tricky. We need to add upper directory to path so
borlanic 0:02dd72d1d465 35 # we can find packages we want from the same level as other files do
borlanic 0:02dd72d1d465 36 import sys
borlanic 0:02dd72d1d465 37 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
borlanic 0:02dd72d1d465 38 from tools.test_api import get_autodetected_MUTS_list
borlanic 0:02dd72d1d465 39 from tools.test_api import get_module_avail
borlanic 0:02dd72d1d465 40
borlanic 0:02dd72d1d465 41
borlanic 0:02dd72d1d465 42 class Mbed:
borlanic 0:02dd72d1d465 43 """ Base class for a host driven test
borlanic 0:02dd72d1d465 44 """
borlanic 0:02dd72d1d465 45 def __init__(self):
borlanic 0:02dd72d1d465 46 parser = OptionParser()
borlanic 0:02dd72d1d465 47
borlanic 0:02dd72d1d465 48 parser.add_option("-m", "--micro",
borlanic 0:02dd72d1d465 49 dest="micro",
borlanic 0:02dd72d1d465 50 help="The target microcontroller",
borlanic 0:02dd72d1d465 51 metavar="MICRO")
borlanic 0:02dd72d1d465 52
borlanic 0:02dd72d1d465 53 parser.add_option("-p", "--port",
borlanic 0:02dd72d1d465 54 dest="port",
borlanic 0:02dd72d1d465 55 help="The serial port of the target mbed",
borlanic 0:02dd72d1d465 56 metavar="PORT")
borlanic 0:02dd72d1d465 57
borlanic 0:02dd72d1d465 58 parser.add_option("-d", "--disk",
borlanic 0:02dd72d1d465 59 dest="disk",
borlanic 0:02dd72d1d465 60 help="The target disk path",
borlanic 0:02dd72d1d465 61 metavar="DISK_PATH")
borlanic 0:02dd72d1d465 62
borlanic 0:02dd72d1d465 63 parser.add_option("-f", "--image-path",
borlanic 0:02dd72d1d465 64 dest="image_path",
borlanic 0:02dd72d1d465 65 help="Path with target's image",
borlanic 0:02dd72d1d465 66 metavar="IMAGE_PATH")
borlanic 0:02dd72d1d465 67
borlanic 0:02dd72d1d465 68 parser.add_option("-c", "--copy",
borlanic 0:02dd72d1d465 69 dest="copy_method",
borlanic 0:02dd72d1d465 70 help="Copy method selector",
borlanic 0:02dd72d1d465 71 metavar="COPY_METHOD")
borlanic 0:02dd72d1d465 72
borlanic 0:02dd72d1d465 73 parser.add_option("-C", "--program_cycle_s",
borlanic 0:02dd72d1d465 74 dest="program_cycle_s",
borlanic 0:02dd72d1d465 75 help="Program cycle sleep. Define how many seconds you want wait after copying bianry onto target",
borlanic 0:02dd72d1d465 76 type="float",
borlanic 0:02dd72d1d465 77 metavar="COPY_METHOD")
borlanic 0:02dd72d1d465 78
borlanic 0:02dd72d1d465 79 parser.add_option("-t", "--timeout",
borlanic 0:02dd72d1d465 80 dest="timeout",
borlanic 0:02dd72d1d465 81 help="Timeout",
borlanic 0:02dd72d1d465 82 metavar="TIMEOUT")
borlanic 0:02dd72d1d465 83
borlanic 0:02dd72d1d465 84 parser.add_option("-r", "--reset",
borlanic 0:02dd72d1d465 85 dest="forced_reset_type",
borlanic 0:02dd72d1d465 86 help="Forces different type of reset")
borlanic 0:02dd72d1d465 87
borlanic 0:02dd72d1d465 88 parser.add_option("-R", "--reset-timeout",
borlanic 0:02dd72d1d465 89 dest="forced_reset_timeout",
borlanic 0:02dd72d1d465 90 metavar="NUMBER",
borlanic 0:02dd72d1d465 91 type="int",
borlanic 0:02dd72d1d465 92 help="When forcing a reset using option -r you can set up after reset timeout in seconds")
borlanic 0:02dd72d1d465 93
borlanic 0:02dd72d1d465 94 parser.add_option('', '--auto',
borlanic 0:02dd72d1d465 95 dest='auto_detect',
borlanic 0:02dd72d1d465 96 metavar=False,
borlanic 0:02dd72d1d465 97 action="store_true",
borlanic 0:02dd72d1d465 98 help='Use mbed-ls module to detect all connected mbed devices')
borlanic 0:02dd72d1d465 99
borlanic 0:02dd72d1d465 100 (self.options, _) = parser.parse_args()
borlanic 0:02dd72d1d465 101
borlanic 0:02dd72d1d465 102 self.DEFAULT_RESET_TOUT = 0
borlanic 0:02dd72d1d465 103 self.DEFAULT_TOUT = 10
borlanic 0:02dd72d1d465 104
borlanic 0:02dd72d1d465 105 if self.options.port is None:
borlanic 0:02dd72d1d465 106 raise Exception("The serial port of the target mbed have to be provided as command line arguments")
borlanic 0:02dd72d1d465 107
borlanic 0:02dd72d1d465 108 # Options related to copy / reset mbed device
borlanic 0:02dd72d1d465 109 self.port = self.options.port
borlanic 0:02dd72d1d465 110 self.disk = self.options.disk
borlanic 0:02dd72d1d465 111 self.image_path = self.options.image_path.strip('"')
borlanic 0:02dd72d1d465 112 self.copy_method = self.options.copy_method
borlanic 0:02dd72d1d465 113 self.program_cycle_s = float(self.options.program_cycle_s)
borlanic 0:02dd72d1d465 114
borlanic 0:02dd72d1d465 115 self.serial = None
borlanic 0:02dd72d1d465 116 self.serial_baud = 9600
borlanic 0:02dd72d1d465 117 self.serial_timeout = 1
borlanic 0:02dd72d1d465 118
borlanic 0:02dd72d1d465 119 self.timeout = self.DEFAULT_TOUT if self.options.timeout is None else self.options.timeout
borlanic 0:02dd72d1d465 120 print 'MBED: Instrumentation: "%s" and disk: "%s"' % (self.port, self.disk)
borlanic 0:02dd72d1d465 121
borlanic 0:02dd72d1d465 122 def init_serial_params(self, serial_baud=9600, serial_timeout=1):
borlanic 0:02dd72d1d465 123 """ Initialize port parameters.
borlanic 0:02dd72d1d465 124 This parameters will be used by self.init_serial() function to open serial port
borlanic 0:02dd72d1d465 125 """
borlanic 0:02dd72d1d465 126 self.serial_baud = serial_baud
borlanic 0:02dd72d1d465 127 self.serial_timeout = serial_timeout
borlanic 0:02dd72d1d465 128
borlanic 0:02dd72d1d465 129 def init_serial(self, serial_baud=None, serial_timeout=None):
borlanic 0:02dd72d1d465 130 """ Initialize serial port.
borlanic 0:02dd72d1d465 131 Function will return error is port can't be opened or initialized
borlanic 0:02dd72d1d465 132 """
borlanic 0:02dd72d1d465 133 # Overload serial port configuration from default to parameters' values if they are specified
borlanic 0:02dd72d1d465 134 serial_baud = serial_baud if serial_baud is not None else self.serial_baud
borlanic 0:02dd72d1d465 135 serial_timeout = serial_timeout if serial_timeout is not None else self.serial_timeout
borlanic 0:02dd72d1d465 136
borlanic 0:02dd72d1d465 137 if get_module_avail('mbed_lstools') and self.options.auto_detect:
borlanic 0:02dd72d1d465 138 # Ensure serial port is up-to-date (try to find it 60 times)
borlanic 0:02dd72d1d465 139 found = False
borlanic 0:02dd72d1d465 140
borlanic 0:02dd72d1d465 141 for i in range(0, 60):
borlanic 0:02dd72d1d465 142 print('Looking for %s with MBEDLS' % self.options.micro)
borlanic 0:02dd72d1d465 143 muts_list = get_autodetected_MUTS_list(platform_name_filter=[self.options.micro])
borlanic 0:02dd72d1d465 144
borlanic 0:02dd72d1d465 145 if 1 in muts_list:
borlanic 0:02dd72d1d465 146 mut = muts_list[1]
borlanic 0:02dd72d1d465 147 self.port = mut['port']
borlanic 0:02dd72d1d465 148 found = True
borlanic 0:02dd72d1d465 149 break
borlanic 0:02dd72d1d465 150 else:
borlanic 0:02dd72d1d465 151 sleep(3)
borlanic 0:02dd72d1d465 152
borlanic 0:02dd72d1d465 153 if not found:
borlanic 0:02dd72d1d465 154 return False
borlanic 0:02dd72d1d465 155
borlanic 0:02dd72d1d465 156 # Clear serial port
borlanic 0:02dd72d1d465 157 if self.serial:
borlanic 0:02dd72d1d465 158 self.serial.close()
borlanic 0:02dd72d1d465 159 self.serial = None
borlanic 0:02dd72d1d465 160
borlanic 0:02dd72d1d465 161 # We will pool for serial to be re-mounted if it was unmounted after device reset
borlanic 0:02dd72d1d465 162 result = self.pool_for_serial_init(serial_baud, serial_timeout) # Blocking
borlanic 0:02dd72d1d465 163
borlanic 0:02dd72d1d465 164 # Port can be opened
borlanic 0:02dd72d1d465 165 if result:
borlanic 0:02dd72d1d465 166 self.flush()
borlanic 0:02dd72d1d465 167 return result
borlanic 0:02dd72d1d465 168
borlanic 0:02dd72d1d465 169 def pool_for_serial_init(self, serial_baud, serial_timeout, pooling_loops=40, init_delay=0.5, loop_delay=0.25):
borlanic 0:02dd72d1d465 170 """ Functions pools for serial port readiness
borlanic 0:02dd72d1d465 171 """
borlanic 0:02dd72d1d465 172 result = True
borlanic 0:02dd72d1d465 173 last_error = None
borlanic 0:02dd72d1d465 174 # This loop is used to check for serial port availability due to
borlanic 0:02dd72d1d465 175 # some delays and remounting when devices are being flashed with new software.
borlanic 0:02dd72d1d465 176 for i in range(pooling_loops):
borlanic 0:02dd72d1d465 177 sleep(loop_delay if i else init_delay)
borlanic 0:02dd72d1d465 178 try:
borlanic 0:02dd72d1d465 179 self.serial = Serial(self.port, baudrate=serial_baud, timeout=serial_timeout)
borlanic 0:02dd72d1d465 180 except Exception as e:
borlanic 0:02dd72d1d465 181 result = False
borlanic 0:02dd72d1d465 182 last_error = "MBED: %s"% str(e)
borlanic 0:02dd72d1d465 183 stdout.write('.')
borlanic 0:02dd72d1d465 184 stdout.flush()
borlanic 0:02dd72d1d465 185 else:
borlanic 0:02dd72d1d465 186 print "...port ready!"
borlanic 0:02dd72d1d465 187 result = True
borlanic 0:02dd72d1d465 188 break
borlanic 0:02dd72d1d465 189 if not result and last_error:
borlanic 0:02dd72d1d465 190 print last_error
borlanic 0:02dd72d1d465 191 return result
borlanic 0:02dd72d1d465 192
borlanic 0:02dd72d1d465 193 def set_serial_timeout(self, timeout):
borlanic 0:02dd72d1d465 194 """ Wraps self.mbed.serial object timeout property
borlanic 0:02dd72d1d465 195 """
borlanic 0:02dd72d1d465 196 result = None
borlanic 0:02dd72d1d465 197 if self.serial:
borlanic 0:02dd72d1d465 198 self.serial.timeout = timeout
borlanic 0:02dd72d1d465 199 result = True
borlanic 0:02dd72d1d465 200 return result
borlanic 0:02dd72d1d465 201
borlanic 0:02dd72d1d465 202 def serial_read(self, count=1):
borlanic 0:02dd72d1d465 203 """ Wraps self.mbed.serial object read method
borlanic 0:02dd72d1d465 204 """
borlanic 0:02dd72d1d465 205 result = None
borlanic 0:02dd72d1d465 206 if self.serial:
borlanic 0:02dd72d1d465 207 try:
borlanic 0:02dd72d1d465 208 result = self.serial.read(count)
borlanic 0:02dd72d1d465 209 except:
borlanic 0:02dd72d1d465 210 result = None
borlanic 0:02dd72d1d465 211 return result
borlanic 0:02dd72d1d465 212
borlanic 0:02dd72d1d465 213 def serial_readline(self, timeout=5):
borlanic 0:02dd72d1d465 214 """ Wraps self.mbed.serial object read method to read one line from serial port
borlanic 0:02dd72d1d465 215 """
borlanic 0:02dd72d1d465 216 result = ''
borlanic 0:02dd72d1d465 217 start = time()
borlanic 0:02dd72d1d465 218 while (time() - start) < timeout:
borlanic 0:02dd72d1d465 219 if self.serial:
borlanic 0:02dd72d1d465 220 try:
borlanic 0:02dd72d1d465 221 c = self.serial.read(1)
borlanic 0:02dd72d1d465 222 result += c
borlanic 0:02dd72d1d465 223 except Exception as e:
borlanic 0:02dd72d1d465 224 print "MBED: %s"% str(e)
borlanic 0:02dd72d1d465 225 result = None
borlanic 0:02dd72d1d465 226 break
borlanic 0:02dd72d1d465 227 if c == '\n':
borlanic 0:02dd72d1d465 228 break
borlanic 0:02dd72d1d465 229 return result
borlanic 0:02dd72d1d465 230
borlanic 0:02dd72d1d465 231 def serial_write(self, write_buffer):
borlanic 0:02dd72d1d465 232 """ Wraps self.mbed.serial object write method
borlanic 0:02dd72d1d465 233 """
borlanic 0:02dd72d1d465 234 result = None
borlanic 0:02dd72d1d465 235 if self.serial:
borlanic 0:02dd72d1d465 236 try:
borlanic 0:02dd72d1d465 237 result = self.serial.write(write_buffer)
borlanic 0:02dd72d1d465 238 except:
borlanic 0:02dd72d1d465 239 result = None
borlanic 0:02dd72d1d465 240 return result
borlanic 0:02dd72d1d465 241
borlanic 0:02dd72d1d465 242 def reset_timeout(self, timeout):
borlanic 0:02dd72d1d465 243 """ Timeout executed just after reset command is issued
borlanic 0:02dd72d1d465 244 """
borlanic 0:02dd72d1d465 245 for n in range(0, timeout):
borlanic 0:02dd72d1d465 246 sleep(1)
borlanic 0:02dd72d1d465 247
borlanic 0:02dd72d1d465 248 def reset(self):
borlanic 0:02dd72d1d465 249 """ Calls proper reset plugin to do the job.
borlanic 0:02dd72d1d465 250 Please refer to host_test_plugins functionality
borlanic 0:02dd72d1d465 251 """
borlanic 0:02dd72d1d465 252 # Flush serials to get only input after reset
borlanic 0:02dd72d1d465 253 self.flush()
borlanic 0:02dd72d1d465 254 if self.options.forced_reset_type:
borlanic 0:02dd72d1d465 255 result = host_tests_plugins.call_plugin('ResetMethod', self.options.forced_reset_type, disk=self.disk)
borlanic 0:02dd72d1d465 256 else:
borlanic 0:02dd72d1d465 257 result = host_tests_plugins.call_plugin('ResetMethod', 'default', serial=self.serial)
borlanic 0:02dd72d1d465 258 # Give time to wait for the image loading
borlanic 0:02dd72d1d465 259 reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
borlanic 0:02dd72d1d465 260 self.reset_timeout(reset_tout_s)
borlanic 0:02dd72d1d465 261 return result
borlanic 0:02dd72d1d465 262
borlanic 0:02dd72d1d465 263 def copy_image(self, image_path=None, disk=None, copy_method=None):
borlanic 0:02dd72d1d465 264 """ Closure for copy_image_raw() method.
borlanic 0:02dd72d1d465 265 Method which is actually copying image to mbed
borlanic 0:02dd72d1d465 266 """
borlanic 0:02dd72d1d465 267 # Set closure environment
borlanic 0:02dd72d1d465 268 image_path = image_path if image_path is not None else self.image_path
borlanic 0:02dd72d1d465 269 disk = disk if disk is not None else self.disk
borlanic 0:02dd72d1d465 270 copy_method = copy_method if copy_method is not None else self.copy_method
borlanic 0:02dd72d1d465 271 # Call proper copy method
borlanic 0:02dd72d1d465 272 result = self.copy_image_raw(image_path, disk, copy_method)
borlanic 0:02dd72d1d465 273 return result
borlanic 0:02dd72d1d465 274
borlanic 0:02dd72d1d465 275 def copy_image_raw(self, image_path=None, disk=None, copy_method=None):
borlanic 0:02dd72d1d465 276 """ Copy file depending on method you want to use. Handles exception
borlanic 0:02dd72d1d465 277 and return code from shell copy commands.
borlanic 0:02dd72d1d465 278 """
borlanic 0:02dd72d1d465 279 # image_path - Where is binary with target's firmware
borlanic 0:02dd72d1d465 280 if copy_method is not None:
borlanic 0:02dd72d1d465 281 # We override 'default' method with 'shell' method
borlanic 0:02dd72d1d465 282 if copy_method == 'default':
borlanic 0:02dd72d1d465 283 copy_method = 'shell'
borlanic 0:02dd72d1d465 284 else:
borlanic 0:02dd72d1d465 285 copy_method = 'shell'
borlanic 0:02dd72d1d465 286
borlanic 0:02dd72d1d465 287 result = host_tests_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk, program_cycle_s=self.program_cycle_s, target_mcu=self.options.micro)
borlanic 0:02dd72d1d465 288 return result;
borlanic 0:02dd72d1d465 289
borlanic 0:02dd72d1d465 290 def flush(self):
borlanic 0:02dd72d1d465 291 """ Flush serial ports
borlanic 0:02dd72d1d465 292 """
borlanic 0:02dd72d1d465 293 result = False
borlanic 0:02dd72d1d465 294 if self.serial:
borlanic 0:02dd72d1d465 295 self.serial.flushInput()
borlanic 0:02dd72d1d465 296 self.serial.flushOutput()
borlanic 0:02dd72d1d465 297 result = True
borlanic 0:02dd72d1d465 298 return result
borlanic 0:02dd72d1d465 299
borlanic 0:02dd72d1d465 300
borlanic 0:02dd72d1d465 301 class HostTestResults:
borlanic 0:02dd72d1d465 302 """ Test results set by host tests
borlanic 0:02dd72d1d465 303 """
borlanic 0:02dd72d1d465 304 def __init__(self):
borlanic 0:02dd72d1d465 305 self.RESULT_SUCCESS = 'success'
borlanic 0:02dd72d1d465 306 self.RESULT_FAILURE = 'failure'
borlanic 0:02dd72d1d465 307 self.RESULT_ERROR = 'error'
borlanic 0:02dd72d1d465 308 self.RESULT_IO_SERIAL = 'ioerr_serial'
borlanic 0:02dd72d1d465 309 self.RESULT_NO_IMAGE = 'no_image'
borlanic 0:02dd72d1d465 310 self.RESULT_IOERR_COPY = "ioerr_copy"
borlanic 0:02dd72d1d465 311 self.RESULT_PASSIVE = "passive"
borlanic 0:02dd72d1d465 312 self.RESULT_NOT_DETECTED = "not_detected"
borlanic 0:02dd72d1d465 313 self.RESULT_MBED_ASSERT = "mbed_assert"
borlanic 0:02dd72d1d465 314
borlanic 0:02dd72d1d465 315
borlanic 0:02dd72d1d465 316 import tools.host_tests as host_tests
borlanic 0:02dd72d1d465 317
borlanic 0:02dd72d1d465 318
borlanic 0:02dd72d1d465 319 class Test(HostTestResults):
borlanic 0:02dd72d1d465 320 """ Base class for host test's test runner
borlanic 0:02dd72d1d465 321 """
borlanic 0:02dd72d1d465 322 # Select default host_test supervision (replaced after autodetection)
borlanic 0:02dd72d1d465 323 test_supervisor = host_tests.get_host_test("default")
borlanic 0:02dd72d1d465 324
borlanic 0:02dd72d1d465 325 def __init__(self):
borlanic 0:02dd72d1d465 326 self.mbed = Mbed()
borlanic 0:02dd72d1d465 327
borlanic 0:02dd72d1d465 328 def detect_test_config(self, verbose=False):
borlanic 0:02dd72d1d465 329 """ Detects test case configuration
borlanic 0:02dd72d1d465 330 """
borlanic 0:02dd72d1d465 331 result = {}
borlanic 0:02dd72d1d465 332 while True:
borlanic 0:02dd72d1d465 333 line = self.mbed.serial_readline()
borlanic 0:02dd72d1d465 334 if "{start}" in line:
borlanic 0:02dd72d1d465 335 self.notify("HOST: Start test...")
borlanic 0:02dd72d1d465 336 break
borlanic 0:02dd72d1d465 337 else:
borlanic 0:02dd72d1d465 338 # Detect if this is property from TEST_ENV print
borlanic 0:02dd72d1d465 339 m = re.search('{([\w_]+);([\w\d\+ ]+)}}', line[:-1])
borlanic 0:02dd72d1d465 340 if m and len(m.groups()) == 2:
borlanic 0:02dd72d1d465 341 # This is most likely auto-detection property
borlanic 0:02dd72d1d465 342 result[m.group(1)] = m.group(2)
borlanic 0:02dd72d1d465 343 if verbose:
borlanic 0:02dd72d1d465 344 self.notify("HOST: Property '%s' = '%s'"% (m.group(1), m.group(2)))
borlanic 0:02dd72d1d465 345 else:
borlanic 0:02dd72d1d465 346 # We can check if this is TArget Id in mbed specific format
borlanic 0:02dd72d1d465 347 m2 = re.search('^([\$]+)([a-fA-F0-9]+)', line[:-1])
borlanic 0:02dd72d1d465 348 if m2 and len(m2.groups()) == 2:
borlanic 0:02dd72d1d465 349 if verbose:
borlanic 0:02dd72d1d465 350 target_id = m2.group(1) + m2.group(2)
borlanic 0:02dd72d1d465 351 self.notify("HOST: TargetID '%s'"% target_id)
borlanic 0:02dd72d1d465 352 self.notify(line[len(target_id):-1])
borlanic 0:02dd72d1d465 353 else:
borlanic 0:02dd72d1d465 354 self.notify("HOST: Unknown property: %s"% line.strip())
borlanic 0:02dd72d1d465 355 return result
borlanic 0:02dd72d1d465 356
borlanic 0:02dd72d1d465 357 def run(self):
borlanic 0:02dd72d1d465 358 """ Test runner for host test. This function will start executing
borlanic 0:02dd72d1d465 359 test and forward test result via serial port to test suite
borlanic 0:02dd72d1d465 360 """
borlanic 0:02dd72d1d465 361 # Copy image to device
borlanic 0:02dd72d1d465 362 self.notify("HOST: Copy image onto target...")
borlanic 0:02dd72d1d465 363 result = self.mbed.copy_image()
borlanic 0:02dd72d1d465 364 if not result:
borlanic 0:02dd72d1d465 365 self.print_result(self.RESULT_IOERR_COPY)
borlanic 0:02dd72d1d465 366
borlanic 0:02dd72d1d465 367 # Initialize and open target's serial port (console)
borlanic 0:02dd72d1d465 368 self.notify("HOST: Initialize serial port...")
borlanic 0:02dd72d1d465 369 result = self.mbed.init_serial()
borlanic 0:02dd72d1d465 370 if not result:
borlanic 0:02dd72d1d465 371 self.print_result(self.RESULT_IO_SERIAL)
borlanic 0:02dd72d1d465 372
borlanic 0:02dd72d1d465 373 # Reset device
borlanic 0:02dd72d1d465 374 self.notify("HOST: Reset target...")
borlanic 0:02dd72d1d465 375 result = self.mbed.reset()
borlanic 0:02dd72d1d465 376 if not result:
borlanic 0:02dd72d1d465 377 self.print_result(self.RESULT_IO_SERIAL)
borlanic 0:02dd72d1d465 378
borlanic 0:02dd72d1d465 379 # Run test
borlanic 0:02dd72d1d465 380 try:
borlanic 0:02dd72d1d465 381 CONFIG = self.detect_test_config(verbose=True) # print CONFIG
borlanic 0:02dd72d1d465 382
borlanic 0:02dd72d1d465 383 if "host_test_name" in CONFIG:
borlanic 0:02dd72d1d465 384 if host_tests.is_host_test(CONFIG["host_test_name"]):
borlanic 0:02dd72d1d465 385 self.test_supervisor = host_tests.get_host_test(CONFIG["host_test_name"])
borlanic 0:02dd72d1d465 386 result = self.test_supervisor.test(self) #result = self.test()
borlanic 0:02dd72d1d465 387
borlanic 0:02dd72d1d465 388 if result is not None:
borlanic 0:02dd72d1d465 389 self.print_result(result)
borlanic 0:02dd72d1d465 390 else:
borlanic 0:02dd72d1d465 391 self.notify("HOST: Passive mode...")
borlanic 0:02dd72d1d465 392 except Exception, e:
borlanic 0:02dd72d1d465 393 print str(e)
borlanic 0:02dd72d1d465 394 self.print_result(self.RESULT_ERROR)
borlanic 0:02dd72d1d465 395
borlanic 0:02dd72d1d465 396 def setup(self):
borlanic 0:02dd72d1d465 397 """ Setup and check if configuration for test is
borlanic 0:02dd72d1d465 398 correct. E.g. if serial port can be opened.
borlanic 0:02dd72d1d465 399 """
borlanic 0:02dd72d1d465 400 result = True
borlanic 0:02dd72d1d465 401 if not self.mbed.serial:
borlanic 0:02dd72d1d465 402 result = False
borlanic 0:02dd72d1d465 403 self.print_result(self.RESULT_IO_SERIAL)
borlanic 0:02dd72d1d465 404 return result
borlanic 0:02dd72d1d465 405
borlanic 0:02dd72d1d465 406 def notify(self, message):
borlanic 0:02dd72d1d465 407 """ On screen notification function
borlanic 0:02dd72d1d465 408 """
borlanic 0:02dd72d1d465 409 print message
borlanic 0:02dd72d1d465 410 stdout.flush()
borlanic 0:02dd72d1d465 411
borlanic 0:02dd72d1d465 412 def print_result(self, result):
borlanic 0:02dd72d1d465 413 """ Test result unified printing function
borlanic 0:02dd72d1d465 414 """
borlanic 0:02dd72d1d465 415 self.notify("\r\n{{%s}}\r\n{{end}}" % result)
borlanic 0:02dd72d1d465 416
borlanic 0:02dd72d1d465 417
borlanic 0:02dd72d1d465 418 class DefaultTestSelector(Test):
borlanic 0:02dd72d1d465 419 """ Test class with serial port initialization
borlanic 0:02dd72d1d465 420 """
borlanic 0:02dd72d1d465 421 def __init__(self):
borlanic 0:02dd72d1d465 422 HostTestResults.__init__(self)
borlanic 0:02dd72d1d465 423 Test.__init__(self)
borlanic 0:02dd72d1d465 424
borlanic 0:02dd72d1d465 425 if __name__ == '__main__':
borlanic 0:02dd72d1d465 426 DefaultTestSelector().run()