pub fn start_component<F, S>(
    start_info: fcrunner::ComponentStartInfo,
    server_end: ServerEnd<fcrunner::ComponentControllerMarker>,
    get_test_server: F,
) -> Result<(), ComponentError>
where
    F: 'static + Fn() -> S,
    S: SuiteServer,
{
    let (component, outgoing_dir) = Component::new(start_info)?;
    let component = Arc::new(component);

    let job_dup = component
        .job
        .duplicate_handle(zx::Rights::SAME_RIGHTS)
        .map_err(ComponentError::DuplicateJob)?;
    let mut fs = ServiceFs::new_local();

    let suite_server_abortable_handles = Arc::new(Mutex::new(vec![]));
    let weak_test_suite_abortable_handles = Arc::downgrade(&suite_server_abortable_handles);

    let weak_component = Arc::downgrade(&component);

    let url = component.url.clone();
    fs.dir("svc").add_fidl_service(move |stream| {
        let abortable_handles = weak_test_suite_abortable_handles.upgrade();
        if abortable_handles.is_none() {
            return;
        }
        let abortable_handles = abortable_handles.unwrap();
        let mut abortable_handles = abortable_handles.lock().unwrap();
        let abortable_handle = get_test_server().run(weak_component.clone(), &url, stream);
        abortable_handles.push(abortable_handle);
    });

    fs.serve_connection(outgoing_dir.into_channel()).map_err(ComponentError::ServeSuite)?;
    let (fut, abortable_handle) = abortable(fs.collect::<()>());

    let url = component.url.clone();
    let component_runtime =
        ComponentRuntime::new(abortable_handle, suite_server_abortable_handles, job_dup, component);

    let resolved_url = url.clone();
    fasync::spawn_local(async move {
        if let Err(e) = fut.await {
            fx_log_err!("Test {} ended with error {:?}", url, e);
        }
    });

    let controller_stream = server_end.into_stream().map_err(|e| {
        ComponentError::Fidl("failed to convert server end to controller".to_owned(), e)
    })?;
    let controller = runner::component::Controller::new(component_runtime, controller_stream);
    fasync::spawn_local(async move {
        if let Err(e) = controller.serve().await {
            fx_log_err!("test '{}' controller ended with error: {:?}", resolved_url, e);
        }
    });

    Ok(())
}
/// Setup and run test component in background.
/// |F|: Funciton which returns new instance of `SuitServer`.
Setup and run test component in background.
|F|: Funciton which returns new instance of `SuitServer`.
Setup and run test component in background . |F| : Funciton which returns new instance of ` SuitServer ` .
pub fn start_component<F, S>(
    start_info: fcrunner::ComponentStartInfo,
    server_end: ServerEnd<fcrunner::ComponentControllerMarker>,
    get_test_server: F,
) -> Result<(), ComponentError>
where
    F: 'static + Fn() -> S,
    S: SuiteServer,
{
    let (component, outgoing_dir) = Component::new(start_info)?;
    let component = Arc::new(component);
    let job_dup = component
        .job
        .duplicate_handle(zx::Rights::SAME_RIGHTS)
        .map_err(ComponentError::DuplicateJob)?;
    let mut fs = ServiceFs::new_local();
    let suite_server_abortable_handles = Arc::new(Mutex::new(vec![]));
    let weak_test_suite_abortable_handles = Arc::downgrade(&suite_server_abortable_handles);
    let weak_component = Arc::downgrade(&component);
    let url = component.url.clone();
    fs.dir("svc").add_fidl_service(move |stream| {
        let abortable_handles = weak_test_suite_abortable_handles.upgrade();
        if abortable_handles.is_none() {
            return;
        }
        let abortable_handles = abortable_handles.unwrap();
        let mut abortable_handles = abortable_handles.lock().unwrap();
        let abortable_handle = get_test_server().run(weak_component.clone(), &url, stream);
        abortable_handles.push(abortable_handle);
    });
    fs.serve_connection(outgoing_dir.into_channel()).map_err(ComponentError::ServeSuite)?;
    let (fut, abortable_handle) = abortable(fs.collect::<()>());
    let url = component.url.clone();
    let component_runtime =
        ComponentRuntime::new(abortable_handle, suite_server_abortable_handles, job_dup, component);
    let resolved_url = url.clone();
    fasync::spawn_local(async move {
        if let Err(e) = fut.await {
            fx_log_err!("Test {} ended with error {:?}", url, e);
        }
    });
    let controller_stream = server_end.into_stream().map_err(|e| {
        ComponentError::Fidl("failed to convert server end to controller".to_owned(), e)
    })?;
    let controller = runner::component::Controller::new(component_runtime, controller_stream);
    fasync::spawn_local(async move {
        if let Err(e) = controller.serve().await {
            fx_log_err!("test '{}' controller ended with error: {:?}", resolved_url, e);
        }
    });
    Ok(())
}
pub fn start_component < F , S > ( start_info : fcrunner :: ComponentStartInfo , server_end : ServerEnd < fcrunner :: ComponentControllerMarker > , get_test_server : F , ) -> Result < ( ) , ComponentError > where F : ' static + Fn ( ) -> S , S : SuiteServer , { let ( component , outgoing_dir ) = Component :: new ( start_info ) ? ; let component = Arc :: new ( component ) ; let job_dup = component . job . duplicate_handle ( zx :: Rights :: SAME_RIGHTS ) . map_err ( ComponentError :: DuplicateJob ) ? ; let mut fs = ServiceFs :: new_local ( ) ; let suite_server_abortable_handles = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ; let weak_test_suite_abortable_handles = Arc :: downgrade ( & suite_server_abortable_handles ) ; let weak_component = Arc :: downgrade ( & component ) ; let url = component . url . clone ( ) ; fs . dir ( " " ) . add_fidl_service ( move | stream | { let abortable_handles = weak_test_suite_abortable_handles . upgrade ( ) ; if abortable_handles . is_none ( ) { return ; } let abortable_handles = abortable_handles . unwrap ( ) ; let mut abortable_handles = abortable_handles . lock ( ) . unwrap ( ) ; let abortable_handle = get_test_server ( ) . run ( weak_component . clone ( ) , & url , stream ) ; abortable_handles . push ( abortable_handle ) ; } ) ; fs . serve_connection ( outgoing_dir . into_channel ( ) ) . map_err ( ComponentError :: ServeSuite ) ? ; let ( fut , abortable_handle ) = abortable ( fs . collect :: < ( ) > ( ) ) ; let url = component . url . clone ( ) ; let component_runtime = ComponentRuntime :: new ( abortable_handle , suite_server_abortable_handles , job_dup , component ) ; let resolved_url = url . clone ( ) ; fasync :: spawn_local ( async move { if let Err ( e ) = fut . await { fx_log_err ! ( " " url e ) ; } } ) ; let controller_stream = server_end . into_stream ( ) . map_err ( | e | { ComponentError :: Fidl ( " " . to_owned ( ) , e ) } ) ? ; let controller = runner :: component :: Controller :: new ( component_runtime , controller_stream ) ; fasync :: spawn_local ( async move { if let Err ( e ) = controller . serve ( ) . await { fx_log_err ! ( " " resolved_url e ) ; } } ) ; Ok ( ( ) ) }
Setup and run test component in background.
Setup and run test component in background .
start_info
fcrunner::ComponentStartInfo
server_end
ServerEnd<fcrunner::ComponentControllerMarker>
get_test_server
F
start_info
fcrunner::ComponentStartInfo
server_end
ServerEnd<fcrunner::ComponentControllerMarker>
get_test_server
F