mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 12:35:26 +00:00
Vcpus are created on the Vm object, instead of with Vcpu::new. Vm keeps a copy of the Hypervisor to support create_vcpu. Otherwise the methods are the same as the kvm crate. BUG=chromium:1077058 TEST=cargo test Change-Id: I6fbd0e5fb5d81d4362a259e85eb392d8edbfff1f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2247366 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Steven Richman <srichman@google.com>
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
// Copyright 2020 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// TODO: Delete these tests soon, once we start getting real implementations in place.
|
|
|
|
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
|
mod test_concrete_aarch64;
|
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
|
mod test_concrete_x86_64;
|
|
|
|
use sys_util::GuestMemory;
|
|
|
|
use hypervisor::*;
|
|
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
|
use test_concrete_aarch64::*;
|
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
|
use test_concrete_x86_64::*;
|
|
|
|
fn run_vcpu<T, U, V>(_hypervm: &HyperVm<T, U, V>, _linux: &RunnableLinuxVm, vcpu: impl Vcpu)
|
|
where
|
|
T: Hypervisor,
|
|
U: Vm,
|
|
V: Vcpu,
|
|
{
|
|
let vcpu = vcpu.to_runnable().unwrap();
|
|
// Tests that run() is callable, but vcpu isn't set up, so run will return an Error.
|
|
assert!(vcpu.run().is_err());
|
|
vcpu.request_interrupt_window().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_concrete_types() {
|
|
let cfg_use_kvm = true;
|
|
if cfg_use_kvm {
|
|
let hypervisor = kvm::Kvm::new().unwrap();
|
|
let mem = GuestMemory::new(&[]).unwrap();
|
|
let vm = kvm::KvmVm::new(&hypervisor, mem).unwrap();
|
|
let vcpu = vm.create_vcpu(0).unwrap();
|
|
let mut vcpus = vec![vcpu];
|
|
let mut hypervm = HyperVm {
|
|
hypervisor,
|
|
vm,
|
|
vcpus,
|
|
};
|
|
let linux = configure_vm(&hypervm);
|
|
vcpus = hypervm.vcpus.split_off(0);
|
|
for vcpu in vcpus.into_iter() {
|
|
run_vcpu(&hypervm, &linux, vcpu);
|
|
}
|
|
}
|
|
}
|