crosvm: Add integration test case for O_DIRECT.

Make sure we keep booting.

BUG=b:190435784
BUG=b:184204645
TEST=boot tests (boot_test_suspend_resume, boot_test_vm) pass.

Change-Id: I586e555ae83759c88759e1aeb96a728785d0cf5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3055557
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Junichi Uekawa 2021-07-26 15:50:50 +09:00 committed by Commit Bot
parent 74b18b8ccb
commit 7cbd02f109
2 changed files with 17 additions and 6 deletions

View file

@ -6,7 +6,13 @@ use fixture::TestVm;
#[test]
fn boot_test_vm() {
let mut vm = TestVm::new(&[], false).unwrap();
let mut vm = TestVm::new(&[], false /* debug */, false /* o_direct */).unwrap();
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
}
#[test]
fn boot_test_vm_odirect() {
let mut vm = TestVm::new(&[], false /* debug */, true /* o_direct */).unwrap();
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
}
@ -14,7 +20,7 @@ fn boot_test_vm() {
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).unwrap();
let mut vm = TestVm::new(&[], false /* debug */, false /*o_direct */).unwrap();
vm.suspend().unwrap();
vm.resume().unwrap();
assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");

View file

@ -230,16 +230,21 @@ impl TestVm {
}
/// Configures the VM kernel and rootfs to load from the guest_under_test assets.
fn configure_kernel(command: &mut Command) {
fn configure_kernel(command: &mut Command, o_direct: bool) {
let rootfs_and_option = format!(
"{}{}",
rootfs_path().to_str().unwrap(),
if o_direct { ",o_direct=true" } else { "" }
);
command
.args(&["--root", rootfs_path().to_str().unwrap()])
.args(&["--root", &rootfs_and_option])
.args(&["--params", "init=/bin/delegate"])
.arg(kernel_path());
}
/// Instanciate a new crosvm instance. The first call will trigger the download of prebuilt
/// files if necessary.
pub fn new(additional_arguments: &[&str], debug: bool) -> Result<TestVm> {
pub fn new(additional_arguments: &[&str], debug: bool, o_direct: bool) -> Result<TestVm> {
static PREP_ONCE: Once = Once::new();
PREP_ONCE.call_once(|| TestVm::initialize_once());
@ -258,7 +263,7 @@ impl TestVm {
command.args(&["--socket", &control_socket_path.to_str().unwrap()]);
command.args(additional_arguments);
TestVm::configure_kernel(&mut command);
TestVm::configure_kernel(&mut command, o_direct);
println!("$ {:?}", command);
if !debug {