Struct fixture::vm::TestVm

source ·
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: bool

Implementations§

source§

impl TestVm

source

fn initialize_once()

Downloads prebuilts if needed.

source

fn initiailize_artifacts(cfg: &Config)

source

pub fn new_generic<F>(f: F, cfg: Config, sudo: bool) -> Result<TestVm>
where F: FnOnce(&mut Command, &Path, &Config) -> Result<()>,

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.

source

pub fn new_generic_restore<F>(f: F, cfg: Config, sudo: bool) -> Result<TestVm>
where F: FnOnce(&mut Command, &Path, &Config) -> Result<()>,

source

pub fn new(cfg: Config) -> Result<TestVm>

source

pub fn new_restore(cfg: Config) -> Result<TestVm>

Create TestVm from a snapshot, using --restore but NOT --suspended.

source

pub fn new_restore_suspended(cfg: Config) -> Result<TestVm>

Create TestVm from a snapshot, using --restore AND --suspended.

source

pub fn new_sudo(cfg: Config) -> Result<TestVm>

source

pub fn new_with_config_file(cfg: Config) -> Result<TestVm>

Instanciate a new crosvm instance using a configuration file. The first call will trigger the download of prebuilt files if necessary.

source

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.

source

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.

source

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.

source

fn wait_for_guest_ready(&mut self, timeout: Duration) -> Result<()>

source

fn read_message_from_guest( &mut self, timeout: Duration ) -> Result<GuestToHostMessage>

Reads one line via the from_guest pipe from the guest delegate.

source

fn write_message_to_guest( &mut self, data: &HostToGuestMessage, timeout: Duration ) -> Result<()>

Send one line via the to_guest pipe to the guest delegate.

source

pub fn hotplug_tap(&mut self, tap_name: &str) -> Result<()>

Hotplug a tap device.

source

pub fn remove_pci_device(&mut self, bus_num: u8) -> Result<()>

Remove hotplugged device on bus.

source

pub fn stop(&mut self) -> Result<()>

source

pub fn suspend(&mut self) -> Result<()>

source

pub fn suspend_full(&mut self) -> Result<()>

source

pub fn resume(&mut self) -> Result<()>

source

pub fn resume_full(&mut self) -> Result<()>

source

pub fn disk(&mut self, args: Vec<String>) -> Result<()>

source

pub fn snapshot(&mut self, filename: &Path) -> Result<()>

source

pub fn restore(&mut self, filename: &Path) -> Result<()>

source

pub fn swap_command(&mut self, command: &str) -> Result<Vec<u8>>

source

pub fn guest_clock_values(&mut self) -> Result<ClockValues>

Trait Implementations§

source§

impl Drop for TestVm

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.