opentitanlib/test_utils/
test_status.rs

1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6#[repr(u32)]
7pub enum TestStatus {
8    InBootRom = bindgen::test_status::test_status_kTestStatusInBootRom,
9    InBootRomHalt = bindgen::test_status::test_status_kTestStatusInBootRomHalt,
10    InTest = bindgen::test_status::test_status_kTestStatusInTest,
11    InWfi = bindgen::test_status::test_status_kTestStatusInWfi,
12    Passed = bindgen::test_status::test_status_kTestStatusPassed,
13    Failed = bindgen::test_status::test_status_kTestStatusFailed,
14}
15
16impl TestStatus {
17    // Return a string describing the pattern that can be expected on the output
18    // console when the device code calls `test_set_status(status)`. This pattern
19    // can be used to wait until the device has printed this message.
20    pub fn wait_pattern(&self) -> String {
21        match self {
22            TestStatus::Passed => "PASS!".into(),
23            TestStatus::Failed => "FAIL!".into(),
24            x => format!("test_status_set to 0x{:x}", *x as u32),
25        }
26    }
27}