mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
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:
parent
72259f101a
commit
3fe81fe4ab
@ -43,6 +43,7 @@ vm-memory = { version = "0.9.0", features = ["backend-mmap"] }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
slog-term = "2.9.0"
|
slog-term = "2.9.0"
|
||||||
slog-async = "2.7.0"
|
slog-async = "2.7.0"
|
||||||
|
test-utils = { path = "../libs/test-utils" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
acpi = []
|
acpi = []
|
||||||
|
@ -641,6 +641,7 @@ mod tests {
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use dbs_utils::epoll_manager::EpollManager;
|
use dbs_utils::epoll_manager::EpollManager;
|
||||||
|
use test_utils::skip_if_not_root;
|
||||||
use vmm_sys_util::tempfile::TempFile;
|
use vmm_sys_util::tempfile::TempFile;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -686,6 +687,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_receive_unknown() {
|
fn test_vmm_action_receive_unknown() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let (_to_vmm, from_api) = channel();
|
let (_to_vmm, from_api) = channel();
|
||||||
let (to_api, _from_vmm) = channel();
|
let (to_api, _from_vmm) = channel();
|
||||||
let vmm = Arc::new(Mutex::new(create_vmm_instance()));
|
let vmm = Arc::new(Mutex::new(create_vmm_instance()));
|
||||||
@ -714,6 +717,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_config_boot_source() {
|
fn test_vmm_action_config_boot_source() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let kernel_file = TempFile::new().unwrap();
|
let kernel_file = TempFile::new().unwrap();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
@ -777,6 +782,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_set_vm_configuration() {
|
fn test_vmm_action_set_vm_configuration() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state
|
// invalid state
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -979,6 +986,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_start_microvm() {
|
fn test_vmm_action_start_microvm() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state (running)
|
// invalid state (running)
|
||||||
TestData::new(VmmAction::StartMicroVm, InstanceState::Running, &|result| {
|
TestData::new(VmmAction::StartMicroVm, InstanceState::Running, &|result| {
|
||||||
@ -1023,6 +1032,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_shutdown_microvm() {
|
fn test_vmm_action_shutdown_microvm() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// success
|
// success
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1042,6 +1053,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-blk")]
|
#[cfg(feature = "virtio-blk")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_insert_block_device() {
|
fn test_vmm_action_insert_block_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let dummy_file = TempFile::new().unwrap();
|
let dummy_file = TempFile::new().unwrap();
|
||||||
let dummy_path = dummy_file.as_path().to_owned();
|
let dummy_path = dummy_file.as_path().to_owned();
|
||||||
|
|
||||||
@ -1097,6 +1110,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-blk")]
|
#[cfg(feature = "virtio-blk")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_update_block_device() {
|
fn test_vmm_action_update_block_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid id
|
// invalid id
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1128,6 +1143,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-blk")]
|
#[cfg(feature = "virtio-blk")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_remove_block_device() {
|
fn test_vmm_action_remove_block_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state
|
// invalid state
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1175,6 +1192,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-fs")]
|
#[cfg(feature = "virtio-fs")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_insert_fs_device() {
|
fn test_vmm_action_insert_fs_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state
|
// invalid state
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1213,6 +1232,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-fs")]
|
#[cfg(feature = "virtio-fs")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_manipulate_fs_device() {
|
fn test_vmm_action_manipulate_fs_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state
|
// invalid state
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1260,6 +1281,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-net")]
|
#[cfg(feature = "virtio-net")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_insert_network_device() {
|
fn test_vmm_action_insert_network_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// hotplug unready
|
// hotplug unready
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1298,6 +1321,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-net")]
|
#[cfg(feature = "virtio-net")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_update_network_interface() {
|
fn test_vmm_action_update_network_interface() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid id
|
// invalid id
|
||||||
TestData::new(
|
TestData::new(
|
||||||
@ -1332,6 +1357,8 @@ mod tests {
|
|||||||
#[cfg(feature = "virtio-vsock")]
|
#[cfg(feature = "virtio-vsock")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmm_action_insert_vsock_device() {
|
fn test_vmm_action_insert_vsock_device() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let tests = &mut [
|
let tests = &mut [
|
||||||
// invalid state
|
// invalid state
|
||||||
TestData::new(
|
TestData::new(
|
||||||
|
@ -210,14 +210,19 @@ mod x86_64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use kvm_ioctls::Kvm;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd};
|
use std::os::unix::io::{AsRawFd, FromRawFd};
|
||||||
|
|
||||||
|
use kvm_ioctls::Kvm;
|
||||||
|
use test_utils::skip_if_not_root;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_kvm_context() {
|
fn test_create_kvm_context() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let c = KvmContext::new(None).unwrap();
|
let c = KvmContext::new(None).unwrap();
|
||||||
|
|
||||||
assert!(c.max_memslots >= 32);
|
assert!(c.max_memslots >= 32);
|
||||||
@ -234,6 +239,8 @@ mod tests {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_supported_cpu_id() {
|
fn test_get_supported_cpu_id() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let c = KvmContext::new(None).unwrap();
|
let c = KvmContext::new(None).unwrap();
|
||||||
|
|
||||||
let _ = c
|
let _ = c
|
||||||
@ -244,6 +251,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_vm() {
|
fn test_create_vm() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let c = KvmContext::new(None).unwrap();
|
let c = KvmContext::new(None).unwrap();
|
||||||
|
|
||||||
let _ = c.create_vm().unwrap();
|
let _ = c.create_vm().unwrap();
|
||||||
|
@ -771,6 +771,7 @@ pub mod tests {
|
|||||||
use dbs_device::device_manager::IoManager;
|
use dbs_device::device_manager::IoManager;
|
||||||
use kvm_ioctls::Kvm;
|
use kvm_ioctls::Kvm;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use test_utils::skip_if_not_root;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::kvm_context::KvmContext;
|
use crate::kvm_context::KvmContext;
|
||||||
@ -880,6 +881,8 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vcpu_run_emulation() {
|
fn test_vcpu_run_emulation() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let (mut vcpu, _) = create_vcpu();
|
let (mut vcpu, _) = create_vcpu();
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
@ -964,6 +967,8 @@ pub mod tests {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vcpu_check_io_port_info() {
|
fn test_vcpu_check_io_port_info() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
let (vcpu, _receiver) = create_vcpu();
|
let (vcpu, _receiver) = create_vcpu();
|
||||||
|
|
||||||
// debug info signal
|
// debug info signal
|
||||||
|
@ -189,6 +189,8 @@ impl Vmm {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
|
use test_utils::skip_if_not_root;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn create_vmm_instance() -> Vmm {
|
pub fn create_vmm_instance() -> Vmm {
|
||||||
@ -210,6 +212,8 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_vmm_instance() {
|
fn test_create_vmm_instance() {
|
||||||
|
skip_if_not_root!();
|
||||||
|
|
||||||
create_vmm_instance();
|
create_vmm_instance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user