From 9ac06bf613413d7ce4fa20ba61124ed0de05e3de Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 21 Jan 2020 09:32:50 +0100 Subject: [PATCH] ci: Run clippy for each specific feature The build is run against "--all-features", "pci,acpi", "pci" and "mmio" separately. The clippy validation must be run against the same set of features in order to validate the code is correct. Because of these new checks, this commit includes multiple fixes related to the errors generated when manually running the checks. Signed-off-by: Sebastien Boeuf --- scripts/run_cargo_tests.sh | 5 ++++- vm-virtio/src/lib.rs | 1 + vmm/src/cpu.rs | 6 ++++++ vmm/src/device_manager.rs | 16 +++++++++++++--- vmm/src/memory_manager.rs | 4 ++++ vmm/src/vm.rs | 1 - 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/scripts/run_cargo_tests.sh b/scripts/run_cargo_tests.sh index aff8c45b9..8f9d46846 100755 --- a/scripts/run_cargo_tests.sh +++ b/scripts/run_cargo_tests.sh @@ -10,15 +10,18 @@ time rustup component add rustfmt time cargo install --force cargo-audit # Run cargo builds and checks +time cargo clippy --all-targets --all-features -- -D warnings time cargo rustc --bin cloud-hypervisor -- -D warnings time cargo rustc --bin vhost_user_net -- -D warnings time cargo test time cargo audit +time cargo clippy --all-targets --no-default-features --features "pci,acpi" -- -D warnings time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci,acpi" -- -D warnings time cargo rustc --bin vhost_user_net --no-default-features --features "pci,acpi" -- -D warnings -time cargo clippy --all-targets --all-features -- -D warnings +time cargo clippy --all-targets --no-default-features --features "pci" -- -D warnings time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci" -- -D warnings time cargo rustc --bin vhost_user_net --no-default-features --features "pci" -- -D warnings +time cargo clippy --all-targets --no-default-features --features "mmio" -- -D warnings time cargo rustc --bin cloud-hypervisor --no-default-features --features "mmio" -- -D warnings time cargo rustc --bin vhost_user_net --no-default-features --features "mmio" -- -D warnings time sh -c 'find . \( -name "*.rs" ! -wholename "*/out/*.rs" \) | xargs rustfmt --check' diff --git a/vm-virtio/src/lib.rs b/vm-virtio/src/lib.rs index 593f34e7b..9154eb549 100755 --- a/vm-virtio/src/lib.rs +++ b/vm-virtio/src/lib.rs @@ -130,6 +130,7 @@ impl fmt::Display for VirtioDeviceType { const INTERRUPT_STATUS_USED_RING: u32 = 0x1; #[allow(dead_code)] const INTERRUPT_STATUS_CONFIG_CHANGED: u32 = 0x2; +#[cfg(feature = "pci_support")] const VIRTIO_MSI_NO_VECTOR: u16 = 0xffff; #[derive(Debug)] diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index a1e67f47d..7610951b2 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -12,6 +12,7 @@ use crate::device_manager::DeviceManager; #[cfg(feature = "acpi")] use acpi_tables::{aml, aml::Aml, sdt::SDT}; use arc_swap::ArcSwap; +#[cfg(feature = "acpi")] use arch::layout; use devices::{ioapic, BusDevice}; use kvm_bindings::CpuId; @@ -197,6 +198,7 @@ impl CpuidPatch { } } +#[cfg(feature = "acpi")] #[repr(packed)] struct LocalAPIC { pub r#type: u8, @@ -747,10 +749,12 @@ impl CpuManager { } } +#[cfg(feature = "acpi")] struct CPU { cpu_id: u8, } +#[cfg(feature = "acpi")] const MADT_CPU_ENABLE_FLAG: usize = 0; #[cfg(feature = "acpi")] @@ -813,6 +817,7 @@ impl Aml for CPU { } } +#[cfg(feature = "acpi")] struct CPUNotify { cpu_id: u8, } @@ -829,6 +834,7 @@ impl Aml for CPUNotify { } } +#[cfg(feature = "acpi")] struct CPUMethods { max_vcpus: u8, } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 88d65ec61..8a1ba8e2e 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -11,13 +11,16 @@ extern crate vm_device; -use crate::config::{ConsoleOutputMode, VmConfig}; +use crate::config::ConsoleOutputMode; +#[cfg(feature = "acpi")] +use crate::config::VmConfig; use crate::interrupt::{KvmInterruptManager, KvmRoutingEntry}; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager}; use crate::vm::VmInfo; #[cfg(feature = "acpi")] use acpi_tables::{aml, aml::Aml}; use arc_swap::ArcSwap; +#[cfg(feature = "acpi")] use arch::layout; use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use devices::{ioapic, HotPlugNotificationFlags}; @@ -380,12 +383,14 @@ pub struct DeviceManager { ged_notification_device: Option>>, // VM configuration + #[cfg(feature = "acpi")] config: Arc>, // Migratable devices migratable_devices: Vec>>, // Memory Manager + #[cfg(feature = "acpi")] memory_manager: Arc>, } @@ -486,7 +491,10 @@ impl DeviceManager { )?; } + #[cfg(feature = "acpi")] let config = vm_info.vm_cfg.clone(); + #[cfg(feature = "acpi")] + let memory_manager_clone = memory_manager.clone(); address_manager .allocator @@ -497,7 +505,7 @@ impl DeviceManager { address_manager .io_bus - .insert(memory_manager.clone(), 0xa00, 0x18) + .insert(memory_manager, 0xa00, 0x18) .map_err(DeviceManagerError::BusError)?; Ok(DeviceManager { @@ -509,9 +517,11 @@ impl DeviceManager { virt_iommu, #[cfg(feature = "acpi")] ged_notification_device, + #[cfg(feature = "acpi")] config, migratable_devices, - memory_manager, + #[cfg(feature = "acpi")] + memory_manager: memory_manager_clone, }) } diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index 4e6644b38..530aad3e2 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -462,6 +462,7 @@ impl MemoryManager { } } +#[cfg(feature = "acpi")] struct MemoryNotify { slot_id: usize, } @@ -478,6 +479,7 @@ impl Aml for MemoryNotify { } } +#[cfg(feature = "acpi")] struct MemorySlot { slot_id: usize, } @@ -534,6 +536,7 @@ impl Aml for MemorySlot { } } +#[cfg(feature = "acpi")] struct MemorySlots { slots: usize, } @@ -551,6 +554,7 @@ impl Aml for MemorySlots { } } +#[cfg(feature = "acpi")] struct MemoryMethods { slots: usize, } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 37efb8ae7..c77ff01d5 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -695,7 +695,6 @@ mod tests { assert!(state.valid_transition(VmState::Shutdown).is_ok()); assert!(state.valid_transition(VmState::Paused).is_err()); } - _ => {} } }