Skip to content

Commit

Permalink
Add integration tests for Intel RDT feature.
Browse files Browse the repository at this point in the history
Note: this requires resctrl filesystem to be mounted.

Signed-off-by: Ismo Puustinen <[email protected]>
  • Loading branch information
ipuustin committed Apr 24, 2023
1 parent 6d9bd12 commit ecf4b54
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/rust-integration-tests/integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod utils;

use crate::tests::hooks::get_hooks_tests;
use crate::tests::hostname::get_hostname_test;
use crate::tests::intel_rdt::get_intel_rdt_test;
use crate::tests::lifecycle::{ContainerCreate, ContainerLifecycle};
use crate::tests::linux_ns_itype::get_ns_itype_tests;
use crate::tests::mounts_recursive::get_mounts_recursive_test;
Expand Down Expand Up @@ -92,6 +93,7 @@ fn main() -> Result<()> {
let ro_paths = get_ro_paths_test();
let hostname = get_hostname_test();
let mounts_recursive = get_mounts_recursive_test();
let intel_rdt = get_intel_rdt_test();

tm.add_test_group(Box::new(cl));
tm.add_test_group(Box::new(cc));
Expand All @@ -109,6 +111,7 @@ fn main() -> Result<()> {
tm.add_test_group(Box::new(ro_paths));
tm.add_test_group(Box::new(hostname));
tm.add_test_group(Box::new(mounts_recursive));
tm.add_test_group(Box::new(intel_rdt));

tm.add_cleanup(Box::new(cgroups::cleanup_v1));
tm.add_cleanup(Box::new(cgroups::cleanup_v2));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use anyhow::{Context, Result};
use libcontainer::process::intel_rdt::find_resctrl_mount_point;

use oci_spec::runtime::{LinuxBuilder, LinuxIntelRdt, Spec, SpecBuilder};
use test_framework::{test_result, TestResult};

use crate::utils::{test_outside_container, test_utils::check_container_created};

fn create_spec(
maybe_l3_cache: Option<&str>,
maybe_mem_bw: Option<&str>,
maybe_clos_id: Option<&str>,
) -> Result<Spec> {
let mut intel_rdt = LinuxIntelRdt::default();
intel_rdt.set_l3_cache_schema(maybe_l3_cache.map(|x| x.to_owned()));
intel_rdt.set_mem_bw_schema(maybe_mem_bw.map(|x| x.to_owned()));
intel_rdt.set_clos_id(maybe_clos_id.map(|x| x.to_owned()));

// Create the Linux Spec
let linux_spec = LinuxBuilder::default()
.intel_rdt(intel_rdt)
.build()
.context("failed to build linux spec")?;

// Create the top level Spec
let spec = SpecBuilder::default()
.linux(linux_spec)
.build()
.context("failed to build spec")?;

Ok(spec)
}

pub fn test_intel_rdt() -> TestResult {
let cases = vec![
test_result!(create_spec(Some("L3:0=fff"), Some("MB:0=70"), None)),
test_result!(create_spec(Some("L3:0=fff"), None, None)),
test_result!(create_spec(None, Some("MB:0=70"), None)),
test_result!(create_spec(None, None, None)),
];

for spec in cases.into_iter() {
let test_result = test_outside_container(spec, &|data| {
test_result!(check_container_created(&data));

TestResult::Passed
});
if let TestResult::Failed(_) = test_result {
return test_result;
}
}

TestResult::Passed
}

pub fn can_run() -> bool {
// Ensure the resctrl pseudo-filesystem is mounted.
let res = find_resctrl_mount_point();
res.is_ok()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use test_framework::{ConditionalTest, TestGroup};

use self::intel_rdt_test::{can_run, test_intel_rdt};

mod intel_rdt_test;

pub fn get_intel_rdt_test() -> TestGroup {
let mut test_group = TestGroup::new("intel_rdt");
let intel_rdt = ConditionalTest::new("intel_rdt", Box::new(can_run), Box::new(test_intel_rdt));

test_group.add(vec![Box::new(intel_rdt)]);

test_group
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod cgroups;
pub mod hooks;
pub mod hostname;
pub mod intel_rdt;
pub mod lifecycle;
pub mod linux_ns_itype;
pub mod mounts_recursive;
Expand Down

0 comments on commit ecf4b54

Please sign in to comment.