Skip to content

Commit 50a9ccd

Browse files
committed
Add integration tests for Intel RDT feature.
Note: this requires resctrl filesystem to be mounted. Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
1 parent 3d9cc19 commit 50a9ccd

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

tests/rust-integration-tests/integration_test/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod utils;
33

44
use crate::tests::hooks::get_hooks_tests;
55
use crate::tests::hostname::get_hostname_test;
6+
use crate::tests::intel_rdt::get_intel_rdt_test;
67
use crate::tests::lifecycle::{ContainerCreate, ContainerLifecycle};
78
use crate::tests::linux_ns_itype::get_ns_itype_tests;
89
use crate::tests::mounts_recursive::get_mounts_recursive_test;
@@ -92,6 +93,7 @@ fn main() -> Result<()> {
9293
let ro_paths = get_ro_paths_test();
9394
let hostname = get_hostname_test();
9495
let mounts_recursive = get_mounts_recursive_test();
96+
let intel_rdt = get_intel_rdt_test();
9597

9698
tm.add_test_group(Box::new(cl));
9799
tm.add_test_group(Box::new(cc));
@@ -109,6 +111,7 @@ fn main() -> Result<()> {
109111
tm.add_test_group(Box::new(ro_paths));
110112
tm.add_test_group(Box::new(hostname));
111113
tm.add_test_group(Box::new(mounts_recursive));
114+
tm.add_test_group(Box::new(intel_rdt));
112115

113116
tm.add_cleanup(Box::new(cgroups::cleanup_v1));
114117
tm.add_cleanup(Box::new(cgroups::cleanup_v2));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use anyhow::{Context, Result};
2+
use libcontainer::process::intel_rdt::find_resctrl_mount_point;
3+
4+
use oci_spec::runtime::{LinuxBuilder, LinuxIntelRdt, Spec, SpecBuilder};
5+
use test_framework::{test_result, TestResult};
6+
7+
use crate::utils::{test_outside_container, test_utils::check_container_created};
8+
9+
fn create_spec(
10+
maybe_l3_cache: Option<&str>,
11+
maybe_mem_bw: Option<&str>,
12+
maybe_clos_id: Option<&str>,
13+
) -> Result<Spec> {
14+
let mut intel_rdt = LinuxIntelRdt::default();
15+
intel_rdt.set_l3_cache_schema(maybe_l3_cache.map(|x| x.to_owned()));
16+
intel_rdt.set_mem_bw_schema(maybe_mem_bw.map(|x| x.to_owned()));
17+
intel_rdt.set_clos_id(maybe_clos_id.map(|x| x.to_owned()));
18+
19+
// Create the Linux Spec
20+
let linux_spec = LinuxBuilder::default()
21+
.intel_rdt(intel_rdt)
22+
.build()
23+
.context("failed to build linux spec")?;
24+
25+
// Create the top level Spec
26+
let spec = SpecBuilder::default()
27+
.linux(linux_spec)
28+
.build()
29+
.context("failed to build spec")?;
30+
31+
Ok(spec)
32+
}
33+
34+
pub fn test_intel_rdt() -> TestResult {
35+
let cases = vec![
36+
test_result!(create_spec(Some("L3:0=fff"), Some("MB:0=70"), None)),
37+
test_result!(create_spec(Some("L3:0=fff"), None, None)),
38+
test_result!(create_spec(None, Some("MB:0=70"), None)),
39+
test_result!(create_spec(None, None, None)),
40+
];
41+
42+
for spec in cases.into_iter() {
43+
let test_result = test_outside_container(spec, &|data| {
44+
test_result!(check_container_created(&data));
45+
46+
TestResult::Passed
47+
});
48+
if let TestResult::Failed(_) = test_result {
49+
return test_result;
50+
}
51+
}
52+
53+
TestResult::Passed
54+
}
55+
56+
pub fn can_run() -> bool {
57+
// Ensure the resctrl pseudo-filesystem is mounted.
58+
let res = find_resctrl_mount_point();
59+
res.is_ok()
60+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use test_framework::{ConditionalTest, TestGroup};
2+
3+
use self::intel_rdt_test::{can_run, test_intel_rdt};
4+
5+
mod intel_rdt_test;
6+
7+
pub fn get_intel_rdt_test() -> TestGroup {
8+
let mut test_group = TestGroup::new("intel_rdt");
9+
let intel_rdt = ConditionalTest::new("intel_rdt", Box::new(can_run), Box::new(test_intel_rdt));
10+
11+
test_group.add(vec![Box::new(intel_rdt)]);
12+
13+
test_group
14+
}

tests/rust-integration-tests/integration_test/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod cgroups;
22
pub mod hooks;
33
pub mod hostname;
4+
pub mod intel_rdt;
45
pub mod lifecycle;
56
pub mod linux_ns_itype;
67
pub mod mounts_recursive;

0 commit comments

Comments
 (0)