cargo fmt

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-09-09 16:42:55 +08:00
parent ff6a0ea82a
commit 250ada183a
27 changed files with 534 additions and 448 deletions
+39 -36
View File
@@ -5,15 +5,15 @@
//
//! Some simple tests covering the builder pattern for control groups.
use cgroups::*;
use cgroups::cpu::*;
use cgroups::devices::*;
use cgroups::pid::*;
use cgroups::memory::*;
use cgroups::net_cls::*;
use cgroups::hugetlb::*;
use cgroups::blkio::*;
use cgroups::cgroup_builder::*;
use cgroups::cpu::*;
use cgroups::devices::*;
use cgroups::hugetlb::*;
use cgroups::memory::*;
use cgroups::net_cls::*;
use cgroups::pid::*;
use cgroups::*;
#[test]
pub fn test_cpu_res_build() {
@@ -21,8 +21,8 @@ pub fn test_cpu_res_build() {
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build", h)
.cpu()
.shares(85)
.done()
.shares(85)
.done()
.build();
{
@@ -40,10 +40,10 @@ pub fn test_memory_res_build() {
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build", h)
.memory()
.kernel_memory_limit(128 * 1024 * 1024)
.swappiness(70)
.memory_hard_limit(1024 * 1024 * 1024)
.done()
.kernel_memory_limit(128 * 1024 * 1024)
.swappiness(70)
.memory_hard_limit(1024 * 1024 * 1024)
.done()
.build();
{
@@ -64,8 +64,8 @@ pub fn test_pid_res_build() {
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build", h)
.pid()
.maximum_number_of_processes(MaxValue::Value(123))
.done()
.maximum_number_of_processes(MaxValue::Value(123))
.done()
.build();
{
@@ -84,23 +84,23 @@ pub fn test_devices_res_build() {
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build", h)
.devices()
.device(1, 6, DeviceType::Char, true,
vec![DevicePermissions::Read])
.done()
.device(1, 6, DeviceType::Char, true, vec![DevicePermissions::Read])
.done()
.build();
{
let c: &DevicesController = cg.controller_of().unwrap();
assert!(c.allowed_devices().is_ok());
assert_eq!(c.allowed_devices().unwrap(), vec![
DeviceResource {
allow: true,
devtype: DeviceType::Char,
major: 1,
minor: 6,
access: vec![DevicePermissions::Read],
}
]);
assert_eq!(
c.allowed_devices().unwrap(),
vec![DeviceResource {
allow: true,
devtype: DeviceType::Char,
major: 1,
minor: 6,
access: vec![DevicePermissions::Read],
}]
);
}
cg.delete();
}
@@ -110,13 +110,13 @@ pub fn test_network_res_build() {
let h = cgroups::hierarchies::auto();
if h.v2() {
// FIXME add cases for v2
return
return;
}
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_network_res_build", h)
.network()
.class_id(1337)
.done()
.class_id(1337)
.done()
.build();
{
@@ -132,19 +132,22 @@ pub fn test_hugepages_res_build() {
let h = cgroups::hierarchies::auto();
if h.v2() {
// FIXME add cases for v2
return
return;
}
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_hugepages_res_build", h)
.hugepages()
.limit("2MB".to_string(), 4 * 2 * 1024 * 1024)
.done()
.limit("2MB".to_string(), 4 * 2 * 1024 * 1024)
.done()
.build();
{
let c: &HugeTlbController = cg.controller_of().unwrap();
assert!(c.limit_in_bytes(&"2MB".to_string()).is_ok());
assert_eq!(c.limit_in_bytes(&"2MB".to_string()).unwrap(), 4 * 2 * 1024 * 1024);
assert_eq!(
c.limit_in_bytes(&"2MB".to_string()).unwrap(),
4 * 2 * 1024 * 1024
);
}
cg.delete();
}
@@ -156,8 +159,8 @@ pub fn test_blkio_res_build() {
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build", h)
.blkio()
.weight(Some(100))
.done()
.weight(Some(100))
.done()
.build();
{
+25 -10
View File
@@ -5,9 +5,9 @@
//
//! Simple unit tests about the control groups system.
use cgroups::{Cgroup, CgroupPid, Hierarchy, Subsystem};
use cgroups::memory::{MemController, SetMemory};
use cgroups::Controller;
use cgroups::{Cgroup, CgroupPid, Hierarchy, Subsystem};
use std::collections::HashMap;
#[test]
@@ -38,11 +38,10 @@ fn test_tasks_iterator() {
cg.delete();
}
#[test]
fn test_cgroup_with_relative_paths() {
if cgroups::hierarchies::is_cgroup2_unified_mode() {
return
return;
}
let h = cgroups::hierarchies::auto();
let cgroup_root = h.root();
@@ -60,14 +59,30 @@ fn test_cgroup_with_relative_paths() {
let cgroup_path = c.path().to_str().unwrap();
let relative_path = "/pids/";
// cgroup_path = cgroup_root + relative_path + cgroup_name
assert_eq!(cgroup_path, format!("{}{}{}", cgroup_root.to_str().unwrap(), relative_path, cgroup_name));
},
assert_eq!(
cgroup_path,
format!(
"{}{}{}",
cgroup_root.to_str().unwrap(),
relative_path,
cgroup_name
)
);
}
Subsystem::Mem(c) => {
let cgroup_path = c.path().to_str().unwrap();
// cgroup_path = cgroup_root + relative_path + cgroup_name
assert_eq!(cgroup_path, format!("{}/memory{}/{}", cgroup_root.to_str().unwrap(), mem_relative_path, cgroup_name));
},
_ => {},
assert_eq!(
cgroup_path,
format!(
"{}/memory{}/{}",
cgroup_root.to_str().unwrap(),
mem_relative_path,
cgroup_name
)
);
}
_ => {}
});
}
cg.delete();
@@ -76,14 +91,14 @@ fn test_cgroup_with_relative_paths() {
#[test]
fn test_cgroup_v2() {
if !cgroups::hierarchies::is_cgroup2_unified_mode() {
return
return;
}
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg = Cgroup::new_with_relative_paths(h, String::from("test_v2"), HashMap::new());
let mem_controller: &MemController = cg.controller_of().unwrap();
let (mem, swp, rev) = (4 * 1024 * 1000, 2 * 1024* 1000, 1024 * 1000);
let (mem, swp, rev) = (4 * 1024 * 1000, 2 * 1024 * 1000, 1024 * 1000);
let _ = mem_controller.set_limit(mem);
let _ = mem_controller.set_memswap_limit(swp);
+4 -4
View File
@@ -25,7 +25,6 @@ fn test_cpuset_memory_pressure_root_cg() {
cg.delete();
}
#[test]
fn test_cpuset_set_cpus() {
let h = cgroups::hierarchies::auto();
@@ -48,10 +47,11 @@ fn test_cpuset_set_cpus() {
let set = cpuset.cpuset();
assert_eq!(1, set.cpus.len());
assert_eq!((0,0), set.cpus[0]);
assert_eq!((0, 0), set.cpus[0]);
// all cpus in system
let cpus = fs::read_to_string("/sys/fs/cgroup/cpuset.cpus.effective").unwrap_or("".to_string());
let cpus =
fs::read_to_string("/sys/fs/cgroup/cpuset.cpus.effective").unwrap_or("".to_string());
let cpus = cpus.trim();
if cpus != "" {
let r = cpuset.set_cpus(&cpus);
@@ -93,4 +93,4 @@ fn test_cpuset_set_cpus_add_task() {
assert_eq!(0, tasks.len());
cg.delete();
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ use cgroups::{Cgroup, DeviceResource, Hierarchy};
fn test_devices_parsing() {
// now only v2
if cgroups::hierarchies::is_cgroup2_unified_mode() {
return
return;
}
let h = cgroups::hierarchies::auto();
+2 -2
View File
@@ -5,8 +5,8 @@
//! Integration tests about the hugetlb subsystem
use cgroups::hugetlb::HugeTlbController;
use cgroups::{Cgroup, Hierarchy};
use cgroups::Controller;
use cgroups::{Cgroup, Hierarchy};
use cgroups::error::ErrorKind::*;
use cgroups::error::*;
@@ -15,7 +15,7 @@ use cgroups::error::*;
fn test_hugetlb_sizes() {
// now only v2
if cgroups::hierarchies::is_cgroup2_unified_mode() {
return
return;
}
let h = cgroups::hierarchies::auto();
+16 -19
View File
@@ -5,8 +5,8 @@
//! Integration tests about the hugetlb subsystem
use cgroups::memory::{MemController, SetMemory};
use cgroups::{Cgroup, Hierarchy, MaxValue};
use cgroups::Controller;
use cgroups::{Cgroup, Hierarchy, MaxValue};
use cgroups::error::ErrorKind::*;
use cgroups::error::*;
@@ -24,7 +24,7 @@ fn test_disable_oom_killer() {
assert_eq!(m.oom_control.oom_kill_disable, false);
// FIXME only v1
if !mem_controller.v2(){
if !mem_controller.v2() {
// disable oom killer
let r = mem_controller.disable_oom_killer();
assert_eq!(r.is_err(), false);
@@ -33,7 +33,6 @@ fn test_disable_oom_killer() {
let m = mem_controller.memory_stat();
assert_eq!(m.oom_control.oom_kill_disable, true);
}
}
cg.delete();
}
@@ -42,7 +41,7 @@ fn test_disable_oom_killer() {
fn set_mem_v2() {
let h = cgroups::hierarchies::auto();
if !h.v2() {
return
return;
}
let h = Box::new(&*h);
@@ -59,10 +58,10 @@ fn set_mem_v2() {
assert_eq!(m.max, Some(MaxValue::Max));
// case 2: set parts
let m = SetMemory{
low: Some(MaxValue::Value(1024*1024* 2)),
high: Some(MaxValue::Value(1024*1024*1024* 2)),
min: Some(MaxValue::Value(1024*1024* 3)),
let m = SetMemory {
low: Some(MaxValue::Value(1024 * 1024 * 2)),
high: Some(MaxValue::Value(1024 * 1024 * 1024 * 2)),
min: Some(MaxValue::Value(1024 * 1024 * 3)),
max: None,
};
let r = mem_controller.set_mem(m);
@@ -70,17 +69,15 @@ fn set_mem_v2() {
let m = mem_controller.get_mem().unwrap();
// get
assert_eq!(m.low, Some(MaxValue::Value(1024*1024* 2)));
assert_eq!(m.min, Some(MaxValue::Value(1024*1024* 3)));
assert_eq!(m.high, Some(MaxValue::Value(1024*1024*1024* 2)));
assert_eq!(m.low, Some(MaxValue::Value(1024 * 1024 * 2)));
assert_eq!(m.min, Some(MaxValue::Value(1024 * 1024 * 3)));
assert_eq!(m.high, Some(MaxValue::Value(1024 * 1024 * 1024 * 2)));
assert_eq!(m.max, Some(MaxValue::Max));
// case 3: set parts
let m = SetMemory{
max: Some(MaxValue::Value(1024*1024*1024* 2)),
min: Some(MaxValue::Value(1024*1024* 4)),
let m = SetMemory {
max: Some(MaxValue::Value(1024 * 1024 * 1024 * 2)),
min: Some(MaxValue::Value(1024 * 1024 * 4)),
high: Some(MaxValue::Max),
low: None,
};
@@ -89,9 +86,9 @@ fn set_mem_v2() {
let m = mem_controller.get_mem().unwrap();
// get
assert_eq!(m.low, Some(MaxValue::Value(1024*1024* 2)));
assert_eq!(m.min, Some(MaxValue::Value(1024*1024* 4)));
assert_eq!(m.max, Some(MaxValue::Value(1024*1024*1024* 2)));
assert_eq!(m.low, Some(MaxValue::Value(1024 * 1024 * 2)));
assert_eq!(m.min, Some(MaxValue::Value(1024 * 1024 * 4)));
assert_eq!(m.max, Some(MaxValue::Value(1024 * 1024 * 1024 * 2)));
assert_eq!(m.high, Some(MaxValue::Max));
}
+1 -1
View File
@@ -5,7 +5,7 @@
//
//! Integration tests about the pids subsystem
use cgroups::pid::{PidController};
use cgroups::pid::PidController;
use cgroups::Controller;
use cgroups::{Cgroup, CgroupPid, Hierarchy, MaxValue, PidResources, Resources};
+1 -1
View File
@@ -5,7 +5,7 @@
//
//! Integration test about setting resources using `apply()`
use cgroups::pid::{PidController};
use cgroups::pid::PidController;
use cgroups::{Cgroup, Hierarchy, MaxValue, PidResources, Resources};
#[test]