1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
mod test_server;
use {
fidl_fuchsia_component_runner as fcrunner, fuchsia_async as fasync,
fuchsia_component::server::ServiceFs,
futures::prelude::*,
test_runners_lib::elf,
test_server::TestServer,
thiserror::Error,
tracing::{error, warn},
};
#[fuchsia::main(logging_tags=["go_test_runner"])]
async fn main() -> Result<(), anyhow::Error> {
let mut fs = ServiceFs::new_local();
fs.dir("svc").add_fidl_service(move |stream| {
fasync::Task::local(
async move { start_runner(stream).await.expect("failed to start runner.") },
)
});
fs.take_and_serve_directory_handle()?;
fs.for_each_concurrent(None, |t| async {
t.await;
})
.await;
Ok(())
}
#[derive(Debug, Error)]
pub enum RunnerError {
#[error("Cannot read request: {:?}", _0)]
RequestRead(fidl::Error),
}
async fn start_runner(
mut request_stream: fcrunner::ComponentRunnerRequestStream,
) -> Result<(), RunnerError> {
while let Some(event) = request_stream.try_next().await.map_err(RunnerError::RequestRead)? {
match event {
fcrunner::ComponentRunnerRequest::Start { start_info, controller, .. } => {
let url = start_info.resolved_url.clone().unwrap_or("".to_owned());
if let Err(e) = elf::start_component(
start_info,
controller,
TestServer::new,
TestServer::validate_args,
)
.await
{
warn!("Cannot start component '{}': {:?}", url, e);
}
}
}
}
Ok(())
}