()
| 5462 | |
| 5463 | #[test] |
| 5464 | fn test_vfio_user() { |
| 5465 | let jammy_image = JAMMY_IMAGE_NAME.to_string(); |
| 5466 | let disk_config = UbuntuDiskConfig::new(jammy_image); |
| 5467 | let guest = Guest::new(Box::new(disk_config)); |
| 5468 | |
| 5469 | let spdk_nvme_dir = guest.tmp_dir.as_path().join("test-vfio-user"); |
| 5470 | let mut spdk_child = setup_spdk_nvme(spdk_nvme_dir.as_path()); |
| 5471 | |
| 5472 | let api_socket = temp_api_path(&guest.tmp_dir); |
| 5473 | let mut child = GuestCommand::new(&guest) |
| 5474 | .args(["--api-socket", &api_socket]) |
| 5475 | .default_cpus() |
| 5476 | .args(["--memory", "size=1G,shared=on,hugepages=on"]) |
| 5477 | .args(["--kernel", fw_path(FwType::RustHypervisorFirmware).as_str()]) |
| 5478 | .args(["--serial", "tty", "--console", "off"]) |
| 5479 | .default_disks() |
| 5480 | .default_net() |
| 5481 | .capture_output() |
| 5482 | .spawn() |
| 5483 | .unwrap(); |
| 5484 | |
| 5485 | let r = std::panic::catch_unwind(|| { |
| 5486 | guest.wait_vm_boot().unwrap(); |
| 5487 | |
| 5488 | // Hotplug the SPDK-NVMe device to the VM |
| 5489 | let (cmd_success, cmd_output, _) = remote_command_w_output( |
| 5490 | &api_socket, |
| 5491 | "add-user-device", |
| 5492 | Some(&format!( |
| 5493 | "socket={},id=vfio_user0", |
| 5494 | spdk_nvme_dir |
| 5495 | .as_path() |
| 5496 | .join("nvme-vfio-user/cntrl") |
| 5497 | .to_str() |
| 5498 | .unwrap(), |
| 5499 | )), |
| 5500 | ); |
| 5501 | assert!(cmd_success); |
| 5502 | assert!( |
| 5503 | String::from_utf8_lossy(&cmd_output) |
| 5504 | .contains("{\"id\":\"vfio_user0\",\"bdf\":\"0000:00:05.0\"}") |
| 5505 | ); |
| 5506 | |
| 5507 | // Check both if /dev/nvme exists and if the block size is 128M. |
| 5508 | assert!(wait_until(Duration::from_secs(10), || { |
| 5509 | guest |
| 5510 | .ssh_command("lsblk | grep nvme0n1 | grep -c 128M") |
| 5511 | .ok() |
| 5512 | .and_then(|output| output.trim().parse::<u32>().ok()) |
| 5513 | == Some(1) |
| 5514 | })); |
| 5515 | |
| 5516 | // Check changes persist after reboot |
| 5517 | assert_eq!( |
| 5518 | guest.ssh_command("sudo mount /dev/nvme0n1 /mnt").unwrap(), |
| 5519 | "" |
| 5520 | ); |
| 5521 | assert_eq!(guest.ssh_command("ls /mnt").unwrap(), "lost+found\n"); |
nothing calls this directly
no test coverage detected