dragonball-ut: use skip_if_not_root to skip root case

Use skip_if_not_root to skip when unit test requires privileges.

Signed-off-by: wllenyj <wllenyj@linux.alibaba.com>
This commit is contained in:
wllenyj 2022-08-22 18:14:40 +08:00
parent 72259f101a
commit 3fe81fe4ab
5 changed files with 48 additions and 2 deletions

View File

@ -43,6 +43,7 @@ vm-memory = { version = "0.9.0", features = ["backend-mmap"] }
[dev-dependencies]
slog-term = "2.9.0"
slog-async = "2.7.0"
test-utils = { path = "../libs/test-utils" }
[features]
acpi = []

View File

@ -641,6 +641,7 @@ mod tests {
use std::sync::{Arc, Mutex};
use dbs_utils::epoll_manager::EpollManager;
use test_utils::skip_if_not_root;
use vmm_sys_util::tempfile::TempFile;
use super::*;
@ -686,6 +687,8 @@ mod tests {
#[test]
fn test_vmm_action_receive_unknown() {
skip_if_not_root!();
let (_to_vmm, from_api) = channel();
let (to_api, _from_vmm) = channel();
let vmm = Arc::new(Mutex::new(create_vmm_instance()));
@ -714,6 +717,8 @@ mod tests {
#[test]
fn test_vmm_action_config_boot_source() {
skip_if_not_root!();
let kernel_file = TempFile::new().unwrap();
let tests = &mut [
@ -777,6 +782,8 @@ mod tests {
#[test]
fn test_vmm_action_set_vm_configuration() {
skip_if_not_root!();
let tests = &mut [
// invalid state
TestData::new(
@ -979,6 +986,8 @@ mod tests {
#[test]
fn test_vmm_action_start_microvm() {
skip_if_not_root!();
let tests = &mut [
// invalid state (running)
TestData::new(VmmAction::StartMicroVm, InstanceState::Running, &|result| {
@ -1023,6 +1032,8 @@ mod tests {
#[test]
fn test_vmm_action_shutdown_microvm() {
skip_if_not_root!();
let tests = &mut [
// success
TestData::new(
@ -1042,6 +1053,8 @@ mod tests {
#[cfg(feature = "virtio-blk")]
#[test]
fn test_vmm_action_insert_block_device() {
skip_if_not_root!();
let dummy_file = TempFile::new().unwrap();
let dummy_path = dummy_file.as_path().to_owned();
@ -1097,6 +1110,8 @@ mod tests {
#[cfg(feature = "virtio-blk")]
#[test]
fn test_vmm_action_update_block_device() {
skip_if_not_root!();
let tests = &mut [
// invalid id
TestData::new(
@ -1128,6 +1143,8 @@ mod tests {
#[cfg(feature = "virtio-blk")]
#[test]
fn test_vmm_action_remove_block_device() {
skip_if_not_root!();
let tests = &mut [
// invalid state
TestData::new(
@ -1175,6 +1192,8 @@ mod tests {
#[cfg(feature = "virtio-fs")]
#[test]
fn test_vmm_action_insert_fs_device() {
skip_if_not_root!();
let tests = &mut [
// invalid state
TestData::new(
@ -1213,6 +1232,8 @@ mod tests {
#[cfg(feature = "virtio-fs")]
#[test]
fn test_vmm_action_manipulate_fs_device() {
skip_if_not_root!();
let tests = &mut [
// invalid state
TestData::new(
@ -1260,6 +1281,8 @@ mod tests {
#[cfg(feature = "virtio-net")]
#[test]
fn test_vmm_action_insert_network_device() {
skip_if_not_root!();
let tests = &mut [
// hotplug unready
TestData::new(
@ -1298,6 +1321,8 @@ mod tests {
#[cfg(feature = "virtio-net")]
#[test]
fn test_vmm_action_update_network_interface() {
skip_if_not_root!();
let tests = &mut [
// invalid id
TestData::new(
@ -1332,6 +1357,8 @@ mod tests {
#[cfg(feature = "virtio-vsock")]
#[test]
fn test_vmm_action_insert_vsock_device() {
skip_if_not_root!();
let tests = &mut [
// invalid state
TestData::new(

View File

@ -210,14 +210,19 @@ mod x86_64 {
#[cfg(test)]
mod tests {
use super::*;
use kvm_ioctls::Kvm;
use std::fs::File;
use std::os::unix::fs::MetadataExt;
use std::os::unix::io::{AsRawFd, FromRawFd};
use kvm_ioctls::Kvm;
use test_utils::skip_if_not_root;
use super::*;
#[test]
fn test_create_kvm_context() {
skip_if_not_root!();
let c = KvmContext::new(None).unwrap();
assert!(c.max_memslots >= 32);
@ -234,6 +239,8 @@ mod tests {
#[cfg(target_arch = "x86_64")]
#[test]
fn test_get_supported_cpu_id() {
skip_if_not_root!();
let c = KvmContext::new(None).unwrap();
let _ = c
@ -244,6 +251,8 @@ mod tests {
#[test]
fn test_create_vm() {
skip_if_not_root!();
let c = KvmContext::new(None).unwrap();
let _ = c.create_vm().unwrap();

View File

@ -771,6 +771,7 @@ pub mod tests {
use dbs_device::device_manager::IoManager;
use kvm_ioctls::Kvm;
use lazy_static::lazy_static;
use test_utils::skip_if_not_root;
use super::*;
use crate::kvm_context::KvmContext;
@ -880,6 +881,8 @@ pub mod tests {
#[test]
fn test_vcpu_run_emulation() {
skip_if_not_root!();
let (mut vcpu, _) = create_vcpu();
#[cfg(target_arch = "x86_64")]
@ -964,6 +967,8 @@ pub mod tests {
#[cfg(target_arch = "x86_64")]
#[test]
fn test_vcpu_check_io_port_info() {
skip_if_not_root!();
let (vcpu, _receiver) = create_vcpu();
// debug info signal

View File

@ -189,6 +189,8 @@ impl Vmm {
#[cfg(test)]
pub(crate) mod tests {
use test_utils::skip_if_not_root;
use super::*;
pub fn create_vmm_instance() -> Vmm {
@ -210,6 +212,8 @@ pub(crate) mod tests {
#[test]
fn test_create_vmm_instance() {
skip_if_not_root!();
create_vmm_instance();
}
}