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