From 4527ae449b26de17f1f98d82a822d5f3d4e1436a Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 30 May 2026 16:13:45 -0700 Subject: [PATCH] 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 --- cloud-hypervisor/tests/integration.rs | 36 ++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cloud-hypervisor/tests/integration.rs b/cloud-hypervisor/tests/integration.rs index f0f9e77eb..042f0405e 100644 --- a/cloud-hypervisor/tests/integration.rs +++ b/cloud-hypervisor/tests/integration.rs @@ -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_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();