Skip to content

Commit

Permalink
Merge pull request #18 from opencomputeproject/fea/file_example
Browse files Browse the repository at this point in the history
Fea/file example
  • Loading branch information
njordr authored Oct 11, 2024
2 parents 81fc064 + 9d59388 commit 501c75d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ required-features = ["boxed-scopes"]

[[example]]
name = "diagnosis"
required-features = ["boxed-scopes"]

[[example]]
name = "file"
required-features = ["boxed-scopes"]
45 changes: 45 additions & 0 deletions examples/file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// (c) Meta Platforms, Inc. and affiliates.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use std::str::FromStr;

use anyhow::Result;
use futures::FutureExt;

use ocptv::output as tv;
use tv::{TestResult, TestStatus};

async fn run_file_step(step: &tv::StartedTestStep) -> Result<TestStatus, tv::OcptvError> {
let uri = tv::Uri::from_str("file:///root/mem_cfg_log").unwrap();
step.file("mem_cfg_log", uri).await?;

Ok(TestStatus::Complete)
}

/// Simple demo with file.
#[tokio::main]
async fn main() -> Result<()> {
let dut = tv::DutInfo::builder("dut0").build();

tv::TestRun::builder("simple measurement", "1.0")
.build()
.scope(dut, |r| {
async move {
r.add_step("step0")
.scope(|s| run_file_step(s).boxed())
.await?;

Ok(tv::TestRunOutcome {
status: TestStatus::Complete,
result: TestResult::Pass,
})
}
.boxed()
})
.await?;

Ok(())
}

0 comments on commit 501c75d

Please sign in to comment.