blob: b3291a95212bff49a007073c4f530b011d777c5f [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use anyhow::Error;
use diagnostics_hierarchy::DiagnosticsHierarchy;
use diagnostics_reader::{ArchiveReader, Inspect};
use fidl_fuchsia_mockrebootcontroller::{MockRebootControllerMarker, MockRebootControllerProxy};
use fidl_fuchsia_sys::ComponentControllerEvent;
use fuchsia_async as fasync;
use fuchsia_async::futures::StreamExt;
use fuchsia_component::client::{launch, launcher, App};
use fuchsia_inspect::{assert_inspect_tree, testing::AnyProperty};
async fn setup() -> (App, App, MockRebootControllerProxy) {
let package = "fuchsia-pkg://";
let sampler_manifest = "sampler.cmx";
let test_component_manifest = "single_counter_test_component.cmx";
let sampler_url = format!("{}{}", package, sampler_manifest);
let test_component_url = format!("{}{}", package, test_component_manifest);
let sampler_app = launch(&launcher().unwrap(), sampler_url.to_string(), None).unwrap();
let test_component =
launch(&launcher().unwrap(), test_component_url.to_string(), None).unwrap();
let mut component_stream = test_component.controller().take_event_stream();
match component_stream
.expect("component event stream has ended before termination event")
ComponentControllerEvent::OnDirectoryReady {} => {}
ComponentControllerEvent::OnTerminated { return_code, termination_reason } => {
"Component terminated unexpectedly. Code: {}. Reason: {:?}",
return_code, termination_reason
let reboot_controller =
(sampler_app, test_component, reboot_controller)
async fn sampler_inspect_hierarchy() -> DiagnosticsHierarchy {
let mut data = ArchiveReader::new()
.expect("got inspect data");
data.pop().expect("one result").payload.expect("payload is not none")
/// Runs the Lapis Sampler and a test component that can have its inspect properties
/// manipulated by the test via fidl, and uses mock services to determine that when
/// the reboot server goes down, lapis continues to run as expected.
async fn sampler_inspect_test() {
let (mut sampler_app, _test_component, _reboot_controller) = setup().await;
let _sampler_app: fasync::Task<Result<(), Error>> = fasync::Task::spawn(async move {
panic!("we crash the reboot server, so sampler_app should never exit.")
// Observe verification shows up in inspect.
let hierarchy = sampler_inspect_hierarchy().await;
// TODO(42067): Introduce better fencing so we can
// guarantee we fetch the hierachy after the metrics were sampled
// AND fully processed.
root: {
"sampler_executor_stats": {
"healthily_exited_samplers": 0 as u64,
"errorfully_exited_samplers": 0 as u64,
"reboot_exited_samplers": 0 as u64,
"total_project_samplers_configured": 2 as u64,
"project_5": {
"project_sampler_count": 2 as u64,
"metrics_configured": 4 as u64,
"cobalt_logs_sent": AnyProperty,
"fuchsia.inspect.Health": {
"start_timestamp_nanos": AnyProperty,
"status": AnyProperty