opentitanlib/test_utils/
mod.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
5pub mod bitbanging;
6pub mod bootstrap;
7pub mod crashdump;
8pub mod e2e_command;
9pub mod epmp;
10// The "english breakfast" variant of the chip doesn't have the same
11// set of CSRs as the "earlgrey" chip.
12#[cfg(not(feature = "english_breakfast"))]
13pub mod extclk;
14pub mod gpio;
15pub mod gpio_monitor;
16pub mod i2c_target;
17pub mod init;
18pub mod lc;
19pub mod lc_transition;
20pub mod load_bitstream;
21pub mod load_sram_program;
22pub mod mem;
23pub mod object;
24pub mod otp_ctrl;
25// The "english breakfast" variant of the chip doesn't have the same
26// set of IO and pinmux constants as the "earlgrey" chip.
27#[cfg(not(feature = "english_breakfast"))]
28pub mod pinmux_config;
29pub mod poll;
30pub mod rpc;
31pub mod spi_passthru;
32pub mod status;
33pub mod test_status;
34
35/// The `execute_test` macro should be used in end-to-end tests to
36/// invoke each test from the `main` function.
37/// ```
38/// fn main() -> Result<()> {
39///     // Set up the test environment.
40///
41///     execute_test!(test_foo, &opts, &stransport);
42///     execute_test!(test_bar, &opts, &stransport);
43///     execute_test!(test_baz, &opts, &stransport);
44///     Ok(())
45/// }
46/// ```
47///
48/// The `main` function and each test function should return an `anyhow::Result<()>`.
49///
50/// The `execute_test` macro will print the standard test header and
51/// result footer.  A failed test will abort the program and subsequent tests will
52/// not be executed.
53#[macro_export]
54macro_rules! execute_test {
55    ($test:path, $($args:tt)*) => {
56        println!("{}:Starting test {}...", line!(), stringify!($test));
57        let result = $test($($args)*);
58        println!("{}:Finished test {}: {:?}", line!(), stringify!($test), result);
59        let _ = result?;
60    };
61}