Skip to content

Commit

Permalink
Add test for cgroups_relative_memory
Browse files Browse the repository at this point in the history
Signed-off-by: omprakaash <[email protected]>
  • Loading branch information
omprakaash committed Feb 15, 2024
1 parent 04f8f2d commit 36b59a7
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/contest/contest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn main() -> Result<()> {
let cgroup_v1_memory = cgroups::memory::get_test_group();
let cgroup_v1_network = cgroups::network::get_test_group();
let cgroup_v1_blkio = cgroups::blkio::get_test_group();
let cgroup_v1_relative_memory = cgroups::relative_memory::get_test_group();
let seccomp = get_seccomp_test();
let seccomp_notify = get_seccomp_notify_test();
let ro_paths = get_ro_paths_test();
Expand All @@ -120,6 +121,7 @@ fn main() -> Result<()> {
tm.add_test_group(Box::new(cgroup_v1_memory));
tm.add_test_group(Box::new(cgroup_v1_network));
tm.add_test_group(Box::new(cgroup_v1_blkio));
tm.add_test_group(Box::new(cgroup_v1_relative_memory));
tm.add_test_group(Box::new(seccomp));
tm.add_test_group(Box::new(seccomp_notify));
tm.add_test_group(Box::new(ro_paths));
Expand Down
1 change: 1 addition & 0 deletions tests/contest/contest/src/tests/cgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod cpu;
pub mod memory;
pub mod network;
pub mod pids;
pub mod relative_memory;

pub fn cleanup_v1() -> Result<()> {
for subsystem in list_subsystem_mount_points()? {
Expand Down
73 changes: 73 additions & 0 deletions tests/contest/contest/src/tests/cgroups/relative_memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use std::path::Path;

use anyhow::{Context, Result};
use oci_spec::runtime::{
LinuxBuilder, LinuxMemoryBuilder, LinuxResourcesBuilder, Spec, SpecBuilder,
};
use test_framework::{test_result, ConditionalTest, TestGroup, TestResult};

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

const CGROUP_MEMORY_LIMIT: &str = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
const CGROUP_MEMORY_SWAPPINESS: &str = "/sys/fs/cgroup/memory/memory.swappiness";

fn create_spec(cgroup_name: &str, limit: i64, swappiness: u64) -> Result<Spec> {
let spec = SpecBuilder::default()
.linux(
LinuxBuilder::default()
.cgroups_path(Path::new("/testdir/runtime-test/container").join(cgroup_name))
.resources(
LinuxResourcesBuilder::default()
.memory(
LinuxMemoryBuilder::default()
.limit(limit)
.swappiness(swappiness)
.build()
.context("failed to build memory spec")?,
)
.build()
.context("failed to build resource spec")?,
)
.build()
.context("failed to build linux spec")?,
)
.build()
.context("failed to build spec")?;

Ok(spec)

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 37 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs
}


fn test_relative_memory_cgroups() -> TestResult {
let cgroup_name = "test_relative_memory_cgroups";

let spec = test_result!(create_spec(cgroup_name, 50593792, 10));

let test_result = test_outside_container(spec, &|data| {
test_result!(check_container_created(&data));

TestResult::Passed
});
test_result
}

fn can_run() -> bool {
Path::new(CGROUP_MEMORY_LIMIT).exists() && Path::new(CGROUP_MEMORY_SWAPPINESS).exists()
}

pub fn get_test_group() -> TestGroup {
let mut test_group = TestGroup::new("cgroup_v1_relative_memory");
let linux_cgroups_memory = ConditionalTest::new(
"test_linux_cgroups_relative_memory",
Box::new(can_run),
Box::new(test_relative_memory_cgroups),
);

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

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs

Check warning on line 67 in tests/contest/contest/src/tests/cgroups/relative_memory.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/cgroups/relative_memory.rs
test_group
}




2 changes: 1 addition & 1 deletion tests/contest/contest/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pub mod scheduler;
pub mod seccomp;
pub mod seccomp_notify;

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs

Check warning on line 14 in tests/contest/contest/src/tests/mod.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/mod.rs
pub mod sysctl;
pub mod tlb;
pub mod tlb;

0 comments on commit 36b59a7

Please sign in to comment.