{"id":18875260,"url":"https://github.com/opencomputeproject/ocp-diag-core-rust","last_synced_at":"2025-04-14T17:31:20.987Z","repository":{"id":257826064,"uuid":"855867289","full_name":"opencomputeproject/ocp-diag-core-rust","owner":"opencomputeproject","description":"Pure rust API for the OCP Test \u0026 Validation project ","archived":false,"fork":false,"pushed_at":"2024-11-05T09:06:32.000Z","size":388,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2024-11-05T10:20:24.735Z","etag":null,"topics":["diagnostics","hardware","rust","testing","validation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opencomputeproject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-11T15:30:14.000Z","updated_at":"2024-11-05T09:06:34.000Z","dependencies_parsed_at":"2024-10-14T13:19:41.073Z","dependency_job_id":"2d99f5fa-3e27-4bae-80d3-e152cd9d51fc","html_url":"https://github.com/opencomputeproject/ocp-diag-core-rust","commit_stats":null,"previous_names":["opencomputeproject/ocp-diag-core-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomputeproject%2Focp-diag-core-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomputeproject%2Focp-diag-core-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomputeproject%2Focp-diag-core-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomputeproject%2Focp-diag-core-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencomputeproject","download_url":"https://codeload.github.com/opencomputeproject/ocp-diag-core-rust/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223639402,"owners_count":17177816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diagnostics","hardware","rust","testing","validation"],"created_at":"2024-11-08T06:06:44.308Z","updated_at":"2024-11-08T06:06:44.803Z","avatar_url":"https://github.com/opencomputeproject.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ocp-diag-core-rust\n\n[![Crates.io Version](https://img.shields.io/crates/v/ocptv)](https://crates.io/crates/ocptv)\n[![codecov](https://codecov.io/github/opencomputeproject/ocp-diag-core-rust/graph/badge.svg?token=IJOG0T8XZ3)](https://codecov.io/github/opencomputeproject/ocp-diag-core-rust)\n[![GitHub License](https://img.shields.io/github/license/opencomputeproject/ocp-diag-core-rust)](https://github.com/opencomputeproject/ocp-diag-core-rust/blob/dev/LICENSE)\n\nThe **OCP Test \u0026 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.\n\nSpecifically, the [ocp-diag-core-rust](https://github.com/opencomputeproject/ocp-diag-core-rust) project makes it easy for developers to use the **OCP Test \u0026 Validation specification** artifacts by presenting a pure-rust api that can be used to output spec compliant JSON messages.\n\nTo start, please see below for [installation instructions](https://github.com/opencomputeproject/ocp-diag-core-rust#installation) and [usage](https://github.com/opencomputeproject/ocp-diag-core-rust#usage).\n\nThis project is part of [ocp-diag-core](https://github.com/opencomputeproject/ocp-diag-core) and exists under the same [MIT License Agreement](https://github.com/opencomputeproject/ocp-diag-core-rust/LICENSE).\n\n### Installation\n\nStable releases of the **ocp-diag-core-rust** codebase are published to **crates.io** under the package name [ocptv](https://crates.io/crates/ocptv), and can be easily installed with cargo.\n\nFor general usage, the following steps should be sufficient to get the latest stable version using the [Package Installer for Rust](https://github.com/rust-lang/cargo):\n\n- **\\[option 1]** using `cargo add`\n\n    ```bash\n    $ cargo add ocptv\n    ```\n\n- **\\[option 2]** specifying it in Cargo.toml file\n\n    \n    ```toml\n    [dependencies]\n    ocptv = \"~0.1\"\n    ```\n    \nTo use the bleeding edge instead of the stable version, the dependecies section should be modified like this:\n\n```\n[dependencies]\nocptv = { git = \"https://github.com/opencomputeproject/ocp-diag-core-rust.git\", branch = \"dev\" }\n```\n\nThe instructions above assume a Linux-type system. However, the steps should be identical on Windows and MacOS platforms.\n\nSee [The Cargo Book](https://doc.rust-lang.org/cargo/index.html) for more details on how to use cargo.\n\n### Usage\n\nThe [specification](https://github.com/opencomputeproject/ocp-diag-core/tree/main/json_spec) 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.\n\n**Full API reference is available [here](https://docs.rs/ocptv).**\n\nA very simple starter example, which just outputs a diagnosis:\n```rust\nuse anyhow::Result;\n\nuse ocptv::output as tv;\nuse ocptv::{ocptv_diagnosis_fail, ocptv_diagnosis_pass};\nuse rand::Rng;\nuse tv::{TestResult, TestStatus};\n\nfn get_fan_speed() -\u003e i32 {\n    let mut rng = rand::thread_rng();\n    rng.gen_range(1500..1700)\n}\n\nasync fn run_diagnosis_step(step: tv::ScopedTestStep) -\u003e Result\u003cTestStatus, tv::OcptvError\u003e {\n    let fan_speed = get_fan_speed();\n\n    if fan_speed \u003e= 1600 {\n        step.add_diagnosis(\"fan_ok\", tv::DiagnosisType::Pass).await?;\n    } else {\n        step.add_diagnosis(\"fan_low\", tv::DiagnosisType::Fail).await?;\n    }\n\n    Ok(TestStatus::Complete)\n}\n\nasync fn run_diagnosis_macros_step(step: tv::ScopedTestStep) -\u003e Result\u003cTestStatus, tv::OcptvError\u003e {\n    let fan_speed = get_fan_speed();\n\n    /// using the macro, the source location is filled automatically\n    if fan_speed \u003e= 1600 {\n        ocptv_diagnosis_pass!(step, \"fan_ok\").await?;\n    } else {\n        ocptv_diagnosis_fail!(step, \"fan_low\").await?;\n    }\n\n    Ok(TestStatus::Complete)\n}\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c()\u003e {\n    let dut = tv::DutInfo::builder(\"dut0\").build();\n\n    tv::TestRun::builder(\"simple measurement\", \"1.0\")\n        .build()\n        .scope(dut, |r| async move {\n            r.add_step(\"step0\")\n                .scope(run_diagnosis_step)\n                .await?;\n\n            r.add_step(\"step1\")\n                .scope(run_diagnosis_macros_step)\n                .await?;\n\n            Ok(tv::TestRunOutcome {\n                status: TestStatus::Complete,\n                result: TestResult::Pass,\n            })\n        })\n        .await?;\n\n    Ok(())\n}\n```\n\nExpected output (slightly reformatted for readability):\n\n```json\n{\"sequenceNumber\":0, \"schemaVersion\":{\"major\":2,\"minor\":0},\"timestamp\":\"2024-10-11T11:39:07.026Z\"}\n\n{\"sequenceNumber\":1,\"testRunArtifact\":{\n  \"testRunStart\":{\n    \"name\":\"simple diagnosis\", \n    \"commandLine\":\"\",\"parameters\":{},\"version\":\"1.0\", \n    \"dutInfo\":{\"dutInfoId\":\"dut0\"}\n  }},\"timestamp\":\"2024-10-11T11:39:07.026Z\"}\n\n{\"sequenceNumber\":2,\"testStepArtifact\":{\n  \"testStepId\":\"step0\",\"testStepStart\":{\"name\":\"step0\"}\n  },\"timestamp\":\"2024-10-11T11:39:07.026Z\"}\n\n{\"sequenceNumber\":3,\"testStepArtifact\":{\n  \"diagnosis\":{\"type\":\"PASS\",\"verdict\":\"fan_ok\"},\n  \"testStepId\":\"step0\"},\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n{\"sequenceNumber\":4,\"testStepArtifact\":{\n  \"testStepEnd\":{\"status\":\"COMPLETE\"},\"testStepId\":\"step0\"\n  },\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n{\"sequenceNumber\":5,\"testStepArtifact\":{\n  \"testStepId\":\"step1\",\"testStepStart\":{\"name\":\"step1\"}\n  },\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n{\"sequenceNumber\":6,\"testStepArtifact\":{\n  \"diagnosis\":{\n    \"sourceLocation\":{\"file\":\"examples/diagnosis.rs\",\"line\":40},\n    \"type\":\"FAIL\",\"verdict\":\"fan_low\"\n    },\"testStepId\":\"step1\"\n  },\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n{\"sequenceNumber\":7,\"testStepArtifact\":{\n  \"testStepEnd\":{\"status\":\"COMPLETE\"},\"testStepId\":\"step1\"\n  },\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n{\"sequenceNumber\":8,\"testRunArtifact\":{\n  \"testRunEnd\":{\"result\":\"PASS\",\"status\":\"COMPLETE\"}\n  },\"timestamp\":\"2024-10-11T11:39:07.027Z\"}\n\n```\n\n### Examples\n\nThe examples in [examples folder](https://github.com/opencomputeproject/ocp-diag-core-rust/tree/dev/examples) can be run using cargo.\n\n```bash\n# run diagnosis example\n$ cargo run --example diagnosis\n```\n\n### Developer notes\n\nIf you would like to contribute, please head over to [developer notes](https://github.com/opencomputeproject/ocp-diag-core-rust/tree/dev/DEVELOPERS.md) for instructions.\n\n### Contact\n\nFeel free to start a new [discussion](https://github.com/opencomputeproject/ocp-diag-core-rust/discussions), or otherwise post an [issue/request](https://github.com/opencomputeproject/ocp-diag-core-rust/issues).\n\nAn email contact is also available at: ocp-test-validation@OCP-All.groups.io\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomputeproject%2Focp-diag-core-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencomputeproject%2Focp-diag-core-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomputeproject%2Focp-diag-core-rust/lists"}