mod.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2022 The ChromiumOS Authors
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #![cfg(any(target_os = "android", target_os = "linux"))]
  5. mod x86_64;
  6. use devices::irqchip::IrqChip;
  7. use devices::irqchip::KvmKernelIrqChip;
  8. use hypervisor::kvm::Kvm;
  9. use hypervisor::kvm::KvmVm;
  10. use hypervisor::MPState;
  11. use hypervisor::Vm;
  12. #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
  13. use hypervisor::VmAArch64;
  14. #[cfg(target_arch = "riscv64")]
  15. use hypervisor::VmRiscv64;
  16. #[cfg(target_arch = "x86_64")]
  17. use hypervisor::VmX86_64;
  18. use vm_memory::GuestMemory;
  19. #[test]
  20. fn create_kvm_kernel_irqchip() {
  21. let kvm = Kvm::new().expect("failed to instantiate Kvm");
  22. let mem = GuestMemory::new(&[]).unwrap();
  23. let vm = KvmVm::new(&kvm, mem, Default::default()).expect("failed to instantiate vm");
  24. let mut chip = KvmKernelIrqChip::new(vm.try_clone().expect("failed to clone vm"), 1)
  25. .expect("failed to instantiate KvmKernelIrqChip");
  26. let vcpu = vm.create_vcpu(0).expect("failed to instantiate vcpu");
  27. chip.add_vcpu(0, vcpu.as_vcpu())
  28. .expect("failed to add vcpu");
  29. }
  30. #[test]
  31. fn mp_state() {
  32. let kvm = Kvm::new().expect("failed to instantiate Kvm");
  33. let mem = GuestMemory::new(&[]).unwrap();
  34. let vm = KvmVm::new(&kvm, mem, Default::default()).expect("failed to instantiate vm");
  35. let mut chip = KvmKernelIrqChip::new(vm.try_clone().expect("failed to clone vm"), 1)
  36. .expect("failed to instantiate KvmKernelIrqChip");
  37. let vcpu = vm.create_vcpu(0).expect("failed to instantiate vcpu");
  38. chip.add_vcpu(0, vcpu.as_vcpu())
  39. .expect("failed to add vcpu");
  40. let state = chip.get_mp_state(0).expect("failed to get mp state");
  41. assert_eq!(state, MPState::Runnable);
  42. let new_mpstate = if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
  43. MPState::Stopped
  44. } else if cfg!(target_arch = "x86_64") {
  45. MPState::Halted
  46. } else {
  47. unimplemented!();
  48. };
  49. chip.set_mp_state(0, &new_mpstate)
  50. .expect("failed to set mp state");
  51. let state = chip.get_mp_state(0).expect("failed to get mp state");
  52. assert_eq!(state, new_mpstate);
  53. }