Skip to content

Commit

Permalink
Rebase and fix file example
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Colapinto <[email protected]>
  • Loading branch information
njordr committed Oct 11, 2024
1 parent 43c509c commit 51aaca7
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions examples/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,22 @@
// 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 rand::Rng;
use tv::{TestResult, TestStatus};

fn get_fan_speed() -> i32 {
let mut rng = rand::thread_rng();
rng.gen_range(1500..1700)
}

async fn run_diagnosis_step(step: &tv::StartedTestStep) -> Result<TestStatus, tv::OcptvError> {
let fan_speed = get_fan_speed();

if fan_speed >= 1600 {
step.diagnosis("fan_ok", tv::DiagnosisType::Pass).await?;
} else {
step.diagnosis("fan_low", tv::DiagnosisType::Fail).await?;
}
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 diagnosis.
/// Simple demo with file.
#[tokio::main]
async fn main() -> Result<()> {
let dut = tv::DutInfo::builder("dut0").build();
Expand All @@ -38,7 +29,7 @@ async fn main() -> Result<()> {
.scope(dut, |r| {
async move {
r.add_step("step0")
.scope(|s| { s.file("output") }.boxed())
.scope(|s| run_file_step(s).boxed())
.await?;

Ok(tv::TestRunOutcome {
Expand Down

0 comments on commit 51aaca7

Please sign in to comment.