Skip to content

Commit

Permalink
Add ns_itype test
Browse files Browse the repository at this point in the history
  • Loading branch information
YJDoc2 committed Oct 21, 2021
1 parent efac2ce commit cf260fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
22 changes: 14 additions & 8 deletions youki_integration_test/src/tests/linux_ns_itype/ns_itype_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,33 @@ fn get_test<'a>(test_name: &'static str) -> Test<'a> {
Test::new(
test_name,
Box::new(move || {
let host_proc = Process::myself().unwrap();
let host_proc = Process::myself().expect("error in getting /proc/self");
let host_namespaces = match host_proc.namespaces() {
Ok(n) => n,
Err(e) => {
return TestResult::Err(anyhow!("Error in resolving host namespaces : {}", e))
return TestResult::Failed(anyhow!(
"error in resolving host namespaces : {}",
e
))
}
};
let spec = get_spec();
test_outside_container(spec, &move |data| {
let pid = match data.state {
Some(s) => s.pid.unwrap(),
None => return TestResult::Err(anyhow!("State command returned error")),
None => return TestResult::Failed(anyhow!("state command returned error")),
};
let container_process = Process::new(pid).unwrap();
let container_namespaces = container_process.namespaces().unwrap();
let container_process =
Process::new(pid).expect("error in getting /proc for container process");
let container_namespaces = container_process
.namespaces()
.expect("error in getting namespaces of container process");
if container_namespaces != host_namespaces {
return TestResult::Err(anyhow!(
"Error : namespaces are not correctly inherited"
return TestResult::Failed(anyhow!(
"error : namespaces are not correctly inherited"
));
}
TestResult::Ok
TestResult::Passed
})
}),
)
Expand Down
8 changes: 4 additions & 4 deletions youki_integration_test/src/tests/pidfile/pidfile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ fn test_pidfile() -> TestResult {

if !err.is_empty() {
cleanup(&container_id, &bundle);
return TestResult::Failed(anyhow!("Error in state : {}", err));
return TestResult::Failed(anyhow!("error in state : {}", err));
}

let state: State = serde_json::from_str(&out).unwrap();

if state.id != container_id.to_string() {
cleanup(&container_id, &bundle);
return TestResult::Failed(anyhow!(
"Error in state : ID not matched ,expected {} got {}",
"error in state : id not matched ,expected {} got {}",
container_id,
state.id
));
Expand All @@ -63,7 +63,7 @@ fn test_pidfile() -> TestResult {
if state.status != "created" {
cleanup(&container_id, &bundle);
return TestResult::Failed(anyhow!(
"Error in state : Status not matched ,expected 'created' got {}",
"error in state : status not matched ,expected 'created' got {}",
state.status
));
}
Expand All @@ -78,7 +78,7 @@ fn test_pidfile() -> TestResult {
if state.pid.unwrap() != pidfile {
cleanup(&container_id, &bundle);
return TestResult::Failed(anyhow!(
"Error : Pid not matched ,expected {} as per state, but got {} from pidfile instead",
"error : pid not matched ,expected {} as per state, but got {} from pidfile instead",
state.pid.unwrap(),
pidfile
));
Expand Down
16 changes: 9 additions & 7 deletions youki_integration_test/src/tests/tlb/tlb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use oci_spec::runtime::LinuxBuilder;
use oci_spec::runtime::{LinuxHugepageLimitBuilder, LinuxResourcesBuilder};
use oci_spec::runtime::{Spec, SpecBuilder};
use std::path::PathBuf;
use test_framework::{ConditionalTest, TestGroup, TestResult};
use test_framework::{test_result, ConditionalTest, TestGroup, TestResult};

fn check_hugetlb() -> bool {
PathBuf::from("/sys/fs/cgroup/hugetlb").exists()
Expand All @@ -21,7 +21,7 @@ fn make_hugetlb_spec(page_size: &str, limit: i64) -> Spec {
.page_size(page_size.to_owned())
.limit(limit)
.build()
.expect("Could not build")])
.expect("could not build")])
.build()
.unwrap(),
)
Expand Down Expand Up @@ -52,7 +52,7 @@ fn test_wrong_tlb() -> TestResult {
}
if res.success() {
// The operation should not have succeeded as pagesize was not power of 2
TestResult::Failed(anyhow!("Invalid page size of {} was allowed", page))
TestResult::Failed(anyhow!("invalid page size of {} was allowed", page))
} else {
TestResult::Passed
}
Expand All @@ -77,8 +77,10 @@ fn extract_page_size(dir_name: &str) -> String {

fn get_tlb_sizes() -> Vec<String> {
let mut sizes = Vec::new();
for hugetlb_entry in std::fs::read_dir("/sys/kernel/mm/hugepages").unwrap() {
let hugetlb_entry = hugetlb_entry.unwrap();
for hugetlb_entry in std::fs::read_dir("/sys/kernel/mm/hugepages")
.expect("error in reading /sys/kernel/mm/hugepages")
{
let hugetlb_entry = hugetlb_entry.expect("error in reading /sys/kernel/mm/hugepages entry");
if !hugetlb_entry.path().is_dir() {
continue;
}
Expand All @@ -100,7 +102,7 @@ fn validate_tlb(id: &str, size: &str, limit: i64) -> TestResult {
TestResult::Passed
} else {
TestResult::Failed(anyhow!(
"Page limit not set correctly : for size {}, expected {}, got {}",
"page limit not set correctly : for size {}, expected {}, got {}",
size,
limit,
val
Expand All @@ -117,7 +119,7 @@ fn test_valid_tlb() -> TestResult {
for size in tlb_sizes.iter() {
let spec = make_hugetlb_spec(size, limit);
let res = test_outside_container(spec, &|data| {
check_container_created(&data).unwrap();
test_result!(check_container_created(&data));

let r = validate_tlb(&data.id, size, limit);
if matches!(r, TestResult::Failed(_)) {
Expand Down

0 comments on commit cf260fe

Please sign in to comment.