Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions vm/devices/virtio/virtio/src/tests/saved_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,28 @@ async fn mmio_restore_rejects_missing_active_queue_progress(driver: DefaultDrive
assert!(destination.restore(saved).await.is_err());
}

#[async_test]
async fn pci_restore_rejects_missing_active_queue_progress(driver: DefaultDriver) {
use vmcore::save_restore::AsyncSaveRestore;

let test_mem = VirtioTestMemoryAccess::new();
let mut saved = save_active_private_pci(&driver, &test_mem).await;
assert!(saved.queues[0].common.enable);
assert!(saved.queues[0].common.queue_state.take().is_some());
let (device, probe) = PrivateStateTestDevice::new(0, 1, false);
let mut destination =
VirtioPciTestDevice::new_with_device(&driver, &test_mem, Box::new(device));

let error = destination.pci_device.restore(saved).await.unwrap_err();
assert!(
error_chain(&error).contains("missing progress state"),
"{error:?}"
);
// Validation rejects the state before the device sees it.
assert_eq!(probe.restore_count.load(Ordering::Relaxed), 0);
assert_eq!(probe.start_count.load(Ordering::Relaxed), 0);
}

#[async_test]
async fn mmio_private_state_round_trip(driver: DefaultDriver) {
use crate::spec::mmio::VirtioMmioRegister;
Expand Down Expand Up @@ -564,6 +586,30 @@ async fn mmio_resave_before_first_start_keeps_restored_state(driver: DefaultDriv
assert_eq!(saved_value(resaved.device_state), 42);
}

#[async_test]
async fn pci_resave_before_first_start_keeps_restored_state(driver: DefaultDriver) {
use vmcore::save_restore::AsyncSaveRestore;

let test_mem = VirtioTestMemoryAccess::new();
let saved = save_active_private_pci(&driver, &test_mem).await;
let (device, probe) = PrivateStateTestDevice::new(0, 1, false);
let mut destination =
VirtioPciTestDevice::new_with_device(&driver, &test_mem, Box::new(device));

destination.pci_device.restore(saved).await.unwrap();
destination.pci_device.stop().await;
let resaved = destination.pci_device.save().await.unwrap();
assert_eq!(probe.start_count.load(Ordering::Relaxed), 0);
assert_eq!(
resaved.queues[0].common.queue_state,
Some(QueueState {
avail_index: 3,
used_index: 1,
})
);
assert_eq!(saved_value(resaved.device_state), 42);
}

#[async_test]
async fn mmio_active_zero_queue_device_restores_private_state(driver: DefaultDriver) {
use vmcore::save_restore::AsyncSaveRestore;
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtio_net/src/tests/saved_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Saved-state tests: stopping the queues rewinds unused RX descriptors,
//! partial queue lifecycles are saved and validated, and an inactive transport
//! defers the device-private state until the device is activated.
//! restores the device-private state before any queue starts.

use super::QUEUE_SIZE;
use super::RX_AVAIL_ADDR;
Expand Down
Loading