-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgroups v1 memory integration test #473
Merged
utam0k
merged 1 commit into
youki-dev:main
from
tsturzl:integration_test_cgroups_memory
Nov 13, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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 = "memory.limit_in_bytes"; | ||
const CGROUP_MEMORY_SWAPPINESS: &str = "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("/runtime-test").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) | ||
} | ||
|
||
fn test_memory_cgroups() -> TestResult { | ||
let cgroup_name = "test_memory_cgroups"; | ||
|
||
let cases = vec![ | ||
test_result!(create_spec(cgroup_name, 50593792, 10)), | ||
test_result!(create_spec(cgroup_name, 50593792, 50)), | ||
test_result!(create_spec(cgroup_name, 50593792, 100)), | ||
test_result!(create_spec(cgroup_name, 151781376, 10)), | ||
test_result!(create_spec(cgroup_name, 151781376, 50)), | ||
test_result!(create_spec(cgroup_name, 151781376, 100)), | ||
]; | ||
|
||
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 | ||
} | ||
|
||
fn can_run() -> bool { | ||
Path::new(CGROUP_MEMORY_LIMIT).exists() && Path::new(CGROUP_MEMORY_SWAPPINESS).exists() | ||
} | ||
|
||
pub fn get_test_group<'a>() -> TestGroup<'a> { | ||
let mut test_group = TestGroup::new("cgroup_v1_memory"); | ||
let linux_cgroups_memory = ConditionalTest::new( | ||
"test_linux_cgroups_memory", | ||
Box::new(can_run), | ||
Box::new(test_memory_cgroups), | ||
); | ||
|
||
test_group.add(vec![Box::new(linux_cgroups_memory)]); | ||
|
||
test_group | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍