-
Notifications
You must be signed in to change notification settings - Fork 45
/
pcrbank_tests.rs
92 lines (76 loc) · 1.88 KB
/
pcrbank_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*++
Licensed under the Apache-2.0 license.
File Name:
pcrbank_tests.rs
Abstract:
File contains test cases for PCR bank API
--*/
#![no_std]
#![no_main]
use caliptra_drivers::{PcrBank, PcrId};
use caliptra_registers::pv::PvReg;
use caliptra_test_harness::test_suite;
const PCR_IDS: [PcrId; 32] = [
PcrId::PcrId0,
PcrId::PcrId1,
PcrId::PcrId2,
PcrId::PcrId3,
PcrId::PcrId4,
PcrId::PcrId5,
PcrId::PcrId6,
PcrId::PcrId7,
PcrId::PcrId8,
PcrId::PcrId9,
PcrId::PcrId10,
PcrId::PcrId11,
PcrId::PcrId12,
PcrId::PcrId13,
PcrId::PcrId14,
PcrId::PcrId15,
PcrId::PcrId16,
PcrId::PcrId17,
PcrId::PcrId18,
PcrId::PcrId19,
PcrId::PcrId20,
PcrId::PcrId21,
PcrId::PcrId22,
PcrId::PcrId23,
PcrId::PcrId24,
PcrId::PcrId25,
PcrId::PcrId26,
PcrId::PcrId27,
PcrId::PcrId28,
PcrId::PcrId29,
PcrId::PcrId30,
PcrId::PcrId31,
];
fn test_lock_and_erase_pcrs() {
let mut pcr_bank = unsafe { PcrBank::new(PvReg::new()) };
for pcr_id in PCR_IDS {
assert!(pcr_bank.erase_pcr(pcr_id).is_ok());
// Set lock.
assert!(!pcr_bank.pcr_lock(pcr_id));
pcr_bank.set_pcr_lock(pcr_id);
assert!(pcr_bank.pcr_lock(pcr_id));
// Test erasing pcr. This should fail.
assert!(pcr_bank.erase_pcr(pcr_id).is_err());
}
}
fn test_erase_all_pcrs() {
let mut pcr_bank = unsafe { PcrBank::new(PvReg::new()) };
pcr_bank.erase_all_pcrs();
}
fn test_write_protection_stickiness() {
let mut pcr_bank = unsafe { PcrBank::new(PvReg::new()) };
for pcr_id in PCR_IDS {
assert!(pcr_bank.pcr_lock(pcr_id));
pcr_bank.clear_pcr_lock(pcr_id);
assert!(pcr_bank.pcr_lock(pcr_id));
}
}
// Maintain the order of the tests.
test_suite! {
test_lock_and_erase_pcrs,
test_erase_all_pcrs,
test_write_protection_stickiness,
}