def __init__(self): self.mbeds = None try: from mbed_lstools.main import create self.mbeds = create() except ImportError: raise AllocationError("mbedls is missing")
def check_serial_port_ready(self, serial_port, target_id=None, timeout=60): """Check and update serial port name information for DUT. If no target_id is specified return the old serial port name. Args: serial_port: Current serial port name. target_id: Target ID of a device under test. timeout: Serial port pooling timeout in seconds. Returns: Tuple with result (always True) and serial port read from mbed-ls. """ # If serial port changed (check using mbed-ls), use new serial port new_serial_port = None if target_id: # Sometimes OSes take a long time to mount devices (up to one minute). # Current pooling time: 120x 500ms = 1 minute self.print_plugin_info( "Waiting up to %d sec for '%s' serial port (current is '%s')..." % (timeout, target_id, serial_port) ) timeout_step = 0.5 timeout = int(timeout / timeout_step) for i in range(timeout): # mbed_lstools.main.create() should be done inside the loop. Otherwise # it will loop on same data. mbeds = create() mbed_list = mbeds.list_mbeds() # list of mbeds present # get first item in list with a matching target_id, if present mbed_target = next( (x for x in mbed_list if x["target_id"] == target_id), None ) if mbed_target is not None: # Only assign if serial port is present and known (not None) if ( "serial_port" in mbed_target and mbed_target["serial_port"] is not None ): new_serial_port = mbed_target["serial_port"] if new_serial_port != serial_port: # Serial port changed, update to new serial port self.print_plugin_info( "Serial port for tid='%s' changed from '%s' to '%s'..." % (target_id, serial_port, new_serial_port) ) break sleep(timeout_step) else: new_serial_port = serial_port return new_serial_port
def setUp(self): self.mbeds = create()
def test_porting_create(self): self.assertNotEqual(None, create())
def check_flash_error(target_id, disk, initial_remount_count): """Check for flash errors. Returns: False if FAIL.TXT present, else True. """ if not target_id: self.logger.prn_wrn( "Target ID not found: Skipping flash check and retry" ) return True bad_files = set(["FAIL.TXT"]) # Re-try at max 5 times with 0.5 sec in delay for i in range(5): # mbed_lstools.main.create() should be done inside the loop. Otherwise # it will loop on same data. mbeds = create() mbed_list = mbeds.list_mbeds() # list of mbeds present # get first item in list with a matching target_id, if present mbed_target = next( (x for x in mbed_list if x["target_id"] == target_id), None ) if mbed_target is not None: if ( "mount_point" in mbed_target and mbed_target["mount_point"] is not None ): if initial_remount_count is not None: new_remount_count = get_remount_count(disk) if ( new_remount_count is not None and new_remount_count == initial_remount_count ): sleep(0.5) continue common_items = [] try: items = set( [ x.upper() for x in os.listdir(mbed_target["mount_point"]) ] ) common_items = bad_files.intersection(items) except OSError: print("Failed to enumerate disk files, retrying") continue for common_item in common_items: full_path = os.path.join( mbed_target["mount_point"], common_item ) self.logger.prn_err("Found %s" % (full_path)) bad_file_contents = "[failed to read bad file]" try: with open(full_path, "r") as bad_file: bad_file_contents = bad_file.read() except IOError as error: self.logger.prn_err( "Error opening '%s': %s" % (full_path, error) ) self.logger.prn_err( "Error file contents:\n%s" % bad_file_contents ) if common_items: return False sleep(0.5) return True
def check_mount_point_ready( self, destination_disk, init_delay=0.2, loop_delay=0.25, target_id=None, timeout=60, ): """Wait until destination_disk is ready and can be accessed. Args: destination_disk: Mount point (disk) which will be checked for readiness. init_delay: Initial delay time before first access check. loop_delay: Polling delay for access check. timeout: Polling timeout in seconds. Returns: True if mount point was ready in given time, otherwise False. """ if target_id: # Wait for mount point to appear with mbed-ls # and if it does check if mount point for target_id changed # If mount point changed, use new mount point and check if its ready. new_destination_disk = destination_disk # Sometimes OSes take a long time to mount devices (up to one minute). # Current pooling time: 120x 500ms = 1 minute self.print_plugin_info( "Waiting up to %d sec for '%s' mount point (current is '%s')..." % (timeout, target_id, destination_disk) ) timeout_step = 0.5 timeout = int(timeout / timeout_step) for i in range(timeout): # mbed_lstools.main.create() should be done inside the loop. # Otherwise it will loop on same data. mbeds = create() mbed_list = mbeds.list_mbeds() # list of mbeds present # get first item in list with a matching target_id, if present mbed_target = next( (x for x in mbed_list if x["target_id"] == target_id), None ) if mbed_target is not None: # Only assign if mount point is present and known (not None) if ( "mount_point" in mbed_target and mbed_target["mount_point"] is not None ): new_destination_disk = mbed_target["mount_point"] break sleep(timeout_step) if new_destination_disk != destination_disk: # Mount point changed, update to new mount point from mbed-ls self.print_plugin_info( "Mount point for '%s' changed from '%s' to '%s'..." % (target_id, destination_disk, new_destination_disk) ) destination_disk = new_destination_disk result = True # Check if mount point we've promoted to be valid one (by optional target_id # check above) # Let's wait for 30 * loop_delay + init_delay max if not access(destination_disk, F_OK): self.print_plugin_info( "Waiting for mount point '%s' to be ready..." % destination_disk, NL=False, ) sleep(init_delay) for i in range(30): if access(destination_disk, F_OK): result = True break sleep(loop_delay) self.print_plugin_char(".") else: self.print_plugin_error( "mount {} is not accessible ...".format(destination_disk) ) result = False return (result, destination_disk)