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:
Levente Kurusa
2018-08-30 13:40:15 +02:00
parent c8b029b154
commit 367ea556ca
8 changed files with 103 additions and 67 deletions

39
tests/pids.rs Normal file
View File

@@ -0,0 +1,39 @@
//! Integration tests about the pids subsystem
extern crate cgroups;
use cgroups::{Cgroup, Resources, PidResources};
use cgroups::pid::{PidController, PidMax};
#[test]
fn create_and_delete_cgroup() {
let hier = cgroups::hierarchies::V1::new();
let cg = Cgroup::new(&hier, String::from("create_and_delete_cgroup"));
{
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 = cgroups::hierarchies::V1::new();
let cg = Cgroup::new(&hier, String::from("test_pid_pids_current_is_zero"));
{
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 = cgroups::hierarchies::V1::new();
let cg = Cgroup::new(&hier, String::from("test_pid_pids_events_is_zero"));
{
let pidcontroller: &PidController = cg.controller_of().unwrap();
assert_eq!(pidcontroller.get_pid_events(), 0);
}
cg.delete();
}

26
tests/resources.rs Normal file
View File

@@ -0,0 +1,26 @@
//! Integration test about setting resources using `apply()`
extern crate cgroups;
use cgroups::{Cgroup, Resources, PidResources};
use cgroups::pid::{PidController, PidMax};
#[test]
fn pid_resources() {
let hier = cgroups::hierarchies::V1::new();
let cg = Cgroup::new(&hier, String::from("pid_resources"));
{
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();
}