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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-01-21 09:32:50 +01:00
parent e91638e6c5
commit 9ac06bf613
6 changed files with 28 additions and 5 deletions

View File

@ -10,15 +10,18 @@ time rustup component add rustfmt
time cargo install --force cargo-audit time cargo install --force cargo-audit
# Run cargo builds and checks # 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 cloud-hypervisor -- -D warnings
time cargo rustc --bin vhost_user_net -- -D warnings time cargo rustc --bin vhost_user_net -- -D warnings
time cargo test time cargo test
time cargo audit 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 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 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 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 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 cloud-hypervisor --no-default-features --features "mmio" -- -D warnings
time cargo rustc --bin vhost_user_net --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' time sh -c 'find . \( -name "*.rs" ! -wholename "*/out/*.rs" \) | xargs rustfmt --check'

View File

@ -130,6 +130,7 @@ impl fmt::Display for VirtioDeviceType {
const INTERRUPT_STATUS_USED_RING: u32 = 0x1; const INTERRUPT_STATUS_USED_RING: u32 = 0x1;
#[allow(dead_code)] #[allow(dead_code)]
const INTERRUPT_STATUS_CONFIG_CHANGED: u32 = 0x2; const INTERRUPT_STATUS_CONFIG_CHANGED: u32 = 0x2;
#[cfg(feature = "pci_support")]
const VIRTIO_MSI_NO_VECTOR: u16 = 0xffff; const VIRTIO_MSI_NO_VECTOR: u16 = 0xffff;
#[derive(Debug)] #[derive(Debug)]

View File

@ -12,6 +12,7 @@ use crate::device_manager::DeviceManager;
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
use acpi_tables::{aml, aml::Aml, sdt::SDT}; use acpi_tables::{aml, aml::Aml, sdt::SDT};
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
#[cfg(feature = "acpi")]
use arch::layout; use arch::layout;
use devices::{ioapic, BusDevice}; use devices::{ioapic, BusDevice};
use kvm_bindings::CpuId; use kvm_bindings::CpuId;
@ -197,6 +198,7 @@ impl CpuidPatch {
} }
} }
#[cfg(feature = "acpi")]
#[repr(packed)] #[repr(packed)]
struct LocalAPIC { struct LocalAPIC {
pub r#type: u8, pub r#type: u8,
@ -747,10 +749,12 @@ impl CpuManager {
} }
} }
#[cfg(feature = "acpi")]
struct CPU { struct CPU {
cpu_id: u8, cpu_id: u8,
} }
#[cfg(feature = "acpi")]
const MADT_CPU_ENABLE_FLAG: usize = 0; const MADT_CPU_ENABLE_FLAG: usize = 0;
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
@ -813,6 +817,7 @@ impl Aml for CPU {
} }
} }
#[cfg(feature = "acpi")]
struct CPUNotify { struct CPUNotify {
cpu_id: u8, cpu_id: u8,
} }
@ -829,6 +834,7 @@ impl Aml for CPUNotify {
} }
} }
#[cfg(feature = "acpi")]
struct CPUMethods { struct CPUMethods {
max_vcpus: u8, max_vcpus: u8,
} }

View File

@ -11,13 +11,16 @@
extern crate vm_device; 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::interrupt::{KvmInterruptManager, KvmRoutingEntry};
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager}; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager};
use crate::vm::VmInfo; use crate::vm::VmInfo;
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
use acpi_tables::{aml, aml::Aml}; use acpi_tables::{aml, aml::Aml};
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
#[cfg(feature = "acpi")]
use arch::layout; use arch::layout;
use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START};
use devices::{ioapic, HotPlugNotificationFlags}; use devices::{ioapic, HotPlugNotificationFlags};
@ -380,12 +383,14 @@ pub struct DeviceManager {
ged_notification_device: Option<Arc<Mutex<devices::AcpiGEDDevice>>>, ged_notification_device: Option<Arc<Mutex<devices::AcpiGEDDevice>>>,
// VM configuration // VM configuration
#[cfg(feature = "acpi")]
config: Arc<Mutex<VmConfig>>, config: Arc<Mutex<VmConfig>>,
// Migratable devices // Migratable devices
migratable_devices: Vec<Arc<Mutex<dyn Migratable>>>, migratable_devices: Vec<Arc<Mutex<dyn Migratable>>>,
// Memory Manager // Memory Manager
#[cfg(feature = "acpi")]
memory_manager: Arc<Mutex<MemoryManager>>, memory_manager: Arc<Mutex<MemoryManager>>,
} }
@ -486,7 +491,10 @@ impl DeviceManager {
)?; )?;
} }
#[cfg(feature = "acpi")]
let config = vm_info.vm_cfg.clone(); let config = vm_info.vm_cfg.clone();
#[cfg(feature = "acpi")]
let memory_manager_clone = memory_manager.clone();
address_manager address_manager
.allocator .allocator
@ -497,7 +505,7 @@ impl DeviceManager {
address_manager address_manager
.io_bus .io_bus
.insert(memory_manager.clone(), 0xa00, 0x18) .insert(memory_manager, 0xa00, 0x18)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
Ok(DeviceManager { Ok(DeviceManager {
@ -509,9 +517,11 @@ impl DeviceManager {
virt_iommu, virt_iommu,
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
ged_notification_device, ged_notification_device,
#[cfg(feature = "acpi")]
config, config,
migratable_devices, migratable_devices,
memory_manager, #[cfg(feature = "acpi")]
memory_manager: memory_manager_clone,
}) })
} }

View File

@ -462,6 +462,7 @@ impl MemoryManager {
} }
} }
#[cfg(feature = "acpi")]
struct MemoryNotify { struct MemoryNotify {
slot_id: usize, slot_id: usize,
} }
@ -478,6 +479,7 @@ impl Aml for MemoryNotify {
} }
} }
#[cfg(feature = "acpi")]
struct MemorySlot { struct MemorySlot {
slot_id: usize, slot_id: usize,
} }
@ -534,6 +536,7 @@ impl Aml for MemorySlot {
} }
} }
#[cfg(feature = "acpi")]
struct MemorySlots { struct MemorySlots {
slots: usize, slots: usize,
} }
@ -551,6 +554,7 @@ impl Aml for MemorySlots {
} }
} }
#[cfg(feature = "acpi")]
struct MemoryMethods { struct MemoryMethods {
slots: usize, slots: usize,
} }

View File

@ -695,7 +695,6 @@ mod tests {
assert!(state.valid_transition(VmState::Shutdown).is_ok()); assert!(state.valid_transition(VmState::Shutdown).is_ok());
assert!(state.valid_transition(VmState::Paused).is_err()); assert!(state.valid_transition(VmState::Paused).is_err());
} }
_ => {}
} }
} }