Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
0:66f3b5499f7f
Add a few normpath calls

Who changed what in which revision?

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