mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tests: exercise TPM after reboot
Extend test_tpm to issue random, fixed-property, PCR read, and PCR event commands before and after a guest reboot. Assisted-by: Copilot:GPT-5.5 Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -5932,15 +5932,33 @@ mod common_parallel {
|
||||
let mut child = guest_cmd.spawn().unwrap();
|
||||
let r = std::panic::catch_unwind(|| {
|
||||
guest.wait_vm_boot().unwrap();
|
||||
assert_eq!(
|
||||
guest.ssh_command("ls /dev/tpm0").unwrap().trim(),
|
||||
"/dev/tpm0"
|
||||
);
|
||||
guest.ssh_command("sudo tpm2_selftest -f").unwrap();
|
||||
guest
|
||||
.ssh_command("echo 'hello' > /tmp/checksum_test; ")
|
||||
.unwrap();
|
||||
guest.ssh_command("cmp <(sudo tpm2_pcrevent /tmp/checksum_test | grep sha256 | awk '{print $2}') <(sha256sum /tmp/checksum_test| awk '{print $1}')").unwrap();
|
||||
let exercise_tpm = || {
|
||||
assert_eq!(
|
||||
guest.ssh_command("ls /dev/tpm0").unwrap().trim(),
|
||||
"/dev/tpm0"
|
||||
);
|
||||
guest.ssh_command("sudo tpm2_selftest -f").unwrap();
|
||||
guest
|
||||
.ssh_command(
|
||||
"sudo tpm2_getrandom 32 >/tmp/tpm_random \
|
||||
&& test $(wc -c </tmp/tpm_random) -eq 32",
|
||||
)
|
||||
.unwrap();
|
||||
guest
|
||||
.ssh_command("sudo tpm2_getcap properties-fixed | grep -q TPM2_PT_MANUFACTURER")
|
||||
.unwrap();
|
||||
guest
|
||||
.ssh_command("sudo tpm2_pcrread sha256:0,1,2,3 >/tmp/tpm_pcrread")
|
||||
.unwrap();
|
||||
guest
|
||||
.ssh_command("echo 'hello' > /tmp/checksum_test; ")
|
||||
.unwrap();
|
||||
guest.ssh_command("cmp <(sudo tpm2_pcrevent /tmp/checksum_test | grep sha256 | awk '{print $2}') <(sha256sum /tmp/checksum_test| awk '{print $1}')").unwrap();
|
||||
};
|
||||
|
||||
exercise_tpm();
|
||||
guest.reboot_linux(0);
|
||||
exercise_tpm();
|
||||
});
|
||||
|
||||
let _ = swtpm_child.kill();
|
||||
|
||||
Reference in New Issue
Block a user