From 039fe7f3917cfbe44c7498e5d089d78570003422 Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Mon, 18 Dec 2023 14:51:10 +0800 Subject: [PATCH] dragonball: Trigger unit tests of dbs_* subcrates by `make test` `make SUPPORT_VIRTUALIZATION=1 test` iterates through all subcrates and does test. Plus, this patch fixes some issues about unit tests: - Feed too much parameters to `I8042Device::new()`. - Virtqueue checks have been introduced since `virtio-queue v0.7.0`. - GHA might have no access to `/var/tmp` dir on runner. Fixes: #8690 Signed-off-by: Xuewei Niu --- src/dragonball/Makefile | 7 ++++- .../src/dbs_legacy_devices/src/i8042.rs | 6 ++--- .../src/dbs_virtio_devices/src/device.rs | 26 ++++++++++++++----- .../src/vhost/vhost_user/fs.rs | 4 +-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/dragonball/Makefile b/src/dragonball/Makefile index a8b86d47f1..df24d78ed3 100644 --- a/src/dragonball/Makefile +++ b/src/dragonball/Makefile @@ -4,6 +4,8 @@ include ../../utils.mk +PROJECT_DIRS := $(shell find . -name Cargo.toml -printf '%h\n' | sort -u) + ifeq ($(ARCH), s390x) default build check test clippy: @echo "s390x not support currently" @@ -40,7 +42,10 @@ clean: test: ifdef SUPPORT_VIRTUALIZATION - RUST_BACKTRACE=1 cargo test --all-features --target $(TRIPLE) -- --nocapture --test-threads=1 + @set -e; \ + for dir in $(PROJECT_DIRS); do \ + bash -c "pushd $${dir} && RUST_BACKTRACE=1 cargo test --all-features --target $(TRIPLE) -- --nocapture --test-threads=1 && popd"; \ + done else @echo "INFO: skip testing dragonball, it need virtualization support." exit 0 diff --git a/src/dragonball/src/dbs_legacy_devices/src/i8042.rs b/src/dragonball/src/dbs_legacy_devices/src/i8042.rs index 5fc4e8f3fd..9d4bce87ca 100644 --- a/src/dragonball/src/dbs_legacy_devices/src/i8042.rs +++ b/src/dragonball/src/dbs_legacy_devices/src/i8042.rs @@ -86,7 +86,7 @@ mod tests { fn test_i8042_valid_ops() { let reset_evt = EventFdTrigger::new(EventFd::new(libc::EFD_NONBLOCK).unwrap()); let metrics = Arc::new(I8042DeviceMetrics::default()); - let mut i8042 = I8042Device::new(reset_evt.try_clone().unwrap(), metrics); + let mut i8042 = I8042Device::new(reset_evt.try_clone().unwrap()); let mut v = [0x00u8; 1]; i8042.pio_read(PioAddress(0), PioAddress(0), &mut v); @@ -107,7 +107,7 @@ mod tests { fn test_i8042_invalid_ops() { let reset_evt = EventFdTrigger::new(EventFd::new(libc::EFD_NONBLOCK).unwrap()); let metrics = Arc::new(I8042DeviceMetrics::default()); - let mut i8042 = I8042Device::new(reset_evt.try_clone().unwrap(), metrics); + let mut i8042 = I8042Device::new(reset_evt.try_clone().unwrap()); let mut v = [0x00u8; 2]; i8042.pio_read(PioAddress(0), PioAddress(0), &mut v); @@ -128,7 +128,7 @@ mod tests { fn test_i8042_reset_err() { let reset_evt = EventFdTrigger::new(unsafe { EventFd::from_raw_fd(i32::MAX) }); let metrics = Arc::new(I8042DeviceMetrics::default()); - let mut i8042 = I8042Device::new(reset_evt, metrics); + let mut i8042 = I8042Device::new(reset_evt); i8042.pio_write( PioAddress(0), PioAddress(COMMAND_OFFSET as u16), diff --git a/src/dragonball/src/dbs_virtio_devices/src/device.rs b/src/dragonball/src/dbs_virtio_devices/src/device.rs index 8ba641df44..ffe2ae28a3 100644 --- a/src/dragonball/src/dbs_virtio_devices/src/device.rs +++ b/src/dragonball/src/dbs_virtio_devices/src/device.rs @@ -576,6 +576,7 @@ pub(crate) mod tests { use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap, GuestMemoryRegion, MmapRegion}; use super::*; + use crate::tests::VirtQueue; use crate::{VIRTIO_INTR_CONFIG, VIRTIO_INTR_VRING}; pub fn create_virtio_device_config() -> VirtioDeviceConfig> { @@ -625,11 +626,17 @@ pub(crate) mod tests { let status = Arc::new(InterruptStatusRegister32::new()); let notifier = Arc::new(LegacyNotifier::new(group, status, VIRTIO_INTR_VRING)); - let mut cfg = VirtioQueueConfig::::create(1024, 1).unwrap(); - cfg.set_interrupt_notifier(notifier); - let mem = Arc::new(GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap()); + let vq = VirtQueue::new(GuestAddress(0), &mem, 1024); + let q = vq.create_queue(); + let mut cfg = VirtioQueueConfig::new( + q, + Arc::new(EventFd::new(EFD_NONBLOCK).unwrap()), + notifier, + 1, + ); + let desc = cfg.get_next_descriptor(mem.memory()).unwrap(); assert!(matches!(desc, None)); @@ -650,12 +657,17 @@ pub(crate) mod tests { let status = Arc::new(InterruptStatusRegister32::new()); let notifier = Arc::new(LegacyNotifier::new(group, status, VIRTIO_INTR_VRING)); - let mut cfg = VirtioQueueConfig::::create(1024, 1).unwrap(); - cfg.set_interrupt_notifier(notifier); - let mut cfg = cfg.clone(); - let mem = Arc::new(GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap()); + let vq = VirtQueue::new(GuestAddress(0), &mem, 1024); + let q = vq.create_queue(); + let mut cfg = VirtioQueueConfig::new( + q, + Arc::new(EventFd::new(EFD_NONBLOCK).unwrap()), + notifier, + 1, + ); + let desc = cfg.get_next_descriptor(mem.memory()).unwrap(); assert!(matches!(desc, None)); diff --git a/src/dragonball/src/dbs_virtio_devices/src/vhost/vhost_user/fs.rs b/src/dragonball/src/dbs_virtio_devices/src/vhost/vhost_user/fs.rs index 43b132656e..e0b6a6dcd7 100644 --- a/src/dragonball/src/dbs_virtio_devices/src/vhost/vhost_user/fs.rs +++ b/src/dragonball/src/dbs_virtio_devices/src/vhost/vhost_user/fs.rs @@ -813,7 +813,7 @@ mod tests { #[test] fn test_vhost_user_fs_virtio_device_normal() { - let device_socket = "/var/tmp/vhost.1"; + let device_socket = "/tmp/vhost.1"; let tag = "test_fs"; let handler = thread::spawn(move || { @@ -882,7 +882,7 @@ mod tests { #[test] fn test_vhost_user_fs_virtio_device_activate() { - let device_socket = "/var/tmp/vhost.1"; + let device_socket = "/tmp/vhost.1"; let tag = "test_fs"; let handler = thread::spawn(move || {