mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 10:10:41 +00:00
integration_tests: Define Config struct
Define `struct Config` to specify crosvm arguments so it'll make it easier to add more complicated arguments in future CLs. BUG=b:220292205 TEST=./integration_tests/run Change-Id: I89921e171a81071dbfc58d22b233e9c71abcdf54 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686717 Reviewed-by: Dennis Kempin <denniskempin@google.com> Reviewed-by: Junichi Uekawa <uekawa@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
f54f7ed040
commit
0974be8042
2 changed files with 37 additions and 7 deletions
|
@ -2,17 +2,17 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
mod fixture;
|
||||
use fixture::TestVm;
|
||||
use fixture::{Config, TestVm};
|
||||
|
||||
#[test]
|
||||
fn boot_test_vm() {
|
||||
let mut vm = TestVm::new(&[], false /* o_direct */).unwrap();
|
||||
let mut vm = TestVm::new(Config::new()).unwrap();
|
||||
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boot_test_vm_odirect() {
|
||||
let mut vm = TestVm::new(&[], true /* o_direct */).unwrap();
|
||||
let mut vm = TestVm::new(Config::new().o_direct()).unwrap();
|
||||
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn boot_test_vm_odirect() {
|
|||
fn boot_test_suspend_resume() {
|
||||
// There is no easy way for us to check if the VM is actually suspended. But at
|
||||
// least exercise the code-path.
|
||||
let mut vm = TestVm::new(&[], false /*o_direct */).unwrap();
|
||||
let mut vm = TestVm::new(Config::new()).unwrap();
|
||||
vm.suspend().unwrap();
|
||||
vm.resume().unwrap();
|
||||
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
|
||||
|
|
|
@ -142,6 +142,36 @@ fn download_file(url: &str, destination: &Path) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Configuration to start `TestVm`.
|
||||
#[derive(Default)]
|
||||
pub struct Config {
|
||||
/// Extra arguments for the `run` subcommand.
|
||||
extra_args: Vec<String>,
|
||||
|
||||
/// Use `O_DIRECT` for the rootfs.
|
||||
o_direct: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Creates a new `run` command with `extra_args`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Uses extra arguments for `crosvm run`.
|
||||
#[allow(dead_code)]
|
||||
pub fn extra_args(mut self, args: Vec<String>) -> Self {
|
||||
self.extra_args = args;
|
||||
self
|
||||
}
|
||||
|
||||
/// Uses `O_DIRECT` for the rootfs.
|
||||
pub fn o_direct(mut self) -> Self {
|
||||
self.o_direct = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
@ -246,7 +276,7 @@ impl TestVm {
|
|||
|
||||
/// Instanciate a new crosvm instance. The first call will trigger the download of prebuilt
|
||||
/// files if necessary.
|
||||
pub fn new(additional_arguments: &[&str], o_direct: bool) -> Result<TestVm> {
|
||||
pub fn new(cfg: Config) -> Result<TestVm> {
|
||||
static PREP_ONCE: Once = Once::new();
|
||||
PREP_ONCE.call_once(TestVm::initialize_once);
|
||||
|
||||
|
@ -263,9 +293,9 @@ impl TestVm {
|
|||
command.args(&["run", "--disable-sandbox"]);
|
||||
TestVm::configure_serial_devices(&mut command, &from_guest_pipe, &to_guest_pipe);
|
||||
command.args(&["--socket", control_socket_path.to_str().unwrap()]);
|
||||
command.args(additional_arguments);
|
||||
command.args(cfg.extra_args);
|
||||
|
||||
TestVm::configure_kernel(&mut command, o_direct);
|
||||
TestVm::configure_kernel(&mut command, cfg.o_direct);
|
||||
|
||||
// Set `Stdio::piped` so we can forward the outputs to stdout later.
|
||||
command.stdout(Stdio::piped());
|
||||
|
|
Loading…
Reference in a new issue