mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Fix warnings in tests
Remove following warnings - unused import - unused Result Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
@@ -884,8 +884,6 @@ mod tests {
|
||||
use crate::memory::{
|
||||
parse_memory_stat, parse_numa_stat, parse_oom_control, MemoryStat, NumaStat, OomControl,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
static GOOD_VALUE: &str = "\
|
||||
total=51189 N0=51189 N1=123
|
||||
file=50175 N0=50175 N1=123
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn test_cpu_res_build() {
|
||||
assert_eq!(cpu.shares().unwrap(), 85);
|
||||
}
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -55,7 +55,7 @@ pub fn test_memory_res_build() {
|
||||
assert_eq!(c.memory_stat().limit_in_bytes, 1024 * 1024 * 1024);
|
||||
}
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -74,7 +74,7 @@ pub fn test_pid_res_build() {
|
||||
assert_eq!(c.get_pid_max().unwrap(), MaxValue::Value(123));
|
||||
}
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -102,7 +102,7 @@ pub fn test_devices_res_build() {
|
||||
}]
|
||||
);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -124,7 +124,7 @@ pub fn test_network_res_build() {
|
||||
assert!(c.get_class().is_ok());
|
||||
assert_eq!(c.get_class().unwrap(), 1337);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -149,7 +149,7 @@ pub fn test_hugepages_res_build() {
|
||||
4 * 2 * 1024 * 1024
|
||||
);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -167,5 +167,5 @@ pub fn test_blkio_res_build() {
|
||||
let c: &BlkIoController = cg.controller_of().unwrap();
|
||||
assert_eq!(c.blkio().weight, 100);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
//
|
||||
|
||||
//! Simple unit tests about the control groups system.
|
||||
use cgroups::memory::{MemController, SetMemory};
|
||||
use cgroups::memory::MemController;
|
||||
use cgroups::Controller;
|
||||
use cgroups::{Cgroup, CgroupPid, Hierarchy, Subsystem};
|
||||
use std::collections::HashMap;
|
||||
use cgroups::{Cgroup, CgroupPid, Subsystem};
|
||||
|
||||
#[test]
|
||||
fn test_tasks_iterator() {
|
||||
@@ -34,7 +33,7 @@ fn test_tasks_iterator() {
|
||||
// Verify that it was indeed removed.
|
||||
assert_eq!(tasks.next(), None);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,7 +74,7 @@ fn test_cgroup_with_relative_paths() {
|
||||
_ => {}
|
||||
});
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -102,5 +101,5 @@ fn test_cgroup_v2() {
|
||||
println!("memswap {:?}", memswap);
|
||||
assert_eq!(swp, memswap.limit_in_bytes);
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
19
tests/cpu.rs
19
tests/cpu.rs
@@ -5,10 +5,7 @@
|
||||
|
||||
//! Simple unit tests about the CPU control groups system.
|
||||
use cgroups::cpu::CpuController;
|
||||
use cgroups::error::ErrorKind;
|
||||
use cgroups::{Cgroup, CgroupPid, CpuResources, Hierarchy, Resources};
|
||||
|
||||
use std::fs;
|
||||
use cgroups::Cgroup;
|
||||
|
||||
#[test]
|
||||
fn test_cfs_quota_and_periods() {
|
||||
@@ -26,7 +23,7 @@ fn test_cfs_quota_and_periods() {
|
||||
assert_eq!(100000, current_peroid);
|
||||
|
||||
// case 1 set quota
|
||||
let r = cpu_controller.set_cfs_quota(2000);
|
||||
let _ = cpu_controller.set_cfs_quota(2000);
|
||||
|
||||
let current_quota = cpu_controller.cfs_quota().unwrap();
|
||||
let current_peroid = cpu_controller.cfs_period().unwrap();
|
||||
@@ -34,14 +31,16 @@ fn test_cfs_quota_and_periods() {
|
||||
assert_eq!(100000, current_peroid);
|
||||
|
||||
// case 2 set period
|
||||
cpu_controller.set_cfs_period(1000000);
|
||||
cpu_controller.set_cfs_period(1000000).unwrap();
|
||||
let current_quota = cpu_controller.cfs_quota().unwrap();
|
||||
let current_peroid = cpu_controller.cfs_period().unwrap();
|
||||
assert_eq!(2000, current_quota);
|
||||
assert_eq!(1000000, current_peroid);
|
||||
|
||||
// case 3 set both quota and period
|
||||
cpu_controller.set_cfs_quota_and_period(Some(5000), Some(100000));
|
||||
cpu_controller
|
||||
.set_cfs_quota_and_period(Some(5000), Some(100000))
|
||||
.unwrap();
|
||||
|
||||
let current_quota = cpu_controller.cfs_quota().unwrap();
|
||||
let current_peroid = cpu_controller.cfs_period().unwrap();
|
||||
@@ -49,12 +48,14 @@ fn test_cfs_quota_and_periods() {
|
||||
assert_eq!(100000, current_peroid);
|
||||
|
||||
// case 4 set both quota and period, set quota to -1
|
||||
cpu_controller.set_cfs_quota_and_period(Some(-1), None);
|
||||
cpu_controller
|
||||
.set_cfs_quota_and_period(Some(-1), None)
|
||||
.unwrap();
|
||||
|
||||
let current_quota = cpu_controller.cfs_quota().unwrap();
|
||||
let current_peroid = cpu_controller.cfs_period().unwrap();
|
||||
assert_eq!(-1, current_quota);
|
||||
assert_eq!(100000, current_peroid);
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use cgroups::cpuset::CpuSetController;
|
||||
use cgroups::error::ErrorKind;
|
||||
use cgroups::{Cgroup, CgroupPid, CpuResources, Hierarchy, Resources};
|
||||
use cgroups::{Cgroup, CgroupPid};
|
||||
|
||||
use std::fs;
|
||||
|
||||
@@ -21,7 +21,7 @@ fn test_cpuset_memory_pressure_root_cg() {
|
||||
let res = cpuset.set_enable_memory_pressure(true);
|
||||
assert_eq!(res.unwrap_err().kind(), &ErrorKind::InvalidOperation);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -59,7 +59,7 @@ fn test_cpuset_set_cpus() {
|
||||
assert_eq!(format!("{}-{}", set.cpus[0].0, set.cpus[0].1), cpus);
|
||||
}
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -89,5 +89,5 @@ fn test_cpuset_set_cpus_add_task() {
|
||||
println!("tasks after deleted: {:?}", tasks);
|
||||
assert_eq!(0, tasks.len());
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! Integration tests about the devices subsystem
|
||||
|
||||
use cgroups::devices::{DevicePermissions, DeviceType, DevicesController};
|
||||
use cgroups::{Cgroup, DeviceResource, Hierarchy};
|
||||
use cgroups::{Cgroup, DeviceResource};
|
||||
|
||||
#[test]
|
||||
fn test_devices_parsing() {
|
||||
@@ -22,16 +22,18 @@ fn test_devices_parsing() {
|
||||
let devices: &DevicesController = cg.controller_of().unwrap();
|
||||
|
||||
// Deny access to all devices first
|
||||
devices.deny_device(
|
||||
DeviceType::All,
|
||||
-1,
|
||||
-1,
|
||||
&vec![
|
||||
DevicePermissions::Read,
|
||||
DevicePermissions::Write,
|
||||
DevicePermissions::MkNod,
|
||||
],
|
||||
);
|
||||
devices
|
||||
.deny_device(
|
||||
DeviceType::All,
|
||||
-1,
|
||||
-1,
|
||||
&vec![
|
||||
DevicePermissions::Read,
|
||||
DevicePermissions::Write,
|
||||
DevicePermissions::MkNod,
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
// Acquire the list of allowed devices after we denied all
|
||||
let allowed_devices = devices.allowed_devices();
|
||||
// Verify that there are no devices that we can access.
|
||||
@@ -39,7 +41,9 @@ fn test_devices_parsing() {
|
||||
assert_eq!(allowed_devices.unwrap(), Vec::new());
|
||||
|
||||
// Now add mknod access to /dev/null device
|
||||
devices.allow_device(DeviceType::Char, 1, 3, &vec![DevicePermissions::MkNod]);
|
||||
devices
|
||||
.allow_device(DeviceType::Char, 1, 3, &vec![DevicePermissions::MkNod])
|
||||
.unwrap();
|
||||
let allowed_devices = devices.allowed_devices();
|
||||
assert!(allowed_devices.is_ok());
|
||||
let allowed_devices = allowed_devices.unwrap();
|
||||
@@ -56,12 +60,14 @@ fn test_devices_parsing() {
|
||||
);
|
||||
|
||||
// Now deny, this device explicitly.
|
||||
devices.deny_device(DeviceType::Char, 1, 3, &DevicePermissions::all());
|
||||
devices
|
||||
.deny_device(DeviceType::Char, 1, 3, &DevicePermissions::all())
|
||||
.unwrap();
|
||||
// Finally, check that.
|
||||
let allowed_devices = devices.allowed_devices();
|
||||
// Verify that there are no devices that we can access.
|
||||
assert!(allowed_devices.is_ok());
|
||||
assert_eq!(allowed_devices.unwrap(), Vec::new());
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@
|
||||
//
|
||||
|
||||
//! Integration tests about the hugetlb subsystem
|
||||
use cgroups::hugetlb::{self, HugeTlbController};
|
||||
use cgroups::Controller;
|
||||
use cgroups::{Cgroup, Hierarchy};
|
||||
|
||||
use cgroups::error::ErrorKind::*;
|
||||
use cgroups::error::*;
|
||||
use cgroups::hugetlb::{self, HugeTlbController};
|
||||
use cgroups::Cgroup;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
@@ -23,7 +20,7 @@ fn test_hugetlb_sizes() {
|
||||
let cg = Cgroup::new(&*h, String::from("test_hugetlb_sizes"));
|
||||
{
|
||||
let hugetlb_controller: &HugeTlbController = cg.controller_of().unwrap();
|
||||
let sizes = hugetlb_controller.get_sizes();
|
||||
let _ = hugetlb_controller.get_sizes();
|
||||
|
||||
// test sizes count
|
||||
let sizes = hugetlb_controller.get_sizes();
|
||||
@@ -39,7 +36,7 @@ fn test_hugetlb_sizes() {
|
||||
assert_no_error(hugetlb_controller.max_usage_in_bytes(&size));
|
||||
}
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
fn assert_no_error(r: Result<u64>) {
|
||||
|
||||
@@ -30,7 +30,7 @@ fn test_disable_oom_killer() {
|
||||
assert_eq!(m.oom_control.oom_kill_disable, true);
|
||||
}
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -87,5 +87,5 @@ fn set_mem_v2() {
|
||||
assert_eq!(m.high, Some(MaxValue::Max));
|
||||
}
|
||||
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -7,27 +7,25 @@
|
||||
//! Integration tests about the pids subsystem
|
||||
use cgroups::pid::PidController;
|
||||
use cgroups::Controller;
|
||||
use cgroups::{Cgroup, CgroupPid, Hierarchy, MaxValue, PidResources, Resources};
|
||||
use cgroups::{Cgroup, MaxValue};
|
||||
|
||||
use nix::sys::wait::{waitpid, WaitStatus};
|
||||
use nix::unistd::{fork, ForkResult, Pid};
|
||||
use nix::unistd::{fork, ForkResult};
|
||||
|
||||
use libc::pid_t;
|
||||
|
||||
use std::thread;
|
||||
|
||||
#[test]
|
||||
fn create_and_delete_cgroup() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let cg = Cgroup::new(&*h, String::from("create_and_delete_cgroup"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
pidcontroller.set_pid_max(MaxValue::Value(1337));
|
||||
pidcontroller.set_pid_max(MaxValue::Value(1337)).unwrap();
|
||||
let max = pidcontroller.get_pid_max();
|
||||
assert!(max.is_ok());
|
||||
assert_eq!(max.unwrap(), MaxValue::Value(1337));
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -39,7 +37,7 @@ fn test_pids_current_is_zero() {
|
||||
let current = pidcontroller.get_pid_current();
|
||||
assert_eq!(current.unwrap(), 0);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -52,7 +50,7 @@ fn test_pids_events_is_zero() {
|
||||
assert!(events.is_ok());
|
||||
assert_eq!(events.unwrap(), 0);
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -101,5 +99,5 @@ fn test_pid_events_is_not_zero() {
|
||||
Err(_) => panic!("failed to fork"),
|
||||
}
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
//! Integration test about setting resources using `apply()`
|
||||
use cgroups::pid::PidController;
|
||||
use cgroups::{Cgroup, Hierarchy, MaxValue, PidResources, Resources};
|
||||
use cgroups::{Cgroup, MaxValue, PidResources, Resources};
|
||||
|
||||
#[test]
|
||||
fn pid_resources() {
|
||||
@@ -19,7 +19,7 @@ fn pid_resources() {
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
cg.apply(&res);
|
||||
cg.apply(&res).unwrap();
|
||||
|
||||
// verify
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
@@ -27,5 +27,5 @@ fn pid_resources() {
|
||||
assert_eq!(pid_max.is_ok(), true);
|
||||
assert_eq!(pid_max.unwrap(), MaxValue::Value(512));
|
||||
}
|
||||
cg.delete();
|
||||
cg.delete().unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user