Skip to content

Commit

Permalink
add rrelatime mount test (#1642)
Browse files Browse the repository at this point in the history
Signed-off-by: lengrongfu <1275177125@qq.com>
  • Loading branch information
lengrongfu committed Mar 11, 2023
1 parent ef5daba commit 29babe7
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ tags.temp
*~

/bundle.tar.gz
/test.log
/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn get_test(test_name: &'static str) -> Test {
delete_hook_output_file();
if log != "pre-start1 called\npre-start2 called\npost-start1 called\npost-start2 called\npost-stop1 called\npost-stop2 called\n" {
return TestResult::Failed(anyhow!(
"error : hooks must be called in the listed order"
"error : hooks must be called in the listed order, {log:?}"
));
}
TestResult::Passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,106 @@ fn check_recursive_readwrite() -> TestResult {
result
}

fn check_recursive_rrelatime() -> TestResult {
let rrelatime_base_dir = PathBuf::from_str("/tmp").unwrap();
let rrelatime_dir_path = rrelatime_base_dir.join("rrelatime_dir");
let rrelatime_suddir_path = rrelatime_dir_path.join("rrelatime_subdir");
let mount_dest_path = PathBuf::from_str("/rrelatime").unwrap();
fs::create_dir_all(rrelatime_suddir_path).unwrap();

let mount_options = vec!["rbind".to_string(), "rrelatime".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rrelatime_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);
let result = test_inside_container(spec, &|_| Ok(()));

fs::remove_dir_all(rrelatime_dir_path).unwrap();
result
}

fn check_recursive_rnorelatime() -> TestResult {
let rnorelatime_base_dir = PathBuf::from_str("/tmp").unwrap();
let rnorelatime_dir_path = rnorelatime_base_dir.join("rnorelatime_dir");
let mount_dest_path = PathBuf::from_str("/rnorelatime").unwrap();
fs::create_dir(rnorelatime_dir_path.clone()).unwrap();

let mount_options = vec!["rbind".to_string(), "rnorelatime".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rnorelatime_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);

let result = test_inside_container(spec, &|_| Ok(()));

fs::remove_dir_all(rnorelatime_dir_path).unwrap();
result
}

fn check_recursive_rnoatime() -> TestResult {
let rnoatime_base_dir = PathBuf::from_str("/tmp").unwrap();
let rnoatime_dir_path = rnoatime_base_dir.join("rnoatime_dir");
let mount_dest_path = PathBuf::from_str("/rnoatime").unwrap();
fs::create_dir(rnoatime_dir_path.clone()).unwrap();

let mount_options = vec!["rbind".to_string(), "rnoatime".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rnoatime_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);

let result = test_inside_container(spec, &|_| Ok(()));

fs::remove_dir_all(rnoatime_dir_path).unwrap();
result
}

fn check_recursive_rstrictatime() -> TestResult {
let rstrictatime_base_dir = PathBuf::from_str("/tmp").unwrap();
let rstrictatime_dir_path = rstrictatime_base_dir.join("rstrictatime_dir");
let mount_dest_path = PathBuf::from_str("/rstrictatime").unwrap();
fs::create_dir(rstrictatime_dir_path.clone()).unwrap();

let mount_options = vec!["rbind".to_string(), "rstrictatime".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rstrictatime_dir_path.clone()))
.set_options(Some(mount_options));
let spec = get_spec(
vec![mount_spec],
vec!["runtimetest".to_string(), "mounts_recursive".to_string()],
);
let result = test_inside_container(spec, &|_| Ok(()));

fs::remove_dir_all(rstrictatime_dir_path).unwrap();
result
}

/// this mount test how to work?
/// 1. Create mount_options based on the mount properties of the test
/// 2. Create OCI.Spec content, container one process is runtimetest,(runtimetest is cargo model, file path `tests/rust-integration-tests/runtimetest/`)
/// 3. inside container to check if the actual mount matches the spec, (spec https://man7.org/linux/man-pages/man2/mount_setattr.2.html),
/// eg. tests/rust-integration-tests/runtimetest/src/tests.rs
pub fn get_mounts_recursive_test() -> TestGroup {
let rro_test = Test::new("rro_test", Box::new(check_recursive_readonly));
let rnosuid_test = Test::new("rnosuid_test", Box::new(check_recursive_nosuid));
Expand All @@ -407,6 +507,10 @@ pub fn get_mounts_recursive_test() -> TestGroup {
let rnodev_test = Test::new("rnodev_test", Box::new(check_recursive_rnodev));
let rrw_test = Test::new("rrw_test", Box::new(check_recursive_readwrite));
let rexec_test = Test::new("rexec_test", Box::new(check_recursive_rexec));
let rrelatime_test = Test::new("rrelatime_test", Box::new(check_recursive_rrelatime));
let rnorelatime_test = Test::new("rnorelatime_test", Box::new(check_recursive_rnorelatime));
let rnoatime_test = Test::new("rnoatime_test", Box::new(check_recursive_rnoatime));
let rstrictatime_test = Test::new("rstrictatime_test", Box::new(check_recursive_rstrictatime));

let mut tg = TestGroup::new("mounts_recursive");
tg.add(vec![
Expand All @@ -419,6 +523,10 @@ pub fn get_mounts_recursive_test() -> TestGroup {
Box::new(rnodev_test),
Box::new(rrw_test),
Box::new(rexec_test),
Box::new(rrelatime_test),
Box::new(rnorelatime_test),
Box::new(rnoatime_test),
Box::new(rstrictatime_test),
]);

tg
Expand Down
34 changes: 34 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,40 @@ pub fn validate_mounts_recursive(spec: &Spec) {
eprintln!("error in testing rnodev recursive mounting");
}
}
"rrelatime" => {
println!("rrelatime: {mount:?}");
if let Err(e) = utils::test_mount_releatime_option(
mount.destination().to_str().unwrap(),
) {
eprintln!("path expected to be rrelatime, found not rrelatime, error: {e}");
}
}
"rnorelatime" => {
println!("rnorelatime: {mount:?}");
if let Err(e) = utils::test_mount_noreleatime_option(
mount.destination().to_str().unwrap(),
) {
eprintln!("path expected to be rnorelatime, found not rnorelatime, error: {e}");
}
}
"rnoatime" => {
println!("rnoatime: {mount:?}");
if let Err(e) = utils::test_mount_rnoatime_option(
mount.destination().to_str().unwrap(),
) {
eprintln!(
"path expected to be rnoatime, found not rnoatime, error: {e}"
);
}
}
"rstrictatime" => {
println!("rstrictatime: {mount:?}");
if let Err(e) = utils::test_mount_rstrictatime_option(
mount.destination().to_str().unwrap(),
) {
eprintln!("path expected to be rstrictatime, found not rstrictatime, error: {e}");
}
}
_ => {}
}
}
Expand Down
Loading

0 comments on commit 29babe7

Please sign in to comment.