Skip to content

Commit

Permalink
Add driver test cases for PersistentDataAccessor. (#747)
Browse files Browse the repository at this point in the history
PersistentData::assert_matches_layout() is executed on the host as part
of the unit tests, but we also need to check the layout when compiled for
risc-v, as some types have a different size on a 32-bit CPU.
  • Loading branch information
korran authored Sep 13, 2023
1 parent 8247d5a commit bf1a7f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/test-fw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ name = "pcrbank"
path = "src/bin/pcrbank_tests.rs"
required-features = ["riscv"]

[[bin]]
name = "persistent"
path = "src/bin/persistent_tests.rs"
required-features = ["riscv"]

[[bin]]
name = "sha384acc"
path = "src/bin/sha384acc_tests.rs"
Expand Down
27 changes: 27 additions & 0 deletions drivers/test-fw/src/bin/persistent_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed under the Apache-2.0 license

#![no_std]
#![no_main]

use caliptra_drivers::{PersistentData, PersistentDataAccessor};
use caliptra_test_harness::test_suite;

fn test_persistent_data_layout() {
PersistentData::assert_matches_layout();
}

fn test_read_write() {
{
let mut accessor = unsafe { PersistentDataAccessor::new() };
accessor.get_mut().fht.fht_marker = 0xfe9cd1c0;
}
{
let accessor = unsafe { PersistentDataAccessor::new() };
assert_eq!(accessor.get().fht.fht_marker, 0xfe9cd1c0);
}
}

test_suite! {
test_persistent_data_layout,
test_read_write,
}
5 changes: 5 additions & 0 deletions drivers/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,3 +1019,8 @@ fn test_trng_in_etrng_mode() {
let trng_block = model.mailbox_execute(0, &[]).unwrap();
assert_eq!(trng_block, Some(block1.as_bytes().to_vec()));
}

#[test]
fn test_persistent() {
run_driver_test("persistent");
}

0 comments on commit bf1a7f7

Please sign in to comment.