MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / test_tpm

Function test_tpm

cloud-hypervisor/tests/integration.rs:5656–5698  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5654 #[cfg(not(feature = "mshv"))] // See issue #7439
5655 #[cfg(target_arch = "x86_64")]
5656 fn test_tpm() {
5657 let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
5658 let guest = Guest::new(Box::new(disk_config));
5659
5660 let (mut swtpm_command, swtpm_socket_path) = prepare_swtpm_daemon(&guest.tmp_dir);
5661
5662 let mut guest_cmd = GuestCommand::new(&guest);
5663 guest_cmd
5664 .default_cpus()
5665 .args(["--memory", "size=1G"])
5666 .args(["--kernel", fw_path(FwType::RustHypervisorFirmware).as_str()])
5667 .args(["--tpm", &format!("socket={swtpm_socket_path}")])
5668 .capture_output()
5669 .default_disks()
5670 .default_net();
5671
5672 // Start swtpm daemon
5673 let mut swtpm_child = swtpm_command.spawn().unwrap();
5674 assert!(wait_until(Duration::from_secs(10), || {
5675 std::path::Path::new(&swtpm_socket_path).exists()
5676 }));
5677 let mut child = guest_cmd.spawn().unwrap();
5678 let r = std::panic::catch_unwind(|| {
5679 guest.wait_vm_boot().unwrap();
5680 assert_eq!(
5681 guest.ssh_command("ls /dev/tpm0").unwrap().trim(),
5682 "/dev/tpm0"
5683 );
5684 guest.ssh_command("sudo tpm2_selftest -f").unwrap();
5685 guest
5686 .ssh_command("echo 'hello' > /tmp/checksum_test; ")
5687 .unwrap();
5688 guest.ssh_command("cmp <(sudo tpm2_pcrevent /tmp/checksum_test | grep sha256 | awk '{print $2}') <(sha256sum /tmp/checksum_test| awk '{print $1}')").unwrap();
5689 });
5690
5691 let _ = swtpm_child.kill();
5692 let _d_out = swtpm_child.wait_with_output().unwrap();
5693
5694 kill_child(&mut child);
5695 let output = child.wait_with_output().unwrap();
5696
5697 handle_child_output(r, &output);
5698 }
5699
5700 #[test]
5701 #[cfg(target_arch = "x86_64")]

Callers

nothing calls this directly

Calls 14

newFunction · 0.85
prepare_swtpm_daemonFunction · 0.85
fw_pathFunction · 0.85
kill_childFunction · 0.85
handle_child_outputFunction · 0.85
default_netMethod · 0.80
default_disksMethod · 0.80
capture_outputMethod · 0.80
argsMethod · 0.80
default_cpusMethod · 0.80
spawnMethod · 0.80
wait_vm_bootMethod · 0.80

Tested by

no test coverage detected