mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
tests: move tests to tests/ directory and give the user cgroup perms
Signed-off-by: Levente Kurusa <lkurusa@acm.org>
This commit is contained in:
@@ -92,7 +92,7 @@ impl Cgroup {
|
||||
///
|
||||
/// ## Example:
|
||||
///
|
||||
/// ```
|
||||
/// ```text
|
||||
/// let pids: &PidController = control_group.controller_of()
|
||||
/// .expect("No pids controller attached!");
|
||||
/// let cpu: &CpuController = control_group.controller_of()
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct CpuAcct {
|
||||
/// time spent is `user` time or `system` time.
|
||||
///
|
||||
/// An example is as follows:
|
||||
/// ```
|
||||
/// ```text
|
||||
/// cpu user system
|
||||
/// 0 8348363768 0
|
||||
/// 1 8324369100 0
|
||||
|
||||
66
src/lib.rs
66
src/lib.rs
@@ -32,6 +32,8 @@ use net_prio::NetPrioController;
|
||||
use hugetlb::HugeTlbController;
|
||||
use rdma::RdmaController;
|
||||
|
||||
pub use cgroup::Cgroup;
|
||||
|
||||
/// Contains all the subsystems that are available in this crate.
|
||||
#[derive(Debug)]
|
||||
pub enum Subsystem {
|
||||
@@ -500,67 +502,3 @@ impl Subsystem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {Resources, PidResources, Hierarchy, Controller, Controllers, Subsystem};
|
||||
use pid::{PidMax, PidController};
|
||||
use cgroup::Cgroup;
|
||||
|
||||
#[test]
|
||||
fn create_and_delete_cgroup() {
|
||||
let hier = ::hierarchies::V1::new();
|
||||
let cg = Cgroup::new(&hier, String::from("ltest2"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
pidcontroller.set_pid_max(PidMax::Value(1337));
|
||||
assert_eq!(pidcontroller.get_pid_max(), Some(PidMax::Value(1337)));
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pid_pids_current_is_zero() {
|
||||
let hier = ::hierarchies::V1::new();
|
||||
let cg = Cgroup::new(&hier, String::from("ltest3"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
assert_eq!(pidcontroller.get_pid_current(), 0);
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pid_pids_events_is_zero() {
|
||||
let hier = ::hierarchies::V1::new();
|
||||
let cg = Cgroup::new(&hier, String::from("ltest4"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
assert_eq!(pidcontroller.get_pid_events(), 0);
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_setting_resources() {
|
||||
let hier = ::hierarchies::V1::new();
|
||||
let cg = Cgroup::new(&hier, String::from("ltest5"));
|
||||
{
|
||||
let res = Resources {
|
||||
pid: PidResources {
|
||||
update_values: true,
|
||||
maximum_number_of_processes: PidMax::Value(512),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
cg.apply(&res);
|
||||
|
||||
/* verify */
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
assert_eq!(pidcontroller.get_pid_max(), Some(PidMax::Value(512)));
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub struct Memory {
|
||||
/// Contains various statistics about the NUMA locality of the control group's tasks.
|
||||
///
|
||||
/// The format of this field (as lifted from the kernel sources):
|
||||
/// ```
|
||||
/// ```text
|
||||
/// total=<total pages> N0=<node 0 pages> N1=<node 1 pages> ...
|
||||
/// file=<total file pages> N0=<node 0 pages> N1=<node 1 pages> ...
|
||||
/// anon=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ...
|
||||
|
||||
Reference in New Issue
Block a user