Expand description
The OCP Test & Validation Initiative is a collaboration between datacenter hyperscalers having the goal of standardizing aspects of the hardware validation/diagnosis space, along with providing necessary tooling to enable both diagnostic developers and executors to leverage these interfaces.
Specifically, the ocp-diag-core-rust project makes it easy for developers to use the OCP Test & Validation specification artifacts by presenting a pure-rust api that can be used to output spec compliant JSON messages.
To start, please see below for installation instructions and usage.
This project is part of ocp-diag-core and exists under the same MIT License Agreement.
§Usage
The specification does not impose any particular level of usage. To be compliant, a diagnostic package just needs output the correct artifact messages in the correct format. However, any particular such diagnostic is free to choose what aspects it needs to use/output; eg. a simple validation test may not output any measurements, opting to just have a final Diagnosis outcome.
A very simple starter example, which just outputs a diagnosis:
use anyhow::Result;
use ocptv::output as tv;
use ocptv::{ocptv_diagnosis_fail, ocptv_diagnosis_pass};
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::ScopedTestStep) -> Result<TestStatus, tv::OcptvError> {
let fan_speed = get_fan_speed();
if fan_speed >= 1600 {
step.add_diagnosis("fan_ok", tv::DiagnosisType::Pass).await?;
} else {
step.add_diagnosis("fan_low", tv::DiagnosisType::Fail).await?;
}
Ok(TestStatus::Complete)
}
async fn run_diagnosis_macros_step(step: tv::ScopedTestStep) -> Result<TestStatus, tv::OcptvError> {
let fan_speed = get_fan_speed();
/// using the macro, the source location is filled automatically
if fan_speed >= 1600 {
ocptv_diagnosis_pass!(step, "fan_ok").await?;
} else {
ocptv_diagnosis_fail!(step, "fan_low").await?;
}
Ok(TestStatus::Complete)
}
#[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(run_diagnosis_step)
.await?;
r.add_step("step1")
.scope(run_diagnosis_macros_step)
.await?;
Ok(tv::TestRunOutcome {
status: TestStatus::Complete,
result: TestResult::Pass,
})
})
.await?;
Ok(())
}
Modules§
Macros§
- ocptv_
diagnosis_ fail - Emit an artifact of type Diagnosis.
- ocptv_
diagnosis_ pass - Emit an artifact of type Diagnosis.
- ocptv_
diagnosis_ unknown - Emit an artifact of type Diagnosis.
- ocptv_
error - Emit an artifact of type Error.
- ocptv_
log_ debug - Emit an artifact of type Log.
- ocptv_
log_ error - Emit an artifact of type Log.
- ocptv_
log_ fatal - Emit an artifact of type Log.
- ocptv_
log_ info - Emit an artifact of type Log.
- ocptv_
log_ warning - Emit an artifact of type Log.