fn flash_target(
    testchannel: &mut CombinedTestChannel,
    target_info: &TargetInfo,
    tss_pos: u8,
    result_sender: &SyncSender<FlashStatus>,
    testprogram: &TestProgram,
    flash_results: &Arc<RwLock<Vec<FlashStatus>>>,
) {
    // Check if Testchannel is ready and if the target_info has been successfully initialized.
    if !testchannel.is_ready() || target_info.status.is_err() {
        return;
    }

    // Check if this target was already flashed successfully
    let flash_results = flash_results.read().unwrap();
    if flash_results
        .iter()
        .filter(|result| {
            result.tss_pos == tss_pos
                && result.target_name == target_info.name
                && result.result.is_ok()
        })
        .count()
        != 0
    {
        return;
    }
    drop(flash_results); // Return lock

    let probe_info_lock = testchannel.get_probe_info().lock();
    let probe_info = probe_info_lock.as_ref().unwrap();

    log::info!(
        "Flashing testbinary onto target {} with probe {}",
        target_info.name,
        probe_info.identifier
    );

    let flash_result = retry_flash(&testchannel, target_info, probe_info, |mut session| {
        let mut download_options = DownloadOptions::default();
        download_options.do_chip_erase = true;

        let path = match target_info.architecture.as_ref().unwrap() {
            Architecture::ARM => {
                testprogram.get_elf_path_arm(&target_info.memory_address.as_ref().unwrap())
            }
            Architecture::RISCV => {
                testprogram.get_elf_path_riscv(&target_info.memory_address.as_ref().unwrap())
            }
        };

        download_file_with_options(&mut session, path, Format::Elf, download_options)?;

        Ok(())
    });

    match flash_result {
        Ok(_) => result_sender.send(FlashStatus {
            tss_pos,
            target_name: target_info.name.clone(),
            result: Ok(()),
        }).expect("Failed to send results to main thread, the receiver might have been dropped unexpectedly."),
        Err(err) => {
            let source = match err.source(){
                Some(source) => source.to_string(),
                None => "No source".to_owned(),
            };
            
            result_sender.send(FlashStatus {
            tss_pos,
            target_name: target_info.name.clone(),
            result: Err(format!("{}: {}",err.to_string(), source)),
        }).expect("Failed to send results to main thread, the receiver might have been dropped unexpectedly.")},
    }

    // reinitialize probe, and transfer ownership back to test_channel
    match probe_info.open() {
        Ok(probe) => testchannel.return_probe(probe),
        Err(err) => {
            log::warn!(
                "Failed to reinitialize the debug probe connected to {}: {}. Skipping the remaining flash attempts on this Testchannel.",
                testchannel.get_channel(),
                err
            )
        }
    }
}
/// Flashes a testbinary onto the provided target.
///
/// # Panics
/// If the provided [`TargetInfo`] struct fields `architecture` and/or `memory_address` are not initialized
Flashes a testbinary onto the provided target.
Flashes a testbinary onto the provided target .
fn flash_target(
    testchannel: &mut CombinedTestChannel,
    target_info: &TargetInfo,
    tss_pos: u8,
    result_sender: &SyncSender<FlashStatus>,
    testprogram: &TestProgram,
    flash_results: &Arc<RwLock<Vec<FlashStatus>>>,
) {
    // Check if Testchannel is ready and if the target_info has been successfully initialized.
    if !testchannel.is_ready() || target_info.status.is_err() {
        return;
    }
    // Check if this target was already flashed successfully
    let flash_results = flash_results.read().unwrap();
    if flash_results
        .iter()
        .filter(|result| {
            result.tss_pos == tss_pos
                && result.target_name == target_info.name
                && result.result.is_ok()
        })
        .count()
        != 0
    {
        return;
    }
    drop(flash_results); // Return lock
    let probe_info_lock = testchannel.get_probe_info().lock();
    let probe_info = probe_info_lock.as_ref().unwrap();
    log::info!(
        "Flashing testbinary onto target {} with probe {}",
        target_info.name,
        probe_info.identifier
    );
    let flash_result = retry_flash(&testchannel, target_info, probe_info, |mut session| {
        let mut download_options = DownloadOptions::default();
        download_options.do_chip_erase = true;
        let path = match target_info.architecture.as_ref().unwrap() {
            Architecture::ARM => {
                testprogram.get_elf_path_arm(&target_info.memory_address.as_ref().unwrap())
            }
            Architecture::RISCV => {
                testprogram.get_elf_path_riscv(&target_info.memory_address.as_ref().unwrap())
            }
        };
        download_file_with_options(&mut session, path, Format::Elf, download_options)?;
        Ok(())
    });
    match flash_result {
        Ok(_) => result_sender.send(FlashStatus {
            tss_pos,
            target_name: target_info.name.clone(),
            result: Ok(()),
        }).expect("Failed to send results to main thread, the receiver might have been dropped unexpectedly."),
        Err(err) => {
            let source = match err.source(){
                Some(source) => source.to_string(),
                None => "No source".to_owned(),
            };
            result_sender.send(FlashStatus {
            tss_pos,
            target_name: target_info.name.clone(),
            result: Err(format!("{}: {}",err.to_string(), source)),
        }).expect("Failed to send results to main thread, the receiver might have been dropped unexpectedly.")},
    }
    // reinitialize probe, and transfer ownership back to test_channel
    match probe_info.open() {
        Ok(probe) => testchannel.return_probe(probe),
        Err(err) => {
            log::warn!(
                "Failed to reinitialize the debug probe connected to {}: {}. Skipping the remaining flash attempts on this Testchannel.",
                testchannel.get_channel(),
                err
            )
        }
    }
}
fn flash_target ( testchannel : & mut CombinedTestChannel , target_info : & TargetInfo , tss_pos : u8 , result_sender : & SyncSender < FlashStatus > , testprogram : & TestProgram , flash_results : & Arc < RwLock < Vec < FlashStatus > > > , ) { // Check if Testchannel is ready and if the target_info has been successfully initialized. if ! testchannel . is_ready ( ) || target_info . status . is_err ( ) { return ; } // Check if this target was already flashed successfully let flash_results = flash_results . read ( ) . unwrap ( ) ; if flash_results . iter ( ) . filter ( | result | { result . tss_pos == tss_pos && result . target_name == target_info . name && result . result . is_ok ( ) } ) . count ( ) != 0 { return ; } drop ( flash_results ) ; // Return lock let probe_info_lock = testchannel . get_probe_info ( ) . lock ( ) ; let probe_info = probe_info_lock . as_ref ( ) . unwrap ( ) ; log :: info ! ( " " target_info name probe_info identifier ) ; let flash_result = retry_flash ( & testchannel , target_info , probe_info , | mut session | { let mut download_options = DownloadOptions :: default ( ) ; download_options . do_chip_erase = true ; let path = match target_info . architecture . as_ref ( ) . unwrap ( ) { Architecture :: ARM => { testprogram . get_elf_path_arm ( & target_info . memory_address . as_ref ( ) . unwrap ( ) ) } Architecture :: RISCV => { testprogram . get_elf_path_riscv ( & target_info . memory_address . as_ref ( ) . unwrap ( ) ) } } ; download_file_with_options ( & mut session , path , Format :: Elf , download_options ) ? ; Ok ( ( ) ) } ) ; match flash_result { Ok ( _ ) => result_sender . send ( FlashStatus { tss_pos , target_name : target_info . name . clone ( ) , result : Ok ( ( ) ) , } ) . expect ( " " ) , Err ( err ) => { let source = match err . source ( ) { Some ( source ) => source . to_string ( ) , None => " " . to_owned ( ) , } ; result_sender . send ( FlashStatus { tss_pos , target_name : target_info . name . clone ( ) , result : Err ( format ! ( " " err to_string ( ) source ) ) , } ) . expect ( " " ) } , } // reinitialize probe, and transfer ownership back to test_channel match probe_info . open ( ) { Ok ( probe ) => testchannel . return_probe ( probe ) , Err ( err ) => { log :: warn ! ( " " testchannel get_channel ( ) err ) } } }
Flashes a testbinary onto the provided target.
Flashes a testbinary onto the provided target .
testchannel
&mut CombinedTestChannel
target_info
&TargetInfo
tss_pos
u8
result_sender
&SyncSender<FlashStatus>
testprogram
&TestProgram
flash_results
&Arc<RwLock<Vec<FlashStatus>>>
panics
If the provided [`TargetInfo`] struct fields `architecture` and/or `memory_address` are not initialized
If the provided [ ` TargetInfo ` ] struct fields ` architecture ` and / or ` memory_address ` are not initialized