pub struct TestVm {
sys: TestVmSys,
ready: bool,
sudo: bool,
}Expand description
Test fixture to spin up a VM running a guest that can be communicated with.
After creation, commands can be sent via exec_in_guest. The VM is stopped when this instance is dropped.
Fields§
§sys: TestVmSys§ready: bool§sudo: boolImplementations§
Source§impl TestVm
impl TestVm
Sourcefn initialize_once()
fn initialize_once()
Downloads prebuilts if needed.
fn initiailize_artifacts(cfg: &Config)
Sourcepub fn new_generic<F>(f: F, cfg: Config, sudo: bool) -> Result<TestVm>
pub fn new_generic<F>(f: F, cfg: Config, sudo: bool) -> Result<TestVm>
Instanciate a new crosvm instance. The first call will trigger the download of prebuilt files if necessary.
This generic method takes a FnOnce argument which is in charge of completing the Command
with all the relevant options needed to boot the VM.
pub fn new_generic_restore<F>(f: F, cfg: Config, sudo: bool) -> Result<TestVm>
pub fn new(cfg: Config) -> Result<TestVm>
Sourcepub fn new_restore(cfg: Config) -> Result<TestVm>
pub fn new_restore(cfg: Config) -> Result<TestVm>
Create TestVm from a snapshot, using --restore but NOT --suspended.
Sourcepub fn new_restore_suspended(cfg: Config) -> Result<TestVm>
pub fn new_restore_suspended(cfg: Config) -> Result<TestVm>
Create TestVm from a snapshot, using --restore AND --suspended.
pub fn new_sudo(cfg: Config) -> Result<TestVm>
Sourcepub fn exec_in_guest(&mut self, command: &str) -> Result<ProgramExit>
pub fn exec_in_guest(&mut self, command: &str) -> Result<ProgramExit>
Executes the provided command in the guest. Returns command output as Ok(ProgramExit), or an Error if the program did not exit with 0.
Sourcepub fn exec_in_guest_unchecked(&mut self, command: &str) -> Result<ProgramExit>
pub fn exec_in_guest_unchecked(&mut self, command: &str) -> Result<ProgramExit>
Same as exec_in_guest but will return Ok(ProgramExit) instead of failing on a
non-zero exit code.
Sourcepub fn exec_in_guest_async(&mut self, command: &str) -> Result<GuestProcess>
pub fn exec_in_guest_async(&mut self, command: &str) -> Result<GuestProcess>
Executes the provided command in the guest asynchronously. The command will be run in the guest, but output will not be read until GuestProcess::wait_ok() or GuestProcess::wait_result() is called.
fn wait_for_guest_ready(&mut self, timeout: Duration) -> Result<()>
Sourcefn read_message_from_guest(
&mut self,
timeout: Duration,
) -> Result<GuestToHostMessage>
fn read_message_from_guest( &mut self, timeout: Duration, ) -> Result<GuestToHostMessage>
Reads one line via the from_guest pipe from the guest delegate.
Sourcefn write_message_to_guest(
&mut self,
data: &HostToGuestMessage,
timeout: Duration,
) -> Result<()>
fn write_message_to_guest( &mut self, data: &HostToGuestMessage, timeout: Duration, ) -> Result<()>
Send one line via the to_guest pipe to the guest delegate.
Sourcepub fn hotplug_tap(&mut self, tap_name: &str) -> Result<()>
pub fn hotplug_tap(&mut self, tap_name: &str) -> Result<()>
Hotplug a tap device.
Sourcepub fn remove_pci_device(&mut self, bus_num: u8) -> Result<()>
pub fn remove_pci_device(&mut self, bus_num: u8) -> Result<()>
Remove hotplugged device on bus.