Skip to content

Commit

Permalink
Merge pull request #1615 from lengrongfu/feat/rdev_recursive_mount_test
Browse files Browse the repository at this point in the history
feat add rdev/rnodev recursive mount test
  • Loading branch information
utam0k authored Mar 7, 2023
2 parents 0fd701f + 6dcf9c1 commit ff5dba9
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,54 @@ fn check_recursive_rnodiratime() -> TestResult {
result
}

fn check_recursive_rdev() -> TestResult {
let rdev_base_dir = PathBuf::from_str("/dev").unwrap();
let mount_dest_path = PathBuf::from_str("/rdev").unwrap();

let mount_options = vec!["rbind".to_string(), "rdev".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rdev_base_dir.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(()));
result
}

fn check_recursive_rnodev() -> TestResult {
let rnodev_base_dir = PathBuf::from_str("/dev").unwrap();
let mount_dest_path = PathBuf::from_str("/rnodev").unwrap();

let mount_options = vec!["rbind".to_string(), "rnodev".to_string()];
let mut mount_spec = Mount::default();
mount_spec
.set_destination(mount_dest_path)
.set_typ(None)
.set_source(Some(rnodev_base_dir.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(()));
result
}

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));
let rnoexec_test = Test::new("rnoexec_test", Box::new(check_recursive_noexec));
let rnodiratime_test = Test::new("rnodiratime_test", Box::new(check_recursive_rnodiratime));
let rdiratime_test = Test::new("rdiratime_test", Box::new(check_recursive_rdiratime));
let rdev_test = Test::new("rdev_test", Box::new(check_recursive_rdev));
let rnodev_test = Test::new("rnodev_test", Box::new(check_recursive_rnodev));

let mut tg = TestGroup::new("mounts_recursive");
tg.add(vec![
Expand All @@ -304,6 +346,8 @@ pub fn get_mounts_recursive_test() -> TestGroup {
Box::new(rnoexec_test),
Box::new(rdiratime_test),
Box::new(rnodiratime_test),
Box::new(rdev_test),
Box::new(rnodev_test),
]);

tg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ pub fn test_inside_container(
.context("getting output after starting the container failed")
.unwrap();

let stdout = String::from_utf8_lossy(&create_output.stdout);
if !stdout.is_empty() {
println!(
"{:?}",
anyhow!("container stdout was not empty, found : {}", stdout)
)
}
let stderr = String::from_utf8_lossy(&create_output.stderr);
if !stderr.is_empty() {
return TestResult::Failed(anyhow!(
Expand Down
17 changes: 17 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ pub fn validate_mounts_recursive(spec: &Spec) {
eprintln!("error in testing rnodiratime recursive mounting: {e}");
}
}
"rdev" => {
println!("test_device_access: {:?}", mount);
let rest =
utils::test_device_access(mount.destination().to_str().unwrap());
if let Err(e) = rest {
eprintln!("error in testing rdev recursive mounting: {e}");
}
}
"rnodev" => {
println!("test_device_unaccess: {:?}", mount);
let rest =
utils::test_device_unaccess(mount.destination().to_str().unwrap());
if rest.is_ok() {
// beacuse /rnodev/null device not access,so rest is err
eprintln!("error in testing rnodev recursive mounting");
}
}
_ => {}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/rust-integration-tests/runtimetest/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,21 @@ pub fn test_dir_not_update_access_time(path: &str) -> Result<(), std::io::Error>
}
Ok(())
}

pub fn test_device_access(path: &str) -> Result<(), std::io::Error> {
println!("test_device_access path: {:?}", path);
let _ = std::fs::OpenOptions::new()
.create(true)
.write(true)
.open(PathBuf::from(path).join("null"))?;
Ok(())
}

pub fn test_device_unaccess(path: &str) -> Result<(), std::io::Error> {
println!("test_device_unaccess path: {:?}", path);
let _ = std::fs::OpenOptions::new()
.create(true)
.write(true)
.open(PathBuf::from(path).join("null"))?;
Ok(())
}

0 comments on commit ff5dba9

Please sign in to comment.