def test_reset_with_wrong_target_id(self, mock_stdout, mock_sleep): resetter = Reset() with self.assertRaises(GeneralFatalError) as cm: resetter.reset(target_id='555', method='simple') self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_DEVICE)
def test_reset_with_all_no_devices(self, mock_stdout): resetter = Reset() ret = resetter.reset(target_id='all', method='simple') self.assertEqual(ret, 3) if mock_stdout: self.assertEqual( mock_stdout.getvalue(), 'Could not map given target_id(s) to available devices\n')
def test_reset_with_wrong_target_id(self, mock_stdout): resetter = Reset() with self.assertRaises(ResetError) as cm: resetter.reset(target_id='555', method='simple') self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_TARGET_ID_TO_DEVICE) self.assertEqual( mock_stdout.getvalue(), 'Could not map given target_id(s) to available devices\n')
def test_reset_with_target_id_list(self): mbeds = mbed_lstools.create() devices = mbeds.list_mbeds() resetter = Reset() ret = None for item in devices: if item['target_id']: ret = resetter.reset(target_id=[item['target_id']], method='simple') break self.assertEqual(ret, 0)
def subcmd_reset_handler(self, args): """ reset command handler """ resetter = Reset() if not args.tid: msg = "Target_id is missing" raise ResetError(message=msg, return_code=EXIT_CODE_TARGET_ID_MISSING) ids = self.parse_id_to_devices(args.tid) return resetter.reset(target_id=ids, method=args.method)
def test_verify_hw_flash_no_reset(self): mbeds = mbed_lstools.create() targets = mbeds.list_mbeds() flasher = Flash() resetter = Reset() target_id = None serial_port = None for target in targets: if target['platform_name'] == 'K64F': if 'serial_port' and 'target_id' in target: target_id = target['target_id'] serial_port = target['serial_port'] break if target_id and serial_port: second_binary = find_second_binary() self.assertIsNotNone(second_binary, 'Second binary not found') ret = flasher.flash(build=second_binary, target_id=target_id, platform_name='K64F', device_mapping_table=False, method='simple') self.assertEqual(ret, 0) if not verify_output_per_device(serial_port, 'help', 'echo'): self.assertEqual( verify_output_per_device(serial_port, 'help', 'echo'), True) ret = flasher.flash(build=second_binary, target_id=target_id, platform_name='K64F', device_mapping_table=False, method='simple', no_reset=True) self.assertEqual(ret, 0) self.assertEqual( verify_output_per_device(serial_port, 'help', 'echo'), False) ret = resetter.reset(target_id=target_id, method='simple') self.assertEqual(ret, 0) if not verify_output_per_device(serial_port, 'help', 'echo'): self.assertEqual( verify_output_per_device(serial_port, 'help', 'echo'), True) ret = flasher.flash(build=self.bin_path, target_id=target_id, platform_name='K64F', device_mapping_table=False, method='simple') self.assertEqual(ret, 0) self.assertEqual( verify_output_per_device(serial_port, 'help', 'echo'), False)
def _erase_board_simple(self, target, no_reset): """ :param target: target to which perform the erase :param no_reset: erase with/without reset :return: exit code """ if "mount_point" not in target: raise EraseError(message="mount point missing from target", return_code=EXIT_CODE_MOUNT_POINT_MISSING) if "serial_port" not in target: raise EraseError(message="serial port missing from target", return_code=EXIT_CODE_SERIAL_PORT_MISSING) Erase._can_be_erased(target) # Copy ERASE.ACT to target mount point, this will trigger the erasing. destination = MbedCommon.get_binary_destination(target["mount_point"], "ERASE.ACT") with open(destination, "wb"): pass target = MbedCommon.wait_for_file_disappear(target, "ERASE.ACT") if not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) self._verify_erase_success(MbedCommon.get_binary_destination( target["mount_point"], "ERASE.ACT")) self.logger.info("erase %s completed", target["target_id"]) return EXIT_CODE_SUCCESS
def subcmd_reset_handler(self, args): """ reset command handler """ resetter = Reset() if args.tid: ids = self.parse_id_to_devices(args.tid) if isinstance(ids, int): retcode = ids else: retcode = resetter.reset(target_id=ids, method=args.method) else: print("Target_id is missing") return EXIT_CODE_NO_TARGET_ID return retcode
def subcmd_reset_handler(self, args): """ reset command handler """ resetter = Reset() if args.tid: ids = self.parse_id_to_devices(args.tid) if isinstance(ids, int): retcode = ids else: retcode = resetter.reset(target_id=ids, method=args.method) else: msg = "Target_id is missing" print(msg) raise ResetError(message=msg, return_code=EXIT_CODE_TARGET_ID_MISSING) return retcode
def test_reset_with_all_no_devices(self, mock_stdout, mock_mbed_lstools_create): # pylint:disable=too-few-public-methods class MockLS(object): def __init__(self): pass # pylint:disable=no-self-use def list_mbeds(self, filter_function=None): return [] mock_mbed_lstools_create.return_value = MockLS() resetter = Reset() with self.assertRaises(ResetError) as cm: resetter.reset(target_id='all', method='simple') self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_TARGET_ID_TO_DEVICE)
def try_drag_and_drop_flash(self, source, target, target_filename, no_reset): """ Try to flash the target using drag and drop method. :param source: file to be flashed :param target: target board to be flashed :param no_reset: whether to reset the board after flash :return: 0 if success """ target = MbedCommon.refresh_target(target["target_id"]) if not target: raise FlashError(message="Target ID is missing", return_code=EXIT_CODE_TARGET_ID_MISSING) destination = MbedCommon.get_binary_destination( target["mount_point"], target_filename) try: if 'serial_port' in target and not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) sleep(0.1) self.copy_file(source, destination) self.logger.debug("copy finished") target = MbedCommon.wait_for_file_disappear( target, target_filename) if not no_reset: Reset(logger=self.logger).reset_board(target["serial_port"]) sleep(0.4) # verify flashing went as planned self.logger.debug("verifying flash") return self.verify_flash_success( target, MbedCommon.get_binary_destination(target["mount_point"], target_filename)) # In python3 IOError is just an alias for OSError except (OSError, IOError) as error: msg = "File copy failed due to: {}".format(str(error)) self.logger.exception(msg) raise FlashError(message=msg, return_code=EXIT_CODE_OS_ERROR)
def test_reset_with_all(self): resetter = Reset() ret = resetter.reset(target_id='all', method='simple') self.assertEqual(ret, 0)
def test_reset_with_none(self): resetter = Reset() ret = resetter.reset(target_id=None, method='simple') self.assertEqual(ret, 15)
def test_reset_with_none(self): resetter = Reset() with self.assertRaises(ResetError) as cm: resetter.reset(target_id=None, method='simple') self.assertEqual(cm.exception.return_code, EXIT_CODE_TARGET_ID_MISSING)